Skip to content

Instantly share code, notes, and snippets.

@daeken daeken/unpackspk.py
Created Aug 19, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.