-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpakExtractor.py
55 lines (41 loc) · 1.47 KB
/
pakExtractor.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
import os
import struct
import argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument("pakfile")
args = parser.parse_args()
f0 = open(args.pakfile, "rb")
headerMagic = struct.unpack("<I", f0.read(4))[0]
if headerMagic != 0x1234567A:
raise ValueError("Not a pak!")
print("Extracting pak...")
fileCount = struct.unpack("<I", f0.read(4))[0]
f0.seek(0x18, os.SEEK_SET)
for i in range(0, fileCount):
nameAddress = struct.unpack("<I", f0.read(4))[0]
fileAddress = struct.unpack("<I", f0.read(4))[0]
fileSize = struct.unpack("<I", f0.read(4))[0]
getBack = f0.tell()
f0.seek(nameAddress)
nameChar = ''
nameString = ""
nameChar = struct.unpack('c', f0.read(1))[0].decode()
while nameChar != '\0':
nameString += nameChar
nameChar = struct.unpack('c', f0.read(1))[0].decode()
print(nameString)
filePath = os.path.join(args.pakfile[:-4], nameString)
if os.path.exists(os.path.dirname(filePath)) == False:
os.makedirs(os.path.dirname(filePath))
f0.seek(fileAddress, os.SEEK_SET)
fileBytes = f0.read(fileSize)
f1 = open(filePath, "wb")
f1.write(fileBytes)
f1.close()
f0.seek(getBack, os.SEEK_SET)
f0.seek(0x10, os.SEEK_CUR)
print("Done!")
f0.close()
if __name__ == "__main__":
main()