Skip to content

Instantly share code, notes, and snippets.

@xyzz
Created August 12, 2013 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyzz/6dbaf7ecd0f132b32e26 to your computer and use it in GitHub Desktop.
Save xyzz/6dbaf7ecd0f132b32e26 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
import os
from toolset import read_int, read_byte
class FileListEntry():
def __init__(self):
pass
def read(self, stream):
name_length = read_int(stream)
self.name = stream.read(name_length).decode()
pack_name_length = read_int(stream)
self.pack_name = stream.read(pack_name_length).decode()
self.offset = read_int(stream)
self.size = read_int(stream)
self.kbn = read_byte(stream)
def __str__(self):
return "{} ← {} [{} @ {}, kbn: {}]".format(self.name, self.pack_name, self.size, self.offset, self.kbn)
def extract(self):
if not self.pack_name:
return
with open(os.path.join(PACK_ROOT, self.pack_name), "rb") as source:
source.seek(self.offset)
data = source.read(self.size)
with open(os.path.join(OUTPUT_ROOT, self.name), "wb") as output:
output.write(data)
PACK_ROOT = None
OUTPUT_ROOT = None
def main():
if len(sys.argv) != 3:
print("Usage: extract-files.py filelist output-directory")
return
global PACK_ROOT, OUTPUT_ROOT
PACK_ROOT = os.path.dirname(sys.argv[1])
OUTPUT_ROOT = sys.argv[2]
filelist_name = sys.argv[1]
with open(filelist_name, "rb") as filelist:
count = int.from_bytes(filelist.read(4), byteorder="big")
files = []
for x in range(count):
file_entry = FileListEntry()
file_entry.read(filelist)
files.append(file_entry)
for file_entry in files:
print(file_entry)
file_entry.extract()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment