-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcrack.js
175 lines (157 loc) · 5.02 KB
/
crack.js
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
var fs = require('fs');
var path = require('path');
var helper = require('./lib/helper');
var sourcePath = "";
// sourcePath = 'cracked/miniui-1505965442741.js';
var template = fs.readFileSync(path.resolve(__dirname, sourcePath || 'source/miniui.js'), 'utf-8').toString();
var rules = [
{
exec: function(str){
return new RegExp('\\\[\\b' + str + '\\b\\\]', 'g')
},
replace: function(key, str){
return function(match){
return '.' + str;
}
}
}
// ,{
// exec: function(str){
// return new RegExp('\\\b' + str + '\\\b'+ '(?!\\\s=\\\s\\\")', 'g');
// },
// replace: function(key, str){
// return '"' + str + '"';
// }
// },
,{
exec: function(str){
return new RegExp('(\\b)(' + str + ')(\\b\|[^ol1O0])', 'g');
},
replace: function(key, str){
return function(match, $1, $2, $3){
return $1 + str + $3;
}
}
}];
var wordRules = [{
exec: function(str){
return new RegExp('\\\[\\b' + str + '\\b\\\]', 'g')
},
replace: function(key, str){
return function(match){
return '.' + str;
}
}
},{
exec: function(str){
return new RegExp('(\\b)(' + str + ')(\\b)', 'g');
},
replace: function(key, str){
return function(match, $1, $2, $3){
return $1 + str + $3;
}
}
}]
var crack = function(){
var pp = require('./dict');
for(var i in pp.dicts){
rules.forEach(function(item, j){
template = template.replace(item.exec(i), item.replace(i, pp.dicts[i]));
})
}
for (var i in pp.words){
wordRules.forEach(function(item, j){
template = template.replace(item.exec(i), item.replace(i, pp.words[i]));
})
}
// move function
var matches = template.match(/\b[ol1O0]{3,}\.(\w+)\s=\s([ol1O0]+([^;]+)?)/g);
if(matches){
matches.forEach(function(item){
var groups = item.split(' ');
var endIndex = groups.length - 1;
var funcBody = helper.findFuncBody(template, groups[endIndex], 0);
// template = template.replace(funcBody, ''); // remove
groups[endIndex] = funcBody.replace(groups[endIndex] + ' = ', '');
template = template.replace(item, groups.join(' '));
})
}
// change prototype name
var protomatches = template.match(/\b[ol1O0]{3,}\s=\smini[\._](\w+)\.prototype;/g);
if(protomatches){
protomatches.forEach(function(item){
var groups = item.split(' ');
var endIndex = groups.length - 1;
var miniprotos = groups[endIndex].split(/(\.|_)/);
// ["mini", ".", "DataGrid", ".", "prototype"]
if(miniprotos){
var newName = miniprotos[2].toLowerCase() + 'Proto';
template = template.replace(new RegExp(groups[0], 'g'), newName);
}
})
}
// delete evil code
// if (olOo0.toString().indexOf("") != -1) return;
// if (!window["OO0" + "110300"]) return;
// if (window["OO0" + "110"].charAt(153) != "0") return;
// if (window["O0" + "lolO"].length != 2127) return;
var evils = [
/[\s]*?if\s*\([\w]{3,}\.toString\(\)\.indexOf\([\"\w\\]+\)\s\!=\s-1\)\s*return(;)?[\n]*/g,
/[\s]*?if\s*\(\!window\[\"[\w\.]+\"\s\+\s\"[\w\.]*\"\]\)\s*return(;)?[\n]*/g,
/[\s]*?if\s*\(window\[\"[\w\.]+\"\s\+\s\"[\w\.]*\"\]\.charAt\(\w+\)\s\!=\s\"[\w\|\\\!\@\#\$\%\^\&\*]*\"\)\s*return(;)?[\n]*/g,
/[\s]*?if\s*\(window\[\"[\w\.]+\"\s\+\s\"[\w\.]*\"\]\.length\s\!=\s\d*\)\s*return(;)?[\n]*/g
]
evils.forEach(function(reg){
var evilmatches = template.match(reg);
if(evilmatches){
evilmatches.forEach(function(item){
template = template.replace(item, '');
})
}
})
template = template.replace('listcontrolProto._OnItemMouseOut = _OnItemMouseOut;', '');
// variable
template = template.replace(/var(\s*(\w+)\s=\s"\2"[,;]\n)+?(?=mini)/, '');
template = template.replace(/\*\/([\s\S]*?)(?=mini\s=)/, '*/\n');
var chainmatches = template.match(/\b\w+\s=\smini[\._](\w+)\.prototype;/g);
if(chainmatches){
chainmatches.forEach(function(item){
var groups = item.split(' ');
var endIndex = groups.length - 1;
var miniprotos = groups[endIndex].split(/(\.|_)/);
var protoItems = '\\b'+ groups[0] + '\\.[\\w]+(?=\\s*\\=\\s*function)';
var names = template.match(new RegExp(protoItems, 'g'));
var nameFuncs = [];
names && names.forEach(function(name){
var $name = name.replace(/\./g, '\\.'); // panelProto\\.setCloseAction
var pName = name.split('.')[1]; // panelProto.setCloseAction => setCloseAction
var body = helper.findFuncBody(template, $name, 1);
var prefix = name + ' = ';
nameFuncs.push({
pName: pName,
body: body.replace(prefix, '').slice(0, -1)
})
template = template.replace(body, ''); // remove
// template = template.split(body).join(''); // remove
});
var builds = [];
builds.push('mini.copyTo(')
builds.push(groups[endIndex].replace(/;$/, ''))
builds.push(', {\n');
var reNameFuncs = nameFuncs.reverse()
var last = reNameFuncs.length - 1;
// reverse order
reNameFuncs.forEach(function(b, index){
builds.push(b.pName)
builds.push(': ')
builds.push(b.body)
if(index != last)
builds.push(',\n')
})
builds.push('});\n')
template = template.replace(item, builds.join(''));
})
}
fs.writeFileSync('dist/miniui-'+ Date.now() + '.js', template);
}
crack();