Last active
September 5, 2024 15:10
-
-
Save obfusk/d9d1223cd1fa1a875e6cf49827621e69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import struct | |
import sys | |
import zipfile | |
zfile, entry = sys.argv[1:] | |
with zipfile.ZipFile(zfile) as zf: | |
info = zf.getinfo(entry) | |
with open(zfile, "rb") as fh: | |
fh.seek(info.header_offset) | |
n, m = struct.unpack("<HH", fh.read(30)[26:30]) | |
fh.seek(info.header_offset + 30 + n + m) | |
cdata, size = b"", info.compress_size | |
while size > 0: | |
cdata += fh.read(min(size, 4096)) | |
size -= 4096 | |
sys.stdout.buffer.write(cdata) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import struct | |
import sys | |
import zipfile | |
import zlib | |
zfile, entry = sys.argv[1:] | |
with zipfile.ZipFile(zfile) as zf: | |
data = zf.read(entry) | |
info = zf.getinfo(entry) | |
with open(zfile, "rb") as fh: | |
fh.seek(info.header_offset) | |
n, m = struct.unpack("<HH", fh.read(30)[26:30]) | |
fh.seek(info.header_offset + 30 + n + m) | |
cdata, size = b"", info.compress_size | |
while size > 0: | |
cdata += fh.read(min(size, 4096)) | |
size -= 4096 | |
levels = list(range(0, 9 + 1)) | |
wbitss = list(range(-15, -9 + 1)) | |
memLevels = list(range(1, 9 + 1)) | |
strategies = list(range(0, 4 + 1)) | |
for level in levels: | |
for wbits in wbitss: | |
for memLevel in memLevels: | |
for strategy in strategies: | |
co = zlib.compressobj(level=level, wbits=wbits, memLevel=memLevel, strategy=strategy) | |
cd = co.compress(data) + co.flush() | |
if cd == cdata: | |
print(dict(level=level, wbits=wbits, memLevel=memLevel, strategy=strategy)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment