forked from bzqweiyi/wechat-jump-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunwxapkg.py
84 lines (56 loc) · 1.98 KB
/
unwxapkg.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
76
77
78
79
80
81
82
83
84
#!/usr/bin/python
# by @wenxingxing
# usage python unwxapkg.py filename
import sys, os
import struct
class WxapkgFile:
nameLen = 0
name = ""
offset = 0
size = 0
if len(sys.argv) < 2:
print('usage: unwxapkg.py filename')
exit()
with open(sys.argv[1], "rb") as f:
root = os.path.dirname(os.path.realpath(f.name))
name = os.path.basename(f.name)
if len(sys.argv) > 2:
name = sys.argv[2]
#read header
firstMark = struct.unpack('B', f.read(1))[0]
print('first header mark = ' + str(firstMark))
info1 = struct.unpack('>L', f.read(4))[0]
print('info1 = ' + str(info1))
indexInfoLength = struct.unpack('>L', f.read(4))[0]
print('indexInfoLength = ' + str(indexInfoLength))
bodyInfoLength = struct.unpack('>L', f.read(4))[0]
print('bodyInfoLength = ' + str(bodyInfoLength))
lastMark = struct.unpack('B', f.read(1))[0]
print('last header mark = ' + str(lastMark))
if firstMark != 0xBE or lastMark != 0xED:
print('its not a wxapkg file!!!!!')
exit()
fileCount = struct.unpack('>L', f.read(4))[0]
print('fileCount = ' + str(fileCount))
#read index
fileList = []
for i in range(fileCount):
data = WxapkgFile()
data.nameLen = struct.unpack('>L', f.read(4))[0]
data.name = f.read(data.nameLen)
data.offset = struct.unpack('>L', f.read(4))[0]
data.size = struct.unpack('>L', f.read(4))[0]
print('readFile = ' + data.name + ' at Offset = ' + str(data.offset))
fileList.append(data)
#save files
for d in fileList:
path = root + '/' + name + '_'
file_ = path + d.name
if not os.path.exists(os.path.dirname(file_)):
os.makedirs(os.path.dirname(file_))
w = open(file_, 'w')
f.seek(d.offset)
w.write(f.read(d.size))
w.close()
print('writeFile = ' + file_)
f.close()