js-confuser 1.2.2 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +132 -0
- package/README.md +4 -1
- package/dist/parser.js +1 -2
- package/dist/transforms/controlFlowFlattening/controlFlowFlattening.js +482 -91
- package/dist/transforms/controlFlowFlattening/expressionObfuscation.js +4 -0
- package/dist/transforms/controlFlowFlattening/{switchCaseObfucation.js → switchCaseObfuscation.js} +2 -2
- package/dist/transforms/deadCode.js +1 -1
- package/dist/transforms/dispatcher.js +7 -6
- package/dist/transforms/eval.js +1 -1
- package/dist/transforms/extraction/duplicateLiteralsRemoval.js +4 -2
- package/dist/transforms/hideInitializingCode.js +4 -1
- package/dist/transforms/identifier/globalConcealing.js +18 -8
- package/dist/transforms/identifier/variableAnalysis.js +1 -1
- package/dist/transforms/label.js +11 -2
- package/dist/transforms/lock/antiDebug.js +32 -13
- package/dist/transforms/lock/lock.js +3 -3
- package/dist/transforms/minify.js +2 -2
- package/dist/transforms/opaquePredicates.js +4 -2
- package/dist/transforms/preparation/preparation.js +8 -0
- package/dist/transforms/renameLabels.js +17 -3
- package/dist/transforms/rgf.js +8 -3
- package/dist/transforms/stack.js +1 -1
- package/dist/transforms/string/encoding.js +74 -0
- package/dist/transforms/string/stringCompression.js +6 -2
- package/dist/transforms/string/stringConcealing.js +1 -1
- package/dist/transforms/string/stringSplitting.js +6 -0
- package/dist/traverse.js +0 -34
- package/dist/util/gen.js +3 -1
- package/dist/util/identifiers.js +8 -18
- package/dist/util/insert.js +4 -38
- package/package.json +2 -2
- package/src/options.ts +3 -3
- package/src/parser.ts +1 -2
- package/src/transforms/controlFlowFlattening/controlFlowFlattening.ts +735 -134
- package/src/transforms/controlFlowFlattening/expressionObfuscation.ts +6 -0
- package/src/transforms/controlFlowFlattening/{switchCaseObfucation.ts → switchCaseObfuscation.ts} +6 -2
- package/src/transforms/deadCode.ts +8 -0
- package/src/transforms/dispatcher.ts +16 -6
- package/src/transforms/eval.ts +2 -1
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +40 -5
- package/src/transforms/hideInitializingCode.ts +432 -425
- package/src/transforms/identifier/globalConcealing.ts +102 -38
- package/src/transforms/identifier/variableAnalysis.ts +1 -1
- package/src/transforms/label.ts +20 -2
- package/src/transforms/lock/antiDebug.ts +69 -33
- package/src/transforms/lock/lock.ts +4 -5
- package/src/transforms/minify.ts +2 -1
- package/src/transforms/opaquePredicates.ts +25 -3
- package/src/transforms/preparation/preparation.ts +8 -1
- package/src/transforms/renameLabels.ts +26 -3
- package/src/transforms/rgf.ts +6 -1
- package/src/transforms/stack.ts +2 -1
- package/src/transforms/string/encoding.ts +107 -1
- package/src/transforms/string/stringCompression.ts +28 -3
- package/src/transforms/string/stringConcealing.ts +2 -0
- package/src/transforms/string/stringSplitting.ts +11 -0
- package/src/transforms/transform.ts +1 -2
- package/src/traverse.ts +0 -30
- package/src/util/gen.ts +5 -3
- package/src/util/identifiers.ts +18 -19
- package/src/util/insert.ts +10 -76
- package/src/util/scope.ts +9 -9
- package/test/{transforms/compare.test.ts → compare.test.ts} +2 -2
- package/test/index.test.ts +109 -1
- package/test/templates/template.test.ts +14 -0
- package/test/transforms/controlFlowFlattening/controlFlowFlattening.test.ts +392 -10
- package/test/transforms/dispatcher.test.ts +30 -0
- package/test/transforms/eval.test.ts +28 -0
- package/test/transforms/flatten.test.ts +28 -0
- package/test/transforms/hideInitializingCode.test.ts +336 -336
- package/test/transforms/identifier/renameVariables.test.ts +31 -0
- package/test/transforms/lock/antiDebug.test.ts +43 -0
- package/test/transforms/renameLabels.test.ts +33 -0
- package/test/transforms/rgf.test.ts +29 -0
- package/test/transforms/string/stringSplitting.test.ts +33 -0
- package/test/util/identifiers.test.ts +105 -17
- package/dist/util/expr.js +0 -60
- package/src/util/expr.ts +0 -56
|
@@ -13,8 +13,15 @@ import {
|
|
|
13
13
|
SwitchStatement,
|
|
14
14
|
SwitchCase,
|
|
15
15
|
LogicalExpression,
|
|
16
|
+
VariableDeclarator,
|
|
17
|
+
FunctionExpression,
|
|
18
|
+
ExpressionStatement,
|
|
19
|
+
SequenceExpression,
|
|
20
|
+
AssignmentExpression,
|
|
21
|
+
VariableDeclaration,
|
|
22
|
+
BreakStatement,
|
|
16
23
|
} from "../../util/gen";
|
|
17
|
-
import { prepend } from "../../util/insert";
|
|
24
|
+
import { append, prepend } from "../../util/insert";
|
|
18
25
|
import { getIdentifierInfo } from "../../util/identifiers";
|
|
19
26
|
import { getRandomInteger } from "../../util/random";
|
|
20
27
|
import { reservedIdentifiers, reservedKeywords } from "../../constants";
|
|
@@ -155,16 +162,16 @@ export default class GlobalConcealing extends Transform {
|
|
|
155
162
|
|
|
156
163
|
// Returns global variable or fall backs to `this`
|
|
157
164
|
var getGlobalVariableFn = Template(`
|
|
158
|
-
|
|
165
|
+
var ${getGlobalVariableFnName} = function(){
|
|
159
166
|
try {
|
|
160
167
|
return ${global};
|
|
161
168
|
} catch (e){
|
|
162
|
-
return ${getThisVariableFnName}();
|
|
169
|
+
return ${getThisVariableFnName}["call"](this);
|
|
163
170
|
}
|
|
164
171
|
}`).single();
|
|
165
172
|
|
|
166
173
|
var getThisVariableFn = Template(`
|
|
167
|
-
|
|
174
|
+
var ${getThisVariableFnName} = function(){
|
|
168
175
|
try {
|
|
169
176
|
return this;
|
|
170
177
|
} catch (e){
|
|
@@ -227,48 +234,105 @@ export default class GlobalConcealing extends Transform {
|
|
|
227
234
|
}
|
|
228
235
|
});
|
|
229
236
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
237
|
+
var indexParamName = this.getPlaceholder();
|
|
238
|
+
var returnName = this.getPlaceholder();
|
|
239
|
+
|
|
240
|
+
var functionDeclaration = FunctionDeclaration(
|
|
241
|
+
globalFn,
|
|
242
|
+
[Identifier(indexParamName)],
|
|
243
|
+
[
|
|
244
|
+
VariableDeclaration(VariableDeclarator(returnName)),
|
|
245
|
+
SwitchStatement(
|
|
246
|
+
Identifier(indexParamName),
|
|
247
|
+
Object.keys(newNames).map((name) => {
|
|
248
|
+
var code = newNames[name];
|
|
249
|
+
var body: Node[] = [
|
|
250
|
+
ReturnStatement(
|
|
251
|
+
LogicalExpression(
|
|
252
|
+
"||",
|
|
253
|
+
MemberExpression(
|
|
254
|
+
Identifier(globalVar),
|
|
255
|
+
Literal(name),
|
|
256
|
+
true
|
|
257
|
+
),
|
|
258
|
+
MemberExpression(Identifier(thisVar), Literal(name), true)
|
|
259
|
+
)
|
|
260
|
+
),
|
|
261
|
+
];
|
|
262
|
+
if (Math.random() > 0.5 && name) {
|
|
263
|
+
body = [
|
|
264
|
+
ExpressionStatement(
|
|
265
|
+
AssignmentExpression(
|
|
266
|
+
"=",
|
|
267
|
+
Identifier(returnName),
|
|
268
|
+
LogicalExpression(
|
|
269
|
+
"||",
|
|
247
270
|
Literal(name),
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
true
|
|
271
|
+
MemberExpression(
|
|
272
|
+
Identifier(thisVar),
|
|
273
|
+
Literal(name),
|
|
274
|
+
true
|
|
275
|
+
)
|
|
254
276
|
)
|
|
255
277
|
)
|
|
256
278
|
),
|
|
257
|
-
|
|
258
|
-
|
|
279
|
+
BreakStatement(),
|
|
280
|
+
];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return SwitchCase(Literal(code), body);
|
|
284
|
+
})
|
|
285
|
+
),
|
|
286
|
+
ReturnStatement(
|
|
287
|
+
LogicalExpression(
|
|
288
|
+
"||",
|
|
289
|
+
MemberExpression(
|
|
290
|
+
Identifier(globalVar),
|
|
291
|
+
Identifier(returnName),
|
|
292
|
+
true
|
|
293
|
+
),
|
|
294
|
+
MemberExpression(
|
|
295
|
+
Identifier(thisVar),
|
|
296
|
+
Identifier(returnName),
|
|
297
|
+
true
|
|
298
|
+
)
|
|
299
|
+
)
|
|
300
|
+
),
|
|
301
|
+
]
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
var tempVar = this.getPlaceholder();
|
|
305
|
+
|
|
306
|
+
var variableDeclaration = Template(`
|
|
307
|
+
var ${globalVar}, ${thisVar};
|
|
308
|
+
`).single();
|
|
309
|
+
|
|
310
|
+
variableDeclaration.declarations.push(
|
|
311
|
+
VariableDeclarator(
|
|
312
|
+
tempVar,
|
|
313
|
+
CallExpression(
|
|
314
|
+
MemberExpression(
|
|
315
|
+
FunctionExpression(
|
|
316
|
+
[],
|
|
317
|
+
[
|
|
318
|
+
getGlobalVariableFn,
|
|
319
|
+
getThisVariableFn,
|
|
320
|
+
|
|
321
|
+
Template(
|
|
322
|
+
`return ${thisVar} = ${getThisVariableFnName}["call"](this, ${globalFn}), ${globalVar} = ${getGlobalVariableFnName}["call"](this)`
|
|
323
|
+
).single(),
|
|
324
|
+
]
|
|
325
|
+
),
|
|
326
|
+
Literal("call"),
|
|
327
|
+
true
|
|
259
328
|
),
|
|
260
|
-
|
|
329
|
+
[]
|
|
330
|
+
)
|
|
261
331
|
)
|
|
262
332
|
);
|
|
263
333
|
|
|
264
|
-
prepend(
|
|
265
|
-
|
|
266
|
-
Template(`
|
|
267
|
-
var ${globalVar} = ${getGlobalVariableFnName}.call(this), ${thisVar} = ${getGlobalVariableFnName}.call(this);
|
|
268
|
-
`).single()
|
|
269
|
-
);
|
|
270
|
-
prepend(object, getGlobalVariableFn);
|
|
271
|
-
prepend(object, getThisVariableFn);
|
|
334
|
+
prepend(object, variableDeclaration);
|
|
335
|
+
append(object, functionDeclaration);
|
|
272
336
|
}
|
|
273
337
|
};
|
|
274
338
|
}
|
package/src/transforms/label.ts
CHANGED
|
@@ -16,7 +16,13 @@ export default class Label extends Transform {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
match(object, parents) {
|
|
19
|
-
return
|
|
19
|
+
return (
|
|
20
|
+
isLoop(object) ||
|
|
21
|
+
(object.type == "BlockStatement" &&
|
|
22
|
+
parents[0] &&
|
|
23
|
+
parents[0].type == "LabeledStatement" &&
|
|
24
|
+
parents[0].body === object)
|
|
25
|
+
);
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
transform(object, parents) {
|
|
@@ -28,7 +34,19 @@ export default class Label extends Transform {
|
|
|
28
34
|
|
|
29
35
|
walk(object, parents, (o, p) => {
|
|
30
36
|
if (o.type == "BreakStatement" || o.type == "ContinueStatement") {
|
|
31
|
-
|
|
37
|
+
function isContinuableStatement(x) {
|
|
38
|
+
return isLoop(x) && x.type !== "SwitchStatement";
|
|
39
|
+
}
|
|
40
|
+
function isBreakableStatement(x) {
|
|
41
|
+
return isLoop(x) || (o.label && x.type == "BlockStatement");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var fn =
|
|
45
|
+
o.type == "ContinueStatement"
|
|
46
|
+
? isContinuableStatement
|
|
47
|
+
: isBreakableStatement;
|
|
48
|
+
|
|
49
|
+
var loop = p.find(fn);
|
|
32
50
|
if (object == loop) {
|
|
33
51
|
if (!o.label) {
|
|
34
52
|
o.label = Identifier(label);
|
|
@@ -1,58 +1,86 @@
|
|
|
1
1
|
import { ObfuscateOrder } from "../../order";
|
|
2
2
|
import Template from "../../templates/template";
|
|
3
3
|
import { isBlock } from "../../traverse";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
AssignmentExpression,
|
|
6
|
+
DebuggerStatement,
|
|
7
|
+
ExpressionStatement,
|
|
8
|
+
FunctionDeclaration,
|
|
9
|
+
Identifier,
|
|
10
|
+
IfStatement,
|
|
11
|
+
Literal,
|
|
12
|
+
WhileStatement,
|
|
13
|
+
} from "../../util/gen";
|
|
5
14
|
import { getBlockBody, prepend } from "../../util/insert";
|
|
6
15
|
import { getRandomInteger } from "../../util/random";
|
|
7
16
|
import Transform from "../transform";
|
|
17
|
+
import Lock from "./lock";
|
|
8
18
|
|
|
9
19
|
var DevToolsDetection = Template(
|
|
10
20
|
`
|
|
11
|
-
function $jsc_debug(){
|
|
12
|
-
|
|
13
|
-
var isDev1 = !("" + function() {/* Hello world */}).includes("/*");
|
|
14
|
-
var s = "s";
|
|
15
|
-
while (isDev1) {
|
|
16
|
-
s = s + s;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
var startTime = new Date();
|
|
20
|
-
debugger;
|
|
21
|
-
var endTime = new Date();
|
|
22
|
-
var isDev2 = endTime-startTime > 600;
|
|
23
|
-
|
|
24
|
-
var a = "a";
|
|
25
|
-
while (isDev2) {
|
|
26
|
-
a = a + a;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
30
21
|
try {
|
|
31
22
|
if ( setInterval ) {
|
|
32
23
|
setInterval(()=>{
|
|
33
|
-
|
|
24
|
+
{functionName}();
|
|
34
25
|
}, 4000);
|
|
35
26
|
}
|
|
36
27
|
} catch ( e ) {
|
|
37
28
|
|
|
38
29
|
}
|
|
39
|
-
|
|
40
30
|
`
|
|
41
31
|
);
|
|
42
32
|
|
|
43
33
|
export default class AntiDebug extends Transform {
|
|
44
34
|
made: number;
|
|
35
|
+
lock: Lock;
|
|
45
36
|
|
|
46
|
-
constructor(o) {
|
|
37
|
+
constructor(o, lock) {
|
|
47
38
|
super(o, ObfuscateOrder.Lock);
|
|
48
39
|
|
|
40
|
+
this.lock = lock;
|
|
49
41
|
this.made = 0;
|
|
50
42
|
}
|
|
51
43
|
|
|
52
44
|
apply(tree) {
|
|
53
45
|
super.apply(tree);
|
|
54
46
|
|
|
55
|
-
|
|
47
|
+
var fnName = this.getPlaceholder();
|
|
48
|
+
var startTimeName = this.getPlaceholder();
|
|
49
|
+
var endTimeName = this.getPlaceholder();
|
|
50
|
+
var isDevName = this.getPlaceholder();
|
|
51
|
+
var functionDeclaration = FunctionDeclaration(
|
|
52
|
+
fnName,
|
|
53
|
+
[],
|
|
54
|
+
[
|
|
55
|
+
...Template(`
|
|
56
|
+
var ${startTimeName} = new Date();
|
|
57
|
+
debugger;
|
|
58
|
+
var ${endTimeName} = new Date();
|
|
59
|
+
var ${isDevName} = ${endTimeName}-${startTimeName} > 1000;
|
|
60
|
+
`).compile(),
|
|
61
|
+
|
|
62
|
+
IfStatement(
|
|
63
|
+
Identifier(isDevName),
|
|
64
|
+
this.options.lock.countermeasures
|
|
65
|
+
? this.lock.getCounterMeasuresCode()
|
|
66
|
+
: [
|
|
67
|
+
WhileStatement(Identifier(isDevName), [
|
|
68
|
+
ExpressionStatement(
|
|
69
|
+
AssignmentExpression(
|
|
70
|
+
"=",
|
|
71
|
+
Identifier(startTimeName),
|
|
72
|
+
Identifier(endTimeName)
|
|
73
|
+
)
|
|
74
|
+
),
|
|
75
|
+
]),
|
|
76
|
+
],
|
|
77
|
+
null
|
|
78
|
+
),
|
|
79
|
+
]
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
tree.body.unshift(...DevToolsDetection.compile({ functionName: fnName }));
|
|
83
|
+
tree.body.push(functionDeclaration);
|
|
56
84
|
}
|
|
57
85
|
|
|
58
86
|
match(object, parents) {
|
|
@@ -60,17 +88,25 @@ export default class AntiDebug extends Transform {
|
|
|
60
88
|
}
|
|
61
89
|
|
|
62
90
|
transform(object, parents) {
|
|
63
|
-
|
|
91
|
+
return () => {
|
|
92
|
+
var body = getBlockBody(object.body);
|
|
93
|
+
|
|
94
|
+
[...body].forEach((stmt, i) => {
|
|
95
|
+
var addDebugger = Math.random() < 0.1 / (this.made || 1);
|
|
96
|
+
|
|
97
|
+
if (object.type == "Program" && i == 0) {
|
|
98
|
+
addDebugger = true;
|
|
99
|
+
}
|
|
64
100
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
body.splice(index, 0, DebuggerStatement());
|
|
101
|
+
if (addDebugger) {
|
|
102
|
+
var index = getRandomInteger(0, body.length);
|
|
103
|
+
if (body[index].type != "DebuggerStatement") {
|
|
104
|
+
body.splice(index, 0, DebuggerStatement());
|
|
70
105
|
|
|
71
|
-
|
|
106
|
+
this.made++;
|
|
107
|
+
}
|
|
72
108
|
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
109
|
+
});
|
|
110
|
+
};
|
|
75
111
|
}
|
|
76
112
|
}
|
|
@@ -62,7 +62,7 @@ export default class Lock extends Transform {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
if (this.options.lock.antiDebug) {
|
|
65
|
-
this.before.push(new AntiDebug(o));
|
|
65
|
+
this.before.push(new AntiDebug(o, this));
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
this.made = 0;
|
|
@@ -112,8 +112,7 @@ export default class Lock extends Transform {
|
|
|
112
112
|
throw new Error(
|
|
113
113
|
"Countermeasures function named '" +
|
|
114
114
|
this.options.lock.countermeasures +
|
|
115
|
-
"' was not found.
|
|
116
|
-
Array.from(defined).slice(0, 100).join(", ")
|
|
115
|
+
"' was not found."
|
|
117
116
|
);
|
|
118
117
|
}
|
|
119
118
|
}
|
|
@@ -271,9 +270,9 @@ export default class Lock extends Transform {
|
|
|
271
270
|
`
|
|
272
271
|
(
|
|
273
272
|
function(){
|
|
274
|
-
|
|
273
|
+
// Breaks JSNice.org, beautifier.io
|
|
275
274
|
var namedFunction = function(){
|
|
276
|
-
const test= function(){
|
|
275
|
+
const test = function(){
|
|
277
276
|
const regExp=new RegExp('\\n');
|
|
278
277
|
return regExp['test'](namedFunction)
|
|
279
278
|
};
|
package/src/transforms/minify.ts
CHANGED
|
@@ -365,6 +365,7 @@ export default class Minify extends Transform {
|
|
|
365
365
|
if (last) {
|
|
366
366
|
var lastStatement = last.consequent[last.consequent.length - 1];
|
|
367
367
|
if (
|
|
368
|
+
lastStatement &&
|
|
368
369
|
lastStatement.type == "BreakStatement" &&
|
|
369
370
|
lastStatement.label == null
|
|
370
371
|
) {
|
|
@@ -525,7 +526,7 @@ export default class Minify extends Transform {
|
|
|
525
526
|
if (key == "toString" && object.arguments.length == 0) {
|
|
526
527
|
this.replace(
|
|
527
528
|
object,
|
|
528
|
-
BinaryExpression("+", clone(object.callee.object)
|
|
529
|
+
BinaryExpression("+", Literal(""), clone(object.callee.object))
|
|
529
530
|
);
|
|
530
531
|
}
|
|
531
532
|
}
|
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
VariableDeclarator,
|
|
16
16
|
ConditionalExpression,
|
|
17
17
|
UnaryExpression,
|
|
18
|
+
ReturnStatement,
|
|
19
|
+
AssignmentPattern,
|
|
18
20
|
} from "../util/gen";
|
|
19
21
|
import {
|
|
20
22
|
choice,
|
|
@@ -93,10 +95,27 @@ export default class OpaquePredicates extends Transform {
|
|
|
93
95
|
if (!this.predicate) {
|
|
94
96
|
this.predicateName = this.getPlaceholder();
|
|
95
97
|
this.predicate = ObjectExpression([]);
|
|
98
|
+
|
|
99
|
+
var tempName = this.getPlaceholder();
|
|
100
|
+
|
|
96
101
|
prepend(
|
|
97
102
|
parents[parents.length - 1] || object,
|
|
98
103
|
VariableDeclaration(
|
|
99
|
-
VariableDeclarator(
|
|
104
|
+
VariableDeclarator(
|
|
105
|
+
this.predicateName,
|
|
106
|
+
CallExpression(
|
|
107
|
+
FunctionExpression(
|
|
108
|
+
[],
|
|
109
|
+
[
|
|
110
|
+
VariableDeclaration(
|
|
111
|
+
VariableDeclarator(tempName, this.predicate)
|
|
112
|
+
),
|
|
113
|
+
ReturnStatement(Identifier(tempName)),
|
|
114
|
+
]
|
|
115
|
+
),
|
|
116
|
+
[]
|
|
117
|
+
)
|
|
118
|
+
)
|
|
100
119
|
)
|
|
101
120
|
);
|
|
102
121
|
}
|
|
@@ -119,11 +138,14 @@ export default class OpaquePredicates extends Transform {
|
|
|
119
138
|
this.predicate.properties.push(
|
|
120
139
|
Property(Identifier(arrayProp), ArrayExpression([]))
|
|
121
140
|
);
|
|
141
|
+
|
|
142
|
+
var paramName = this.getPlaceholder();
|
|
143
|
+
|
|
122
144
|
this.predicate.properties.push(
|
|
123
145
|
Property(
|
|
124
146
|
Identifier(prop),
|
|
125
147
|
FunctionExpression(
|
|
126
|
-
[],
|
|
148
|
+
[AssignmentPattern(Identifier(paramName), Literal("length"))],
|
|
127
149
|
Template(`
|
|
128
150
|
if ( !${this.predicateName}.${arrayProp}[0] ) {
|
|
129
151
|
${this.predicateName}.${arrayProp}.push(${getRandomInteger(
|
|
@@ -131,7 +153,7 @@ export default class OpaquePredicates extends Transform {
|
|
|
131
153
|
100
|
|
132
154
|
)});
|
|
133
155
|
}
|
|
134
|
-
return ${this.predicateName}.${arrayProp}
|
|
156
|
+
return ${this.predicateName}.${arrayProp}[${paramName}];
|
|
135
157
|
`).compile()
|
|
136
158
|
)
|
|
137
159
|
)
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
ReturnStatement,
|
|
14
14
|
} from "../../util/gen";
|
|
15
15
|
import { ObfuscateOrder } from "../../order";
|
|
16
|
-
import { getIndexDirect, clone } from "../../util/insert";
|
|
16
|
+
import { getIndexDirect, clone, getFunction } from "../../util/insert";
|
|
17
17
|
import { ok } from "assert";
|
|
18
18
|
import { getIdentifierInfo } from "../../util/identifiers";
|
|
19
19
|
import { walk } from "../../traverse";
|
|
@@ -79,6 +79,13 @@ class ExplicitIdentifiers extends Transform {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
transform(object, parents) {
|
|
82
|
+
if (object.name === "eval") {
|
|
83
|
+
var fn = getFunction(object, parents);
|
|
84
|
+
if (fn) {
|
|
85
|
+
fn.$requiresEval = true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
82
89
|
var info = getIdentifierInfo(object, parents);
|
|
83
90
|
if (info.isPropertyKey || info.isAccessor) {
|
|
84
91
|
var propIndex = parents.findIndex(
|
|
@@ -24,13 +24,35 @@ export default class RenameLabels extends Transform {
|
|
|
24
24
|
transform(object, parents) {
|
|
25
25
|
return () => {
|
|
26
26
|
var newName = null;
|
|
27
|
+
var isRemovable = object.body.type !== "BlockStatement";
|
|
28
|
+
var labelNeverUsed = true;
|
|
27
29
|
|
|
28
30
|
walk(object, parents, (o, p) => {
|
|
29
31
|
if (o.type == "BreakStatement" || o.type == "ContinueStatement") {
|
|
30
|
-
|
|
32
|
+
function isContinuableStatement(x, stmtParents) {
|
|
33
|
+
return isLoop(x) && x.type !== "SwitchStatement";
|
|
34
|
+
}
|
|
35
|
+
function isBreakableStatement(x, stmtParents) {
|
|
36
|
+
return (
|
|
37
|
+
isLoop(x) ||
|
|
38
|
+
(x.type == "BlockStatement" &&
|
|
39
|
+
o.label &&
|
|
40
|
+
stmtParents[0] &&
|
|
41
|
+
stmtParents[0].type == "LabeledStatement")
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
var fn =
|
|
46
|
+
o.type == "ContinueStatement"
|
|
47
|
+
? isContinuableStatement
|
|
48
|
+
: isBreakableStatement;
|
|
49
|
+
|
|
50
|
+
var labelStatement = p.find((node, i) => {
|
|
51
|
+
return fn(node, p.slice(i + 1));
|
|
52
|
+
});
|
|
31
53
|
|
|
32
54
|
if (o.label && o.label.name == object.label.name) {
|
|
33
|
-
if (object.body == labelStatement) {
|
|
55
|
+
if (object.body == labelStatement && isRemovable) {
|
|
34
56
|
// In same loop
|
|
35
57
|
|
|
36
58
|
o.label = null;
|
|
@@ -39,6 +61,7 @@ export default class RenameLabels extends Transform {
|
|
|
39
61
|
newName = this.gen.generate();
|
|
40
62
|
}
|
|
41
63
|
o.label = Identifier(newName);
|
|
64
|
+
labelNeverUsed = false;
|
|
42
65
|
}
|
|
43
66
|
}
|
|
44
67
|
}
|
|
@@ -46,7 +69,7 @@ export default class RenameLabels extends Transform {
|
|
|
46
69
|
|
|
47
70
|
if (newName) {
|
|
48
71
|
object.label = Identifier(newName);
|
|
49
|
-
} else {
|
|
72
|
+
} else if (isRemovable || labelNeverUsed) {
|
|
50
73
|
this.replace(object, clone(object.body));
|
|
51
74
|
}
|
|
52
75
|
};
|
package/src/transforms/rgf.ts
CHANGED
|
@@ -76,6 +76,7 @@ export default class RGF extends Transform {
|
|
|
76
76
|
if (
|
|
77
77
|
object !== contextObject &&
|
|
78
78
|
isFunction(object) &&
|
|
79
|
+
!object.$requiresEval &&
|
|
79
80
|
!object.async &&
|
|
80
81
|
!object.generator &&
|
|
81
82
|
getVarContext(parents[0], parents.slice(1)) === contextObject
|
|
@@ -92,9 +93,12 @@ export default class RGF extends Transform {
|
|
|
92
93
|
!this.options.globalVariables.has(o.name)
|
|
93
94
|
) {
|
|
94
95
|
var info = getIdentifierInfo(o, p);
|
|
96
|
+
if (!info.spec.isReferenced) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
95
99
|
if (info.spec.isDefined) {
|
|
96
100
|
defined.add(o.name);
|
|
97
|
-
} else
|
|
101
|
+
} else {
|
|
98
102
|
referenced.add(o.name);
|
|
99
103
|
}
|
|
100
104
|
}
|
|
@@ -256,6 +260,7 @@ export default class RGF extends Transform {
|
|
|
256
260
|
integrity: false,
|
|
257
261
|
},
|
|
258
262
|
eval: false,
|
|
263
|
+
hideInitializingCode: false,
|
|
259
264
|
});
|
|
260
265
|
var transforms = Object.values(obfuscator.transforms).filter(
|
|
261
266
|
(x) => x.priority > this.priority
|
package/src/transforms/stack.ts
CHANGED
|
@@ -46,7 +46,8 @@ export default class Stack extends Transform {
|
|
|
46
46
|
isFunction(object) &&
|
|
47
47
|
!object.params.find((x) => x.type !== "Identifier") &&
|
|
48
48
|
object.body.type === "BlockStatement" &&
|
|
49
|
-
!parents.find((x) => x.$dispatcherSkip)
|
|
49
|
+
!parents.find((x) => x.$dispatcherSkip) &&
|
|
50
|
+
!object.$requiresEval
|
|
50
51
|
);
|
|
51
52
|
}
|
|
52
53
|
|