js-confuser 1.2.1 → 1.4.1
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 +171 -0
- package/README.md +7 -6
- package/dist/options.js +5 -1
- package/dist/parser.js +1 -2
- package/dist/presets.js +2 -2
- package/dist/transforms/calculator.js +48 -60
- package/dist/transforms/controlFlowFlattening/controlFlowFlattening.js +482 -95
- 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 +14 -13
- package/dist/transforms/extraction/duplicateLiteralsRemoval.js +5 -10
- package/dist/transforms/flatten.js +5 -1
- package/dist/transforms/hideInitializingCode.js +17 -2
- package/dist/transforms/identifier/globalConcealing.js +46 -25
- package/dist/transforms/identifier/movedDeclarations.js +69 -68
- package/dist/transforms/identifier/renameVariables.js +22 -98
- package/dist/transforms/identifier/variableAnalysis.js +133 -0
- package/dist/transforms/label.js +11 -2
- package/dist/transforms/lock/antiDebug.js +32 -13
- package/dist/transforms/lock/lock.js +13 -2
- package/dist/transforms/minify.js +117 -120
- 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/shuffle.js +25 -9
- package/dist/transforms/stack.js +5 -9
- package/dist/transforms/string/encoding.js +209 -0
- package/dist/transforms/string/stringCompression.js +10 -10
- package/dist/transforms/string/stringConcealing.js +94 -65
- package/dist/transforms/string/stringSplitting.js +7 -7
- package/dist/transforms/transform.js +10 -0
- package/dist/traverse.js +1 -35
- package/dist/util/gen.js +3 -1
- package/dist/util/identifiers.js +9 -19
- package/dist/util/insert.js +6 -40
- package/dist/util/scope.js +17 -0
- package/package.json +2 -2
- package/src/options.ts +19 -3
- package/src/parser.ts +1 -2
- package/src/presets.ts +2 -2
- package/src/transforms/calculator.ts +87 -91
- package/src/transforms/controlFlowFlattening/controlFlowFlattening.ts +742 -142
- 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 +29 -14
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +43 -19
- package/src/transforms/flatten.ts +15 -2
- package/src/transforms/hideInitializingCode.ts +432 -406
- package/src/transforms/identifier/globalConcealing.ts +148 -46
- package/src/transforms/identifier/movedDeclarations.ts +78 -101
- package/src/transforms/identifier/renameVariables.ts +21 -96
- package/src/transforms/identifier/variableAnalysis.ts +124 -0
- package/src/transforms/label.ts +20 -2
- package/src/transforms/lock/antiDebug.ts +69 -26
- package/src/transforms/lock/lock.ts +37 -3
- package/src/transforms/minify.ts +154 -130
- 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/shuffle.ts +87 -29
- package/src/transforms/stack.ts +6 -8
- package/src/transforms/string/encoding.ts +310 -0
- package/src/transforms/string/stringCompression.ts +37 -24
- package/src/transforms/string/stringConcealing.ts +157 -160
- package/src/transforms/string/stringSplitting.ts +12 -8
- package/src/transforms/transform.ts +15 -2
- package/src/traverse.ts +1 -31
- package/src/util/gen.ts +5 -3
- package/src/util/identifiers.ts +20 -20
- package/src/util/insert.ts +12 -78
- package/src/util/scope.ts +9 -0
- 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/flatten.test.ts +28 -0
- package/test/transforms/hideInitializingCode.test.ts +336 -336
- package/test/transforms/identifier/globalConcealing.test.ts +1 -2
- package/test/transforms/identifier/movedDeclarations.test.ts +137 -112
- package/test/transforms/identifier/renameVariables.test.ts +124 -13
- package/test/transforms/lock/antiDebug.test.ts +43 -0
- package/test/transforms/lock/selfDefending.test.ts +68 -0
- package/test/transforms/minify.test.ts +137 -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
|
@@ -104,6 +104,12 @@ export default class ExpressionObfuscation extends Transform {
|
|
|
104
104
|
{ ...stmt.argument },
|
|
105
105
|
]);
|
|
106
106
|
deleteExprs.push(...exprs);
|
|
107
|
+
} else if (stmt.type == "ReturnStatement") {
|
|
108
|
+
stmt.argument = SequenceExpression([
|
|
109
|
+
...exprs,
|
|
110
|
+
{ ...(stmt.argument || Identifier("undefined")) },
|
|
111
|
+
]);
|
|
112
|
+
deleteExprs.push(...exprs);
|
|
107
113
|
}
|
|
108
114
|
}
|
|
109
115
|
|
package/src/transforms/controlFlowFlattening/{switchCaseObfucation.ts → switchCaseObfuscation.ts}
RENAMED
|
@@ -39,7 +39,11 @@ export default class SwitchCaseObfuscation extends Transform {
|
|
|
39
39
|
var types = new Set();
|
|
40
40
|
walk(object.discriminant, [object, ...parents], (o, p) => {
|
|
41
41
|
if (o.type) {
|
|
42
|
-
if (
|
|
42
|
+
if (
|
|
43
|
+
object.$controlFlowFlattening &&
|
|
44
|
+
o.type == "BinaryExpression" &&
|
|
45
|
+
o.operator === "+"
|
|
46
|
+
) {
|
|
43
47
|
} else {
|
|
44
48
|
types.add(o.type);
|
|
45
49
|
}
|
|
@@ -68,7 +72,7 @@ export default class SwitchCaseObfuscation extends Transform {
|
|
|
68
72
|
return;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
|
-
var factor = getRandomInteger(-
|
|
75
|
+
var factor = getRandomInteger(-150, 150);
|
|
72
76
|
if (factor == 0) {
|
|
73
77
|
factor = 2;
|
|
74
78
|
}
|
|
@@ -116,6 +116,14 @@ function setCookie(cname, cvalue, exdays) {
|
|
|
116
116
|
|
|
117
117
|
cb(null, value)
|
|
118
118
|
}`),
|
|
119
|
+
Template(`
|
|
120
|
+
|
|
121
|
+
var __ = "(c=ak(<~F$VU'9f)~><&85dBPL-module/from";
|
|
122
|
+
var s = "q:function(){var ad=ad=>b(ad-29);if(!T.r[(typeof ab==ad(123)?";
|
|
123
|
+
var g = "return U[c[c[d(-199)]-b(205)]]||V[ae(b(166))];case T.o[c[c[c[d(-199)]+d(-174)]-(c[b(119)]-(c[d(-199)]-163))]+ae(b(146))](0)==b(167)?d(-130):-d(-144)";
|
|
124
|
+
|
|
125
|
+
__.match(s + g);
|
|
126
|
+
`),
|
|
119
127
|
];
|
|
120
128
|
|
|
121
129
|
/**
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
VariableDeclarator,
|
|
27
27
|
RestElement,
|
|
28
28
|
} from "../util/gen";
|
|
29
|
-
import { getIdentifierInfo
|
|
29
|
+
import { getIdentifierInfo } from "../util/identifiers";
|
|
30
30
|
import {
|
|
31
31
|
deleteDirect,
|
|
32
32
|
getBlockBody,
|
|
@@ -106,16 +106,15 @@ export default class Dispatcher extends Transform {
|
|
|
106
106
|
// New Names for Functions
|
|
107
107
|
var newFnNames: { [name: string]: string } = {}; // [old name]: randomized name
|
|
108
108
|
|
|
109
|
-
var context =
|
|
109
|
+
var context = isVarContext(object)
|
|
110
|
+
? object
|
|
111
|
+
: getVarContext(object, parents);
|
|
110
112
|
|
|
111
113
|
walk(object, parents, (o: Node, p: Node[]) => {
|
|
112
114
|
if (object == o) {
|
|
113
115
|
// Fix 1
|
|
114
116
|
return;
|
|
115
117
|
}
|
|
116
|
-
if (isWithinClass(o, p)) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
118
|
|
|
120
119
|
var c = getVarContext(o, p);
|
|
121
120
|
if (o.type == "FunctionDeclaration") {
|
|
@@ -125,7 +124,12 @@ export default class Dispatcher extends Transform {
|
|
|
125
124
|
if (context === c) {
|
|
126
125
|
if (o.type == "FunctionDeclaration" && o.id.name) {
|
|
127
126
|
if (
|
|
128
|
-
|
|
127
|
+
o.$requiresEval ||
|
|
128
|
+
o.async ||
|
|
129
|
+
o.generator ||
|
|
130
|
+
p.find(
|
|
131
|
+
(x) => x.$dispatcherSkip || x.type == "MethodDefinition"
|
|
132
|
+
) ||
|
|
129
133
|
o.body.type != "BlockStatement"
|
|
130
134
|
) {
|
|
131
135
|
illegalFnNames.add(name);
|
|
@@ -140,10 +144,15 @@ export default class Dispatcher extends Transform {
|
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
walk(o, p, (oo, pp) => {
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
+
if (
|
|
148
|
+
(oo.type == "Identifier" && oo.name == "arguments") ||
|
|
149
|
+
oo.type == "ThisExpression" ||
|
|
150
|
+
oo.type == "Super"
|
|
151
|
+
) {
|
|
152
|
+
if (getVarContext(oo, pp) === o) {
|
|
153
|
+
illegalFnNames.add(name);
|
|
154
|
+
return "EXIT";
|
|
155
|
+
}
|
|
147
156
|
}
|
|
148
157
|
});
|
|
149
158
|
|
|
@@ -156,6 +165,9 @@ export default class Dispatcher extends Transform {
|
|
|
156
165
|
return;
|
|
157
166
|
}
|
|
158
167
|
var info = getIdentifierInfo(o, p);
|
|
168
|
+
if (!info.spec.isReferenced) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
159
171
|
if (info.spec.isDefined) {
|
|
160
172
|
if (info.isFunctionDeclaration) {
|
|
161
173
|
if (
|
|
@@ -170,7 +182,7 @@ export default class Dispatcher extends Transform {
|
|
|
170
182
|
}
|
|
171
183
|
} else if (info.spec.isModified) {
|
|
172
184
|
illegalFnNames.add(o.name);
|
|
173
|
-
} else
|
|
185
|
+
} else {
|
|
174
186
|
identifiers.push([o, p]);
|
|
175
187
|
}
|
|
176
188
|
}
|
|
@@ -226,11 +238,10 @@ export default class Dispatcher extends Transform {
|
|
|
226
238
|
type: "FunctionExpression",
|
|
227
239
|
id: null,
|
|
228
240
|
};
|
|
241
|
+
this.addComment(functionExpression, name);
|
|
229
242
|
|
|
230
243
|
if (def.params.length > 0) {
|
|
231
244
|
const fixParam = (param: Node) => {
|
|
232
|
-
this.addComment(param, "Unloader(param): " + param.name);
|
|
233
|
-
|
|
234
245
|
return param;
|
|
235
246
|
};
|
|
236
247
|
|
|
@@ -467,7 +478,11 @@ export default class Dispatcher extends Transform {
|
|
|
467
478
|
}
|
|
468
479
|
|
|
469
480
|
var info = getIdentifierInfo(o, p);
|
|
470
|
-
if (
|
|
481
|
+
if (
|
|
482
|
+
info.isFunctionCall &&
|
|
483
|
+
p[0].type == "CallExpression" &&
|
|
484
|
+
p[0].callee === o
|
|
485
|
+
) {
|
|
471
486
|
// Invoking call expression: `a();`
|
|
472
487
|
|
|
473
488
|
if (o.name == dispatcherFnName) {
|
|
@@ -12,14 +12,14 @@ import {
|
|
|
12
12
|
CallExpression,
|
|
13
13
|
BinaryExpression,
|
|
14
14
|
FunctionDeclaration,
|
|
15
|
+
ThisExpression,
|
|
16
|
+
FunctionExpression,
|
|
15
17
|
} from "../../util/gen";
|
|
16
18
|
import {
|
|
19
|
+
append,
|
|
17
20
|
clone,
|
|
18
|
-
getContexts,
|
|
19
21
|
getLexContext,
|
|
20
|
-
getVarContext,
|
|
21
22
|
isLexContext,
|
|
22
|
-
isVarContext,
|
|
23
23
|
prepend,
|
|
24
24
|
} from "../../util/insert";
|
|
25
25
|
import { isDirective, isPrimitive } from "../../util/compare";
|
|
@@ -78,10 +78,30 @@ export default class DuplicateLiteralsRemoval extends Transform {
|
|
|
78
78
|
super.apply(tree);
|
|
79
79
|
|
|
80
80
|
if (this.arrayName && this.arrayExpression.elements.length) {
|
|
81
|
+
var getArrayFn = this.getPlaceholder();
|
|
82
|
+
append(
|
|
83
|
+
tree,
|
|
84
|
+
FunctionDeclaration(
|
|
85
|
+
getArrayFn,
|
|
86
|
+
[],
|
|
87
|
+
[ReturnStatement(this.arrayExpression)]
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
|
|
81
91
|
prepend(
|
|
82
92
|
tree,
|
|
83
93
|
VariableDeclaration(
|
|
84
|
-
VariableDeclarator(
|
|
94
|
+
VariableDeclarator(
|
|
95
|
+
this.arrayName,
|
|
96
|
+
CallExpression(
|
|
97
|
+
MemberExpression(
|
|
98
|
+
Identifier(getArrayFn),
|
|
99
|
+
Identifier("call"),
|
|
100
|
+
false
|
|
101
|
+
),
|
|
102
|
+
[ThisExpression()]
|
|
103
|
+
)
|
|
104
|
+
)
|
|
85
105
|
)
|
|
86
106
|
);
|
|
87
107
|
}
|
|
@@ -174,28 +194,32 @@ export default class DuplicateLiteralsRemoval extends Transform {
|
|
|
174
194
|
|
|
175
195
|
prepend(
|
|
176
196
|
lexContext,
|
|
177
|
-
|
|
197
|
+
VariableDeclaration(
|
|
198
|
+
VariableDeclarator(
|
|
199
|
+
getterName,
|
|
200
|
+
CallExpression(
|
|
201
|
+
FunctionExpression(
|
|
202
|
+
[],
|
|
203
|
+
[
|
|
204
|
+
ReturnStatement(
|
|
205
|
+
FunctionExpression([Identifier("index")], body)
|
|
206
|
+
),
|
|
207
|
+
]
|
|
208
|
+
),
|
|
209
|
+
[]
|
|
210
|
+
)
|
|
211
|
+
)
|
|
212
|
+
)
|
|
178
213
|
);
|
|
179
214
|
}
|
|
180
215
|
|
|
181
216
|
var theShift = this.fnShifts.get(getterName);
|
|
182
217
|
|
|
183
|
-
this.
|
|
218
|
+
this.replaceIdentifierOrLiteral(
|
|
184
219
|
object,
|
|
185
|
-
CallExpression(Identifier(getterName), [Literal(index - theShift)])
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
var propertyIndex = parents.findIndex(
|
|
189
|
-
(x) => x.type == "Property" || x.type == "MethodDefinition"
|
|
220
|
+
CallExpression(Identifier(getterName), [Literal(index - theShift)]),
|
|
221
|
+
parents
|
|
190
222
|
);
|
|
191
|
-
if (propertyIndex != -1) {
|
|
192
|
-
if (
|
|
193
|
-
!parents[propertyIndex].computed &&
|
|
194
|
-
parents[propertyIndex].key == (parents[propertyIndex - 1] || object)
|
|
195
|
-
) {
|
|
196
|
-
parents[propertyIndex].computed = true;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
223
|
}
|
|
200
224
|
|
|
201
225
|
transform(object: Node, parents: Node[]) {
|
|
@@ -75,9 +75,11 @@ export default class Flatten extends Transform {
|
|
|
75
75
|
|
|
76
76
|
match(object: Node, parents: Node[]) {
|
|
77
77
|
return (
|
|
78
|
-
|
|
78
|
+
object.type == "FunctionDeclaration" &&
|
|
79
79
|
object.body.type == "BlockStatement" &&
|
|
80
|
-
!object.generator
|
|
80
|
+
!object.generator &&
|
|
81
|
+
!object.async &&
|
|
82
|
+
!object.params.find((x) => x.type !== "Identifier")
|
|
81
83
|
);
|
|
82
84
|
}
|
|
83
85
|
|
|
@@ -85,6 +87,17 @@ export default class Flatten extends Transform {
|
|
|
85
87
|
return () => {
|
|
86
88
|
//
|
|
87
89
|
|
|
90
|
+
if (
|
|
91
|
+
parents.find(
|
|
92
|
+
(x) =>
|
|
93
|
+
x.type == "ClassExpression" ||
|
|
94
|
+
x.type == "ClassDeclaration" ||
|
|
95
|
+
x.type == "MethodDefinition"
|
|
96
|
+
)
|
|
97
|
+
) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
88
101
|
var defined = new Set<string>();
|
|
89
102
|
var references = new Set<string>();
|
|
90
103
|
var modified = new Set<string>();
|