Last active
March 29, 2024 16:43
-
-
Save obfusk/4c141994c827dcac13506c7132cc103e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import zipfile | |
def test(filename): | |
_orig_EndRecData = zipfile._EndRecData | |
eocd_offset = None | |
def _EndRecData(fh): | |
endrec = _orig_EndRecData(fh) | |
if endrec: | |
nonlocal eocd_offset | |
eocd_offset = endrec[zipfile._ECD_LOCATION] | |
endrec[zipfile._ECD_LOCATION] = ( | |
endrec[zipfile._ECD_OFFSET] + endrec[zipfile._ECD_SIZE] | |
) | |
return endrec | |
zipfile._EndRecData = _EndRecData | |
zf = zipfile.ZipFile(filename) | |
zipfile._EndRecData = _orig_EndRecData | |
zinfos = sorted(zf.filelist, key=lambda zinfo: zinfo.header_offset, reverse=True) | |
if zinfos: | |
if hasattr(zinfos[0], "_end_offset"): | |
zinfos[0]._end_offset = eocd_offset | |
return zf | |
zf1 = test("test1.mozzip") | |
zf2 = test("test2.mozzip") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment