forked from Toruk-Makto66/wxappUnpacker
-
Notifications
You must be signed in to change notification settings - Fork 7
/
jianshu
191 lines (96 loc) · 4.61 KB
/
jianshu
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
下面讲解需要更改的源码和操作步骤:
修改wxappUnpacker中wuWxss.js部分代码,具体如下:
functionrunVM(name,code){
let wxAppCode={},handle={cssFile:name};
let vm=new VM({sandbox:Object.assign(new GwxCfg(),{__wxAppCode__:wxAppCode,setCssToHead:cssRebuild.bind(handle)})});
vm.run(code);
for(let name in wxAppCode)if(name.endsWith(".wxss")){
handle.cssFile=path.resolve(frameName,"..",name);
wxAppCode[name]();
}
}
修改为
functionrunVM(name,code){
let wxAppCode={},handle={cssFile:name};
let gg = new GwxCfg();
let tsandbox ={$gwx:GwxCfg.prototype["$gwx"],__mainPageFrameReady__:GwxCfg.prototype["$gwx"],__wxAppCode__:wxAppCode,setCssToHead:cssRebuild.bind(handle)};
let vm = new VM({sandbox:tsandbox});
vm.run(code);
for(let name in wxAppCode)if(name.endsWith(".wxss")){
handle.cssFile=path.resolve(frameName,"..",name);
wxAppCode[name]();
}
}
问题完美解决
由于大神qwerty472123代码的一些bug会导致报错:
__vd_version_info__ is not defined
具体:
D:\xiaochengxu\my_test_decompiler\wxappUnpacker-master\node_modules\vm2\lib\main.js:224
throwthis._internal.Decontextify.value(e);
^
ReferenceError:__vd_version_info__ is not defined
at vm.js:3:3
at Script.runInContext (vm.js:130:20)
at VM.run(D:\xiaochengxu\my_test_decompiler\wxappUnpacker-master\node_modules\vm2\lib\main
.js:218:62)
at runVM (D:\xiaochengxu\my_test_decompiler\wxappUnpacker-master\wuWxss.js:69:6)
at runOnce(D:\xiaochengxu\my_test_decompiler\wxappUnpacker-master\wuWxss.js:86:27)
at Array.preRun(D:\xiaochengxu\my_test_decompiler\wxappUnpacker-master\wuWxss.js:166:5)
at CntEvent.decount (D:\xiaochengxu\my_test_decompiler\wxappUnpacker-master\wuLib.js:17:43)
at ioLimit.runWithCb.err(D:\xiaochengxu\my_test_decompiler\wxappUnpacker-master\wuLib.js:7
3:11)
at agent(D:\xiaochengxu\my_test_decompiler\wxappUnpacker-master\wuLib.js:54:14)
at FSReqWrap.args [as oncomplete] (fs.js:140:20)
解决方案:
wuWxss.jss找到函数wu.scanDirByExt内部的代码
code=code.slice(code.indexOf('var setCssToHead = function(file, _xcInvalid'));
code=code.slice(code.indexOf('\nvar _C= ')+1);
let oriCode=code;
code=code.slice(0,code.indexOf('\n'));
let vm=new VM({sandbox:{}});
pureData=vm.run(code+"\n_C");
let mainCode=oriCode.slice(oriCode.indexOf("setCssToHead"),oriCode.lastIndexOf(";var __pageFrameEndTime__"));
然后将其替换成:
code = code.replace(/display:-webkit-box;display:-webkit-flex;/gm, '');
let scriptCode = code;
//extract script content from html
if (frameFile.endsWith(".html")) {
try {
const $ = cheerio.load(code);
scriptCode = [].join.apply($('html').find('script').map(function (item) {
return $(this).html();
}, "\n"));
} catch (e) {
//ignore
}
}
let window = {
screen: {
width: 720,
height: 1028,
orientation: {
type: 'vertical'
}
}
};
let navigator = {
userAgent: "iPhone"
};
scriptCode = scriptCode.slice(scriptCode.lastIndexOf('window.__wcc_version__'));
let mainCode = 'window= ' + JSON.stringify(window) +
';\nnavigator=' + JSON.stringify(navigator) +
';\nvar __mainPageFrameReady__ = window.__mainPageFrameReady__ || function(){};var __WXML_GLOBAL__={entrys:{},defines:{},modules:{},ops:[],wxs_nf_init:undefined,total_ops:0};var __vd_version_info__=__vd_version_info__||{}' +
";\n" + scriptCode;
//remove setCssToHead function
mainCode = mainCode.replace('var setCssToHead = function', 'var setCssToHead2 = function');
code = code.slice(code.lastIndexOf('var setCssToHead = function(file, _xcInvalid'));
code = code.slice(code.lastIndexOf('\nvar _C= ') + 1);
code = code.slice(0, code.indexOf('\n'));
let vm = new VM({sandbox: {}});
pureData = vm.run(code + "\n_C");
这样问题就能完美解决。
考虑到大神wxappUnpacker项目中仍然有很多bug(包含但不限于结构设计上的不合理),建议采用下面的项目进行反编译,我修复了wxappUnpacker项目中的一些bug(包含但不限于$gwx is not defined 和__vd_version_info__ is not defined,并且它支持分包)
有的朋友使用了上面代码又碰到其他的bug,建议使用下面“分包的实现”项目,将项目下载下来,然后在自己电脑上安装 git bash ,运行命令:
1:解包主包 ./bingo.sh testpkg/master-xxx.wxapkg
2:解包子包 ./bingo.sh testpkg/sub-1-xxx.wxapkg -s=../master-xxx
分包的实现:https://github.com/Toruk-Makto66/wxappUnpacker/tree/master