Created
August 19, 2019 20:12
-
-
Save daeken/1f60a25b660894e50bed28fb1fbd28d8 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 os, struct, sys | |
def main(fn, odir): | |
fp = file(fn, 'rb') | |
fp.seek(0, 2) | |
flen = fp.tell() | |
fp.seek(flen - 10, 0) | |
n, n2 = struct.unpack('<II', fp.read(8)) | |
assert n <= flen and n2 <= flen | |
n3 = flen - n - n2 - 22 | |
maximum = flen - n - 22 | |
fp.seek(maximum, 0) | |
n4 = flen - 22 | |
n5 = 0 | |
while fp.tell() < n4: | |
fp.read(20) | |
n6, n7, intl = struct.unpack('<III', fp.read(12)) | |
fp.read(10) | |
value = struct.unpack('<I', fp.read(4))[0] + n3 + 66 + intl | |
fn = fp.read(intl) | |
print '%r - %x %x %x' % (fn, value, n6, n7) | |
assert n6 == n7 | |
if '/' in fn: | |
dn = odir + '/' + fn.rsplit('/', 1)[0] | |
try: | |
os.makedirs(dn) | |
except: | |
pass | |
pre = fp.tell() | |
with file(odir + '/' + fn, 'wb') as zfp: | |
fp.seek(value, 0) | |
zfp.write(fp.read(n6)) | |
fp.seek(pre, 0) | |
n5 += 1 | |
if __name__=='__main__': | |
main(*sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment