Last active
September 13, 2024 21:40
-
-
Save thedreamwork/01691af73eeda292e7327bc6bd3e1d08 to your computer and use it in GitHub Desktop.
unpack wxapkg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# 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: | |
d.name = '/' + name + d.name | |
path = root + os.path.dirname(d.name) | |
if not os.path.exists(path): | |
os.makedirs(path) | |
w = open(root + d.name, 'w') | |
f.seek(d.offset) | |
w.write(f.read(d.size)) | |
w.close() | |
print 'writeFile = ' + root + d.name | |
f.close() |
fork了一版python3的,亲测可用,需要的亲自下,感谢作者
raceback (most recent call last):
File "index.py", line 30, in
firstMark = struct.unpack('B', f.read(1))[0]
struct.error: unpack requires a string argument of length 1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
写入文件语句 w = open(file_, 'w') 改为 w = open(file_, 'wb') 资源文件是二进制的格式需要用二进制方式操作,否则会出现图片和音乐格式错误