-
Notifications
You must be signed in to change notification settings - Fork 0
/
pckUnpacker.py
75 lines (63 loc) · 2.06 KB
/
pckUnpacker.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
# For Windows OS Only....
import sys
import os
import struct
class Header:
def __init__(H,f):
f.seek(0)
H.indexOffset=32
H.headerData=f.read(32)
H.headerList=struct.unpack('8I',H.headerData)
H.type=H.headerList[0]
H.fileCount=H.headerList[1]
H.dataOffset=H.headerList[2]+H.indexOffset
H.sizeOffset=H.headerList[3]+H.indexOffset
H.nameOffset=H.indexOffset+H.fileCount*4
def main(argv):
if len(argv)<2 or argv[1]=='':
print ("Usage: "+argv[0][argv[0].rfind("\\")+1:]+" <pck file> [output folder\]")
return False
if len(argv)<3 or argv[2]=='':
outF=argv[1].replace(".pck","")+"\\"
else:
outF=argv[0][:argv[0].rfind("\\")+1]+argv[2]+"\\"
try:
f=open(argv[1],'rb')
f.read()
f.close()
except:
return False
size=os.path.getsize(argv[1])
scene=open(argv[1],'rb')
header=Header(scene)
if not header.type==1:
print("NOT a pck data file!")
return False
if not os.path.exists(outF):
os.makedirs(outF)
scene.seek(header.indexOffset)
nameLength=struct.unpack('%dI'%header.fileCount,scene.read(header.fileCount*4))
fileName=[]
for n in range(0,header.fileCount):
fileName.append(scene.read(nameLength[n]))
#print(fileName[n].decode("UTF-16"))
scene.seek(header.sizeOffset)
fileOffset=[]
fileLength=[]
for n in range(0,header.fileCount):
fileOffset.append(struct.unpack('Q',scene.read(8))[0])
fileLength.append(struct.unpack('Q',scene.read(8))[0])
scene.seek(header.dataOffset)
for n in range(0,header.fileCount):
outFN=fileName[n].decode("UTF-16")
scene.seek(fileOffset[n])
print(outFN)
fileData=scene.read(fileLength[n])
output=open(outF+outFN,'wb')
output.write(fileData)
output.close()
scene.close()
return True
if __name__=="__main__":
main(sys.argv)