Instantly share code, notes, and snippets.

@feix /unwxapkg.py
Last active Dec 11, 2018

Embed
What would you like to do?
#!/usr/bin/env python2
# lrdcq
# usage python2 unwxapkg.py filename
import sys, os
import struct
class WxapkgFile(object):
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) + '_dir'
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()
@feix

This comment has been minimized.

Owner

feix commented Jan 1, 2018

原始代码链接: http://lrdcq.com/me/read.php/66.htm

@Integ

This comment has been minimized.

Integ commented Jan 2, 2018

Amazing tool, Great job!

You can find a python3 version here

@SpecsShi

This comment has been minimized.

SpecsShi commented Jan 2, 2018

解出来是 一些 .html 文件,编辑器都打不开。。

@duenyang

This comment has been minimized.

duenyang commented Jan 2, 2018

请问怎么获取小程序的appID?

@oddballwu

This comment has been minimized.

oddballwu commented Jan 4, 2018

解压出来的都是html文件,怎么用呢

@FantasticSkyBaby

This comment has been minimized.

FantasticSkyBaby commented Jan 5, 2018

同问 HTML文件有还原的工具吗

@inputfuture

This comment has been minimized.

inputfuture commented Jan 6, 2018

Traceback (most recent call last):
File "unwxapkg.py", line 78, in
w = open(root + d.name, 'w')
IOError: [Errno 22] invalid mode ('w') or filename: 'xxx.wxapkg_dir/res/\xe6\xb0\x94\xe6\xb3\xa1\xe7\x8b\x97\xe7\x99\xbd\xe8\x84\xb8.png'

@Hansuku

This comment has been minimized.

Hansuku commented Jan 6, 2018

Traceback (most recent call last):
File "unwxapkg.py", line 31, in
firstMark = struct.unpack('B', f.read(1))[0]
struct.error: unpack requires a string argument of length 1
这个是啥毛病....

@yaoshanliang

This comment has been minimized.

yaoshanliang commented Jan 19, 2018

同问html后面怎么解码

@chenrensong

This comment has been minimized.

chenrensong commented Jan 22, 2018

@wxbug-cn

This comment has been minimized.

wxbug-cn commented Jun 1, 2018

https://wxbug.cn 这里可直接上传解析

@shuidong

This comment has been minimized.

shuidong commented Aug 4, 2018

现在微信小游戏里的图片加密了?能破吗

@ubbcou

This comment has been minimized.

ubbcou commented Sep 19, 2018

如果出现中文文件名会报错,可以试试这样( line: 65 && line: 78):

# line 65
print 'readFile = ' + data.name.decode('utf-8') + ' at Offset = ' + str(data.offset)

# line 78
filepath = unicode(root + d.name,'utf8')
w = open(filepath, 'w')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment