wxapkg解包工具有很多,文本附上python3的解包工具,其他可以上github上搜索
# coding: utf-8
# py2 origin author lrdcq
# usage python3 unwxapkg.py filename
__author__ = 'Integ: https://github.com./integ'
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 [output_dir]')
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 = {}'.format(firstMark))
info1 = struct.unpack('>L', f.read(4))[0]
print('info1 = {}'.format(info1))
indexInfoLength = struct.unpack('>L', f.read(4))[0]
print('indexInfoLength = {}'.format(indexInfoLength))
bodyInfoLength = struct.unpack('>L', f.read(4))[0]
print('bodyInfoLength = {}'.format(bodyInfoLength))
lastMark = struct.unpack('B', f.read(1))[0]
print('last header mark = {}'.format(lastMark))
if firstMark != 0xBE or lastMark != 0xED:
print('its not a wxapkg file!!!!!')
f.close()
exit()
fileCount = struct.unpack('>L', f.read(4))[0]
print('fileCount = {}'.format(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 = {} at Offset = {}'.format(str(data.name, encoding = "utf-8"), data.offset))
fileList.append(data)
#save files
for d in fileList:
d.name = '/' + name + str(d.name, encoding = "utf-8")
path = root + os.path.dirname(d.name)
if not os.path.exists(path):
os.makedirs(path)
w = open(root + d.name, 'wb')
f.seek(d.offset)
w.write(f.read(d.size))
w.close()
print('writeFile = {}{}'.format(root, d.name))
f.close()
解包出来的文件路径
-\pages 每个页面的wxss样式文件
-app-config.json 页面配置的汇总(app.json+各个页面的配置文件)
-app-service.js 源码js的汇总 直接格式化看就行
-page-frame.html wxml文件的汇总
主要处理page-frame.html文件,需要修改里面的部分代码,修改代码如下:
添加wxml 输出方法:
function forwxml(raw){
var str="";
for(var i in raw){
if(i=="tag"){
if(raw[i]!="virtual"){
str+="<"+raw[i];
}
if(raw["wx:for-items"]!=undefined){
str+=" wx:for-items=\""+raw["wx:for-items"]+"\"";
}
if(raw["wx:key"]!=undefined){
str+=" wx:key=\""+raw["wx:key"]+"\"";
}
if(raw["attr"]!=undefined){
for(var j in raw["attr"]){
str+=" "+j+"=\""+raw["attr"][j]+"\"";
}
}
if(raw[i]!="virtual"){
str+=">";
}
if(raw["children"]!=undefined){
for(var k in raw["children"]){
if(typeof(raw["children"][k])=="object"){
str+=forwxml(raw["children"][k]);
}else{
str+=raw["children"][k];
}
}
}
if(raw[i]!="virtual"){
str+="</"+raw[i]+">";
}
}
}
return str;
}
修改如下的方法:
function _v(k) {
if (typeof(k) != 'undefined') return {
tag: 'block',
'wx:for-items': k,
children: []
};
return {
tag: 'virtual',
children: []
};
}
function _n(tag) {
$gwxc++;
if ($gwxc >= 16000) {
throw 'Dom limit exceeded, please check if there\'s any mistake you\'ve made.'
};
return {
tag: 'wx-' + tag,
attr: {},
children: [],
n: [],
raw: {},
generics: {}
}
}
function $gwrt(should_pass_type_info) {
function ArithmeticEv(ops, e, s, g, o) {
var _f = false;
var rop = ops[0][1];
var _a, _b, _c, _d, _aa, _bb;
switch (rop) {
case '?:':
_a = rev(ops[1], e, s, g, o, _f);
_c = should_pass_type_info && (wh.hn(_a) === 'h');
_d = wh.rv(_a) ? rev(ops[2], e, s, g, o, _f) : rev(ops[3], e, s, g, o, _f);
_d = _c && wh.hn(_d) === 'n' ? wh.nh(_d, 'c') : _d;
//return _d;
if (typeof(_a) != "boolean" && typeof(_a) != "number" && _a != "") {
_a = _a.replace("{
{", "").replace("}}", "");
}
return "{
{" + _a + "?'" + rev(ops[2], e, s, g, o) + "':'" + rev(ops[3], e, s, g, o) + "'}}";
break;
case '&&':
_a = rev(ops[1], e, s, g, o, _f);
_c = should_pass_type_info && (wh.hn(_a) ==