Skip to content

Instantly share code, notes, and snippets.

@obfusk
Last active September 5, 2024 15:10
Show Gist options
  • Save obfusk/d9d1223cd1fa1a875e6cf49827621e69 to your computer and use it in GitHub Desktop.
Save obfusk/d9d1223cd1fa1a875e6cf49827621e69 to your computer and use it in GitHub Desktop.
#!/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)
#!/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