-
Notifications
You must be signed in to change notification settings - Fork 2
/
extract-pkr.py
executable file
·60 lines (43 loc) · 1.17 KB
/
extract-pkr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
import sys
import os
from common import *
with open(sys.argv[1], "rb") as f:
magic = read32(f)
version = read32(f)
num_dir = read32(f)
num_file = read32(f)
known_files = 0
for i in range(num_dir):
name = read_string(f, 32)
print("dir: '%s'" % name)
offset = read32(f)
count = read32(f)
# Create path
path = name.split('/')
dir_export_path = os.path.join("out", *path)
os.makedirs(dir_export_path, exist_ok=True)
known_files += count
# Dump all files
cursor = f.tell()
f.seek(offset)
for j in range(count):
name = read_string(f, 32)
print("\tfile: '%s'" % name)
unk1 = read32(f)
assert(unk1 == 0xFFFFFFFE)
data_offset = read32(f)
size1 = read32(f)
size2 = read32(f)
assert(size1 == size2)
file_cursor = f.tell()
f.seek(data_offset)
# Construct path
file_export_path = os.path.join(dir_export_path, name)
# Extract file
with open(file_export_path, "wb") as fo:
data = f.read(size1)
fo.write(data)
f.seek(file_cursor)
f.seek(cursor)
print("%d / %d files known" % (known_files, num_file))