Guest User

CHLCC AFS Unpack

a guest
Jun 30th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import struct
  2. from itertools import zip_longest
  3. from functools import partial
  4.  
  5. def grouper(iterable, n, fillvalue=None):
  6.     args = [iter(iterable)] * n
  7.     return zip_longest(*args, fillvalue=fillvalue)
  8.  
  9. with open('SCENE00.AFS', 'rb') as f:
  10.     f.seek(4)
  11.     num_of_files = struct.unpack('<I', f.read(4))[0]
  12.     TOC = (struct.unpack('<' + 'I' * 2 * num_of_files,
  13.                          f.read(8 * num_of_files)))
  14.     TOC_pos, TOC_size = struct.unpack('<II', f.read(8))
  15.     filenames = []
  16.     f.seek(TOC_pos)
  17.     for x in range(num_of_files):
  18.         s = b''
  19.         pos = f.tell()
  20.         for byte in iter(partial(f.read, 1), b'\x00'):
  21.             s += byte
  22.         filenames.append(s)
  23.         f.seek(pos + 0x30)
  24.     for filename, (fileoffset, filesize) in zip(filenames, grouper(TOC, 2)):
  25.         f.seek(fileoffset)
  26.         with open(filename, 'wb') as g:
  27.             g.write(f.read(filesize))
Add Comment
Please, Sign In to add comment