Skip to content

Instantly share code, notes, and snippets.

@sir-wabbit
Created May 19, 2015 06:01
Show Gist options
  • Select an option

  • Save sir-wabbit/89590fcea2fcbccf2a59 to your computer and use it in GitHub Desktop.

Select an option

Save sir-wabbit/89590fcea2fcbccf2a59 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from struct import pack, unpack
import re
import os, errno
import os.path
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else: raise
with open('data0002.lib', 'rb') as f:
def readi32():
return unpack("<i", f.read(4))[0]
def readi16():
return unpack("<H", f.read(2))[0]
f.read(4)
dir_count = readi32()
file_count = readi32()
# Skip meaningless directory info.
for i in xrange(dir_count):
length = readi32()
path = f.read(length).decode("latin-1")
count = readi32()
# Read file info.
files = []
for i in xrange(file_count):
length = readi32()
path = f.read(length).decode("latin-1")
num1 = readi32()
num2 = readi32()
files.append((path, num1, num2))
# Extract files.
for t in files:
path = "./unpacked/" + t[0].replace('\\', '/')
print path
f.seek(t[1])
data = f.read(t[2])
mkdir_p(os.path.dirname(path))
with open(path, 'w') as out:
out.write(data)
out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment