js-confuser 1.5.9 → 1.7.0
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/.github/workflows/node.js.yml +2 -2
- package/CHANGELOG.md +55 -0
- package/README.md +346 -165
- package/dist/constants.js +6 -2
- package/dist/index.js +9 -21
- package/dist/obfuscator.js +19 -31
- package/dist/options.js +5 -5
- package/dist/order.js +1 -3
- package/dist/presets.js +6 -7
- package/dist/probability.js +2 -4
- package/dist/templates/bufferToString.js +13 -0
- package/dist/templates/crash.js +3 -3
- package/dist/templates/es5.js +18 -0
- package/dist/templates/functionLength.js +16 -0
- package/dist/transforms/calculator.js +77 -21
- package/dist/transforms/controlFlowFlattening/controlFlowFlattening.js +980 -367
- package/dist/transforms/controlFlowFlattening/expressionObfuscation.js +4 -1
- package/dist/transforms/controlFlowFlattening/switchCaseObfuscation.js +25 -26
- package/dist/transforms/deadCode.js +33 -25
- package/dist/transforms/dispatcher.js +8 -4
- package/dist/transforms/es5/antiDestructuring.js +2 -0
- package/dist/transforms/es5/es5.js +31 -34
- package/dist/transforms/extraction/duplicateLiteralsRemoval.js +92 -58
- package/dist/transforms/finalizer.js +82 -0
- package/dist/transforms/flatten.js +229 -148
- package/dist/transforms/identifier/globalAnalysis.js +88 -0
- package/dist/transforms/identifier/globalConcealing.js +10 -83
- package/dist/transforms/identifier/movedDeclarations.js +35 -88
- package/dist/transforms/identifier/renameVariables.js +124 -59
- package/dist/transforms/identifier/variableAnalysis.js +58 -62
- package/dist/transforms/lock/lock.js +0 -37
- package/dist/transforms/minify.js +60 -57
- package/dist/transforms/opaquePredicates.js +1 -1
- package/dist/transforms/preparation/preparation.js +2 -2
- package/dist/transforms/preparation.js +231 -0
- package/dist/transforms/renameLabels.js +1 -1
- package/dist/transforms/rgf.js +139 -247
- package/dist/transforms/stack.js +128 -26
- package/dist/transforms/string/encoding.js +150 -179
- package/dist/transforms/string/stringCompression.js +14 -15
- package/dist/transforms/string/stringConcealing.js +25 -8
- package/dist/transforms/string/stringEncoding.js +13 -24
- package/dist/transforms/transform.js +12 -19
- package/dist/traverse.js +24 -10
- package/dist/util/gen.js +17 -1
- package/dist/util/identifiers.js +37 -3
- package/dist/util/insert.js +35 -4
- package/dist/util/random.js +15 -0
- package/docs/ControlFlowFlattening.md +595 -0
- package/{Countermeasures.md → docs/Countermeasures.md} +1 -15
- package/{Integrity.md → docs/Integrity.md} +2 -2
- package/docs/RGF.md +419 -0
- package/package.json +5 -5
- package/src/constants.ts +3 -0
- package/src/index.ts +2 -2
- package/src/obfuscator.ts +19 -31
- package/src/options.ts +14 -103
- package/src/order.ts +1 -5
- package/src/presets.ts +6 -7
- package/src/probability.ts +2 -3
- package/src/templates/bufferToString.ts +68 -0
- package/src/templates/crash.ts +15 -19
- package/src/templates/es5.ts +131 -0
- package/src/templates/functionLength.ts +14 -0
- package/src/transforms/calculator.ts +122 -59
- package/src/transforms/controlFlowFlattening/controlFlowFlattening.ts +1583 -571
- package/src/transforms/controlFlowFlattening/expressionObfuscation.ts +4 -1
- package/src/transforms/deadCode.ts +383 -26
- package/src/transforms/dispatcher.ts +9 -4
- package/src/transforms/es5/antiDestructuring.ts +2 -0
- package/src/transforms/es5/es5.ts +32 -77
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +133 -129
- package/src/transforms/{hexadecimalNumbers.ts → finalizer.ts} +29 -13
- package/src/transforms/flatten.ts +357 -300
- package/src/transforms/identifier/globalAnalysis.ts +85 -0
- package/src/transforms/identifier/globalConcealing.ts +14 -103
- package/src/transforms/identifier/movedDeclarations.ts +49 -102
- package/src/transforms/identifier/renameVariables.ts +149 -78
- package/src/transforms/identifier/variableAnalysis.ts +66 -73
- package/src/transforms/lock/lock.ts +1 -42
- package/src/transforms/minify.ts +91 -75
- package/src/transforms/opaquePredicates.ts +2 -2
- package/src/transforms/preparation.ts +238 -0
- package/src/transforms/renameLabels.ts +2 -2
- package/src/transforms/rgf.ts +213 -405
- package/src/transforms/stack.ts +156 -36
- package/src/transforms/string/encoding.ts +115 -212
- package/src/transforms/string/stringCompression.ts +27 -18
- package/src/transforms/string/stringConcealing.ts +39 -9
- package/src/transforms/string/stringEncoding.ts +18 -18
- package/src/transforms/transform.ts +21 -23
- package/src/traverse.ts +23 -4
- package/src/types.ts +2 -1
- package/src/util/gen.ts +28 -3
- package/src/util/identifiers.ts +43 -2
- package/src/util/insert.ts +38 -3
- package/src/util/random.ts +13 -0
- package/test/code/Cash.test.ts +1 -1
- package/test/code/Dynamic.test.ts +12 -10
- package/test/code/ES6.src.js +146 -0
- package/test/code/ES6.test.ts +28 -2
- package/test/index.test.ts +2 -1
- package/test/probability.test.ts +44 -0
- package/test/templates/template.test.ts +1 -1
- package/test/transforms/antiTooling.test.ts +22 -0
- package/test/transforms/calculator.test.ts +40 -0
- package/test/transforms/controlFlowFlattening/controlFlowFlattening.test.ts +702 -160
- package/test/transforms/controlFlowFlattening/expressionObfuscation.test.ts +173 -0
- package/test/transforms/deadCode.test.ts +66 -15
- package/test/transforms/dispatcher.test.ts +20 -1
- package/test/transforms/es5/antiDestructuring.test.ts +16 -0
- package/test/transforms/flatten.test.ts +399 -86
- package/test/transforms/identifier/movedDeclarations.test.ts +63 -8
- package/test/transforms/identifier/renameVariables.test.ts +119 -0
- package/test/transforms/lock/antiDebug.test.ts +2 -2
- package/test/transforms/lock/lock.test.ts +1 -48
- package/test/transforms/minify.test.ts +104 -0
- package/test/transforms/preparation.test.ts +157 -0
- package/test/transforms/rgf.test.ts +261 -381
- package/test/transforms/stack.test.ts +143 -21
- package/test/transforms/string/stringCompression.test.ts +39 -0
- package/test/transforms/string/stringConcealing.test.ts +82 -0
- package/test/transforms/string/stringEncoding.test.ts +53 -2
- package/test/transforms/transform.test.ts +66 -0
- package/test/traverse.test.ts +139 -0
- package/test/util/identifiers.test.ts +113 -1
- package/test/util/insert.test.ts +57 -3
- package/src/transforms/controlFlowFlattening/choiceFlowObfuscation.ts +0 -87
- package/src/transforms/controlFlowFlattening/controlFlowObfuscation.ts +0 -203
- package/src/transforms/controlFlowFlattening/switchCaseObfuscation.ts +0 -130
- package/src/transforms/eval.ts +0 -89
- package/src/transforms/hideInitializingCode.ts +0 -432
- package/src/transforms/identifier/nameRecycling.ts +0 -280
- package/src/transforms/label.ts +0 -64
- package/src/transforms/preparation/nameConflicts.ts +0 -102
- package/src/transforms/preparation/preparation.ts +0 -176
- package/test/transforms/controlFlowFlattening/controlFlowObfuscation.test.ts +0 -101
- package/test/transforms/controlFlowFlattening/switchCaseObfuscation.test.ts +0 -120
- package/test/transforms/eval.test.ts +0 -131
- package/test/transforms/hideInitializingCode.test.ts +0 -336
- package/test/transforms/identifier/nameRecycling.test.ts +0 -205
- package/test/transforms/preparation/nameConflicts.test.ts +0 -52
- package/test/transforms/preparation/preparation.test.ts +0 -62
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
import JsConfuser from "../../src/index";
|
|
2
|
-
|
|
3
|
-
test("Variant #1: Do not apply with exported names", async () => {
|
|
4
|
-
var output = await JsConfuser.obfuscate(
|
|
5
|
-
`
|
|
6
|
-
export function myFunction(){
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
`,
|
|
10
|
-
{
|
|
11
|
-
target: "node",
|
|
12
|
-
hideInitializingCode: true,
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
expect(output).not.toContain("__p_");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test("Variant #2: Add ternary expressions and wrap initializing code in a function and still work", async () => {
|
|
20
|
-
var output = await JsConfuser.obfuscate(
|
|
21
|
-
`
|
|
22
|
-
var myNumber = 10;
|
|
23
|
-
input(myNumber)
|
|
24
|
-
`,
|
|
25
|
-
{
|
|
26
|
-
target: "node",
|
|
27
|
-
hideInitializingCode: true,
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
expect(output).toContain("__p_");
|
|
32
|
-
expect(output).toContain("function ");
|
|
33
|
-
expect(output).toContain("?");
|
|
34
|
-
|
|
35
|
-
var value = "never_called";
|
|
36
|
-
function input(valueIn) {
|
|
37
|
-
value = valueIn;
|
|
38
|
-
}
|
|
39
|
-
eval(output);
|
|
40
|
-
|
|
41
|
-
expect(value).toStrictEqual(10);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("Variant #3: Should work with other function declarations", async () => {
|
|
45
|
-
var output = await JsConfuser.obfuscate(
|
|
46
|
-
`
|
|
47
|
-
var myNumber = myFunction();
|
|
48
|
-
input(myNumber)
|
|
49
|
-
|
|
50
|
-
function myFunction(){
|
|
51
|
-
return 10;
|
|
52
|
-
}
|
|
53
|
-
`,
|
|
54
|
-
{
|
|
55
|
-
target: "node",
|
|
56
|
-
hideInitializingCode: true,
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
expect(output).toContain("__p_");
|
|
61
|
-
expect(output).toContain("function ");
|
|
62
|
-
|
|
63
|
-
var value = "never_called";
|
|
64
|
-
function input(valueIn) {
|
|
65
|
-
value = valueIn;
|
|
66
|
-
}
|
|
67
|
-
eval(output);
|
|
68
|
-
|
|
69
|
-
expect(value).toStrictEqual(10);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("Variant #4: Should work when doubly obfuscated", async () => {
|
|
73
|
-
var output = await JsConfuser.obfuscate(
|
|
74
|
-
`
|
|
75
|
-
var myNumber = myFunction();
|
|
76
|
-
input(myNumber)
|
|
77
|
-
|
|
78
|
-
function myFunction(){
|
|
79
|
-
return 10;
|
|
80
|
-
}
|
|
81
|
-
`,
|
|
82
|
-
{
|
|
83
|
-
target: "node",
|
|
84
|
-
hideInitializingCode: true,
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
expect(output).toContain("__p_");
|
|
89
|
-
expect(output).toContain("function ");
|
|
90
|
-
|
|
91
|
-
var doublyObfuscated = await JsConfuser.obfuscate(output, {
|
|
92
|
-
target: "node",
|
|
93
|
-
hideInitializingCode: true,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
var value = "never_called";
|
|
97
|
-
function input(valueIn) {
|
|
98
|
-
value = valueIn;
|
|
99
|
-
}
|
|
100
|
-
eval(doublyObfuscated);
|
|
101
|
-
|
|
102
|
-
expect(value).toStrictEqual(10);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test("Variant #5: Should bring up variable declarations", async () => {
|
|
106
|
-
var output = await JsConfuser.obfuscate(
|
|
107
|
-
`
|
|
108
|
-
var myNumber = 10;
|
|
109
|
-
function myFunction(){
|
|
110
|
-
return myNumber;
|
|
111
|
-
}
|
|
112
|
-
input(myFunction())
|
|
113
|
-
`,
|
|
114
|
-
{
|
|
115
|
-
target: "node",
|
|
116
|
-
hideInitializingCode: true,
|
|
117
|
-
}
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
expect(output).toContain("__p_");
|
|
121
|
-
expect(output).toContain("function ");
|
|
122
|
-
expect(output).toContain("var myNumber;");
|
|
123
|
-
expect(output).toContain("myNumber=");
|
|
124
|
-
|
|
125
|
-
var value = "never_called";
|
|
126
|
-
function input(valueIn) {
|
|
127
|
-
value = valueIn;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
eval(output);
|
|
131
|
-
|
|
132
|
-
expect(value).toStrictEqual(10);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test("Variant #6: Should not bring up variable declarations in nested contexts", async () => {
|
|
136
|
-
var output = await JsConfuser.obfuscate(
|
|
137
|
-
`
|
|
138
|
-
function myFunction(){
|
|
139
|
-
function myNestedFunction(){
|
|
140
|
-
var myNumber = 10;
|
|
141
|
-
return myNumber;
|
|
142
|
-
}
|
|
143
|
-
return myNestedFunction();
|
|
144
|
-
}
|
|
145
|
-
input(myFunction())
|
|
146
|
-
`,
|
|
147
|
-
{
|
|
148
|
-
target: "node",
|
|
149
|
-
hideInitializingCode: true,
|
|
150
|
-
}
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
expect(output).toContain("__p_");
|
|
154
|
-
expect(output).toContain("function ");
|
|
155
|
-
expect(output).toContain("var myNumber=");
|
|
156
|
-
|
|
157
|
-
var value = "never_called";
|
|
158
|
-
function input(valueIn) {
|
|
159
|
-
value = valueIn;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
eval(output);
|
|
163
|
-
|
|
164
|
-
expect(value).toStrictEqual(10);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test("Variant #7: Should bring up class declarations", async () => {
|
|
168
|
-
var output = await JsConfuser.obfuscate(
|
|
169
|
-
`
|
|
170
|
-
|
|
171
|
-
class MyClass {
|
|
172
|
-
static getNumber(){
|
|
173
|
-
return 10;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function myFunction(){
|
|
178
|
-
return MyClass.getNumber();
|
|
179
|
-
}
|
|
180
|
-
input(myFunction())
|
|
181
|
-
`,
|
|
182
|
-
{
|
|
183
|
-
target: "node",
|
|
184
|
-
hideInitializingCode: true,
|
|
185
|
-
}
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
expect(output).toContain("__p_");
|
|
189
|
-
expect(output).toContain("function ");
|
|
190
|
-
expect(output).toContain("var MyClass;");
|
|
191
|
-
expect(output).toContain("MyClass=class MyClass{");
|
|
192
|
-
|
|
193
|
-
var value = "never_called";
|
|
194
|
-
function input(valueIn) {
|
|
195
|
-
value = valueIn;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
eval(output);
|
|
199
|
-
|
|
200
|
-
expect(value).toStrictEqual(10);
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
test("Variant #8: Should bring up variable declarations in for statements", async () => {
|
|
204
|
-
var output = await JsConfuser.obfuscate(
|
|
205
|
-
`
|
|
206
|
-
|
|
207
|
-
for(var i=0; i <= 9; i++){
|
|
208
|
-
|
|
209
|
-
} // i ends as 10
|
|
210
|
-
|
|
211
|
-
function myFunction(){
|
|
212
|
-
return i;
|
|
213
|
-
}
|
|
214
|
-
input(myFunction())
|
|
215
|
-
`,
|
|
216
|
-
{
|
|
217
|
-
target: "node",
|
|
218
|
-
hideInitializingCode: true,
|
|
219
|
-
}
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
expect(output).toContain("__p_");
|
|
223
|
-
expect(output).toContain("function ");
|
|
224
|
-
|
|
225
|
-
var value = "never_called";
|
|
226
|
-
function input(valueIn) {
|
|
227
|
-
value = valueIn;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
eval(output);
|
|
231
|
-
|
|
232
|
-
expect(value).toStrictEqual(10);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
test("Variant #9: Should bring up variable declarations in for in statements", async () => {
|
|
236
|
-
var output = await JsConfuser.obfuscate(
|
|
237
|
-
`
|
|
238
|
-
|
|
239
|
-
var myNumber = 0;
|
|
240
|
-
var myArray = [0,1,2,3,4,5,6,7,8,9,10];
|
|
241
|
-
for(var i in myArray){
|
|
242
|
-
if(i==10){
|
|
243
|
-
myNumber = 10;
|
|
244
|
-
}
|
|
245
|
-
} // i ends as "10"
|
|
246
|
-
|
|
247
|
-
function myFunction(){
|
|
248
|
-
return parseInt(i);
|
|
249
|
-
}
|
|
250
|
-
input(myFunction())
|
|
251
|
-
`,
|
|
252
|
-
{
|
|
253
|
-
target: "node",
|
|
254
|
-
hideInitializingCode: true,
|
|
255
|
-
}
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
expect(output).toContain("__p_");
|
|
259
|
-
expect(output).toContain("function ");
|
|
260
|
-
|
|
261
|
-
var value = "never_called";
|
|
262
|
-
function input(valueIn) {
|
|
263
|
-
value = valueIn;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
eval(output);
|
|
267
|
-
|
|
268
|
-
expect(value).toStrictEqual(10);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
test("Variant #10: Should work with multiple variable declarations", async () => {
|
|
272
|
-
var output = await JsConfuser.obfuscate(
|
|
273
|
-
`
|
|
274
|
-
|
|
275
|
-
var myNumber1 = 3, myNumber2 = 2;
|
|
276
|
-
|
|
277
|
-
function myFunction(){
|
|
278
|
-
return myNumber1*2 + myNumber2*2;
|
|
279
|
-
}
|
|
280
|
-
input(myFunction())
|
|
281
|
-
`,
|
|
282
|
-
{
|
|
283
|
-
target: "node",
|
|
284
|
-
hideInitializingCode: true,
|
|
285
|
-
}
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
expect(output).toContain("__p_");
|
|
289
|
-
expect(output).toContain("function ");
|
|
290
|
-
|
|
291
|
-
var value = "never_called";
|
|
292
|
-
function input(valueIn) {
|
|
293
|
-
value = valueIn;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
eval(output);
|
|
297
|
-
|
|
298
|
-
expect(value).toStrictEqual(10);
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
test("Variant #11: Should bring up variable declaration but not default values function expression's variables", async () => {
|
|
302
|
-
var output = await JsConfuser.obfuscate(
|
|
303
|
-
`
|
|
304
|
-
|
|
305
|
-
var [myNumber1 = function(){
|
|
306
|
-
var myNumber = 2;
|
|
307
|
-
}] = [10];
|
|
308
|
-
|
|
309
|
-
function myFunction(){
|
|
310
|
-
return myNumber1;
|
|
311
|
-
}
|
|
312
|
-
input(myFunction())
|
|
313
|
-
`,
|
|
314
|
-
{
|
|
315
|
-
target: "node",
|
|
316
|
-
hideInitializingCode: true,
|
|
317
|
-
}
|
|
318
|
-
);
|
|
319
|
-
|
|
320
|
-
expect(output).toContain("__p_");
|
|
321
|
-
expect(output).toContain("function ");
|
|
322
|
-
expect(output).toContain("var myNumber1;");
|
|
323
|
-
expect(output).toContain("[myNumber1");
|
|
324
|
-
expect(output).toContain("=[");
|
|
325
|
-
|
|
326
|
-
expect(output).toContain("var myNumber=");
|
|
327
|
-
|
|
328
|
-
var value = "never_called";
|
|
329
|
-
function input(valueIn) {
|
|
330
|
-
value = valueIn;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
eval(output);
|
|
334
|
-
|
|
335
|
-
expect(value).toStrictEqual(10);
|
|
336
|
-
});
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import JsConfuser from "../../../src/index";
|
|
2
|
-
|
|
3
|
-
it("should reuse released names", async () => {
|
|
4
|
-
var output = await JsConfuser(
|
|
5
|
-
`
|
|
6
|
-
var a = "Hello World";
|
|
7
|
-
TEST_VAR_1 = a;
|
|
8
|
-
var b = "Name Recycling"
|
|
9
|
-
TEST_VAR_2 = b;
|
|
10
|
-
`,
|
|
11
|
-
{
|
|
12
|
-
target: "node",
|
|
13
|
-
nameRecycling: true,
|
|
14
|
-
renameGlobals: true,
|
|
15
|
-
}
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
expect(output).not.toContain("b=");
|
|
19
|
-
expect(output).not.toContain("b;");
|
|
20
|
-
|
|
21
|
-
var TEST_VAR_1, TEST_VAR_2;
|
|
22
|
-
|
|
23
|
-
eval(output);
|
|
24
|
-
|
|
25
|
-
expect(TEST_VAR_1).toStrictEqual("Hello World");
|
|
26
|
-
expect(TEST_VAR_2).toStrictEqual("Name Recycling");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("should not reuse released names when in nested context", async () => {
|
|
30
|
-
var output = await JsConfuser(
|
|
31
|
-
`
|
|
32
|
-
var fn = function(){
|
|
33
|
-
TEST_VAR_3 = b;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
var a = "Hello World";
|
|
37
|
-
TEST_VAR_1 = a;
|
|
38
|
-
var b = "Name Recycling"
|
|
39
|
-
TEST_VAR_2 = b;
|
|
40
|
-
|
|
41
|
-
fn()
|
|
42
|
-
|
|
43
|
-
`,
|
|
44
|
-
{
|
|
45
|
-
target: "node",
|
|
46
|
-
nameRecycling: true,
|
|
47
|
-
renameGlobals: true,
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
expect(output).toContain("b=");
|
|
52
|
-
|
|
53
|
-
var TEST_VAR_1, TEST_VAR_2, TEST_VAR_3;
|
|
54
|
-
|
|
55
|
-
eval(output);
|
|
56
|
-
|
|
57
|
-
expect(TEST_VAR_1).toStrictEqual("Hello World");
|
|
58
|
-
expect(TEST_VAR_2).toStrictEqual("Name Recycling");
|
|
59
|
-
expect(TEST_VAR_3).toStrictEqual("Name Recycling");
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should convert function declarations to assignment expressions", async () => {
|
|
63
|
-
var output = await JsConfuser(
|
|
64
|
-
`
|
|
65
|
-
var a = "Hello World";
|
|
66
|
-
TEST_VAR_1 = a;
|
|
67
|
-
function b(){
|
|
68
|
-
TEST_VAR_2 = "Name Recycling"
|
|
69
|
-
}
|
|
70
|
-
b()
|
|
71
|
-
`,
|
|
72
|
-
{
|
|
73
|
-
target: "node",
|
|
74
|
-
nameRecycling: true,
|
|
75
|
-
renameGlobals: true,
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
expect(output).not.toContain("b()");
|
|
80
|
-
expect(output).toContain("a=function()");
|
|
81
|
-
|
|
82
|
-
var TEST_VAR_1, TEST_VAR_2;
|
|
83
|
-
|
|
84
|
-
eval(output);
|
|
85
|
-
|
|
86
|
-
expect(TEST_VAR_1).toStrictEqual("Hello World");
|
|
87
|
-
expect(TEST_VAR_2).toStrictEqual("Name Recycling");
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("should convert class declarations to assignment expressions", async () => {
|
|
91
|
-
var output = await JsConfuser(
|
|
92
|
-
`
|
|
93
|
-
var a = "Hello World";
|
|
94
|
-
TEST_VAR_1 = a;
|
|
95
|
-
class b {
|
|
96
|
-
constructor(){
|
|
97
|
-
TEST_VAR_2 = "Name Recycling"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
var c = new b()
|
|
101
|
-
`,
|
|
102
|
-
{
|
|
103
|
-
target: "node",
|
|
104
|
-
nameRecycling: true,
|
|
105
|
-
renameGlobals: true,
|
|
106
|
-
}
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
var TEST_VAR_1, TEST_VAR_2;
|
|
110
|
-
|
|
111
|
-
eval(output);
|
|
112
|
-
|
|
113
|
-
expect(TEST_VAR_1).toStrictEqual("Hello World");
|
|
114
|
-
expect(TEST_VAR_2).toStrictEqual("Name Recycling");
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("should convert variable declarations with multiple declarators properly", async () => {
|
|
118
|
-
var output = await JsConfuser(
|
|
119
|
-
`
|
|
120
|
-
var a = "Hello World", b;
|
|
121
|
-
TEST_VAR_1 = a;
|
|
122
|
-
var c = "Name Recycling", d = "JsConfuser";
|
|
123
|
-
TEST_VAR_2 = c;
|
|
124
|
-
TEST_VAR_3 = d;
|
|
125
|
-
`,
|
|
126
|
-
{
|
|
127
|
-
target: "node",
|
|
128
|
-
nameRecycling: true,
|
|
129
|
-
renameGlobals: true,
|
|
130
|
-
}
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
var TEST_VAR_1, TEST_VAR_2, TEST_VAR_3;
|
|
134
|
-
|
|
135
|
-
eval(output);
|
|
136
|
-
|
|
137
|
-
expect(TEST_VAR_1).toStrictEqual("Hello World");
|
|
138
|
-
expect(TEST_VAR_2).toStrictEqual("Name Recycling");
|
|
139
|
-
expect(TEST_VAR_3).toStrictEqual("JsConfuser");
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("should convert variable declarations in for loop initializers properly", async () => {
|
|
143
|
-
var output = await JsConfuser(
|
|
144
|
-
`
|
|
145
|
-
var a = "Hello World";
|
|
146
|
-
TEST_VAR_1 = a;
|
|
147
|
-
for ( var b = 0; b < 1; b++ ) {
|
|
148
|
-
TEST_VAR_2 = "Number: " + b;
|
|
149
|
-
}
|
|
150
|
-
`,
|
|
151
|
-
{
|
|
152
|
-
target: "node",
|
|
153
|
-
nameRecycling: true,
|
|
154
|
-
renameGlobals: true,
|
|
155
|
-
}
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
expect(output).toContain("for(a=0");
|
|
159
|
-
|
|
160
|
-
var TEST_VAR_1, TEST_VAR_2;
|
|
161
|
-
|
|
162
|
-
eval(output);
|
|
163
|
-
|
|
164
|
-
expect(TEST_VAR_1).toStrictEqual("Hello World");
|
|
165
|
-
expect(TEST_VAR_2).toStrictEqual("Number: 0");
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// https://github.com/MichaelXF/js-confuser/issues/68
|
|
169
|
-
it("should work on Function Declarations that are defined later in the code", async () => {
|
|
170
|
-
var output = await JsConfuser(
|
|
171
|
-
`
|
|
172
|
-
var result = MyFunction();
|
|
173
|
-
TEST_VAR = result;
|
|
174
|
-
|
|
175
|
-
function MyFunction(b) {
|
|
176
|
-
return "Hello World";
|
|
177
|
-
}
|
|
178
|
-
`,
|
|
179
|
-
{ target: "node", nameRecycling: true }
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
var TEST_VAR;
|
|
183
|
-
eval(output);
|
|
184
|
-
|
|
185
|
-
expect(TEST_VAR).toStrictEqual("Hello World");
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// https://github.com/MichaelXF/js-confuser/issues/71
|
|
189
|
-
it("should work on Import Declarations", async () => {
|
|
190
|
-
var output = await JsConfuser(
|
|
191
|
-
`
|
|
192
|
-
import crypto from 'node:crypto'
|
|
193
|
-
|
|
194
|
-
var x = 1;
|
|
195
|
-
|
|
196
|
-
console.log(x);
|
|
197
|
-
`,
|
|
198
|
-
{
|
|
199
|
-
target: "node",
|
|
200
|
-
nameRecycling: true,
|
|
201
|
-
}
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
expect(output).not.toContain("crypto=");
|
|
205
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import JsConfuser from "../../../src/index";
|
|
2
|
-
|
|
3
|
-
it("should fix name conflicts for easier AST parsing", async () => {
|
|
4
|
-
var output = await JsConfuser.obfuscate(
|
|
5
|
-
`
|
|
6
|
-
|
|
7
|
-
var TEST=1;
|
|
8
|
-
|
|
9
|
-
function example(){
|
|
10
|
-
var TEST = 2;
|
|
11
|
-
}
|
|
12
|
-
`,
|
|
13
|
-
{
|
|
14
|
-
target: "browser",
|
|
15
|
-
objectExtraction: true, // <- something needs to be enabled
|
|
16
|
-
}
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
// expect(output).toContain("var _TEST=2");
|
|
20
|
-
expect(typeof output).toStrictEqual("string");
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("should properly execute with names resolved", async () => {
|
|
24
|
-
var output = await JsConfuser.obfuscate(
|
|
25
|
-
`
|
|
26
|
-
|
|
27
|
-
var TEST= -10;
|
|
28
|
-
|
|
29
|
-
function example(){
|
|
30
|
-
var TEST = 100;
|
|
31
|
-
input(TEST)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
example();
|
|
35
|
-
`,
|
|
36
|
-
{
|
|
37
|
-
target: "browser",
|
|
38
|
-
objectExtraction: true, // <- something needs to be enabled
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
var value = "never_called";
|
|
43
|
-
function input(valueIn) {
|
|
44
|
-
value = valueIn;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// expect(output).toContain("var _TEST=100");
|
|
48
|
-
|
|
49
|
-
eval(output);
|
|
50
|
-
|
|
51
|
-
expect(value).toStrictEqual(100);
|
|
52
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import JsConfuser from "../../../src/index";
|
|
2
|
-
|
|
3
|
-
it("should force blocks to be block statements (if statement)", async () => {
|
|
4
|
-
var output = await JsConfuser.obfuscate(
|
|
5
|
-
`
|
|
6
|
-
if ( a ) b();
|
|
7
|
-
|
|
8
|
-
if ( a ) {} else c()
|
|
9
|
-
`,
|
|
10
|
-
{
|
|
11
|
-
target: "node",
|
|
12
|
-
objectExtraction: true, // <- something needs to enabled
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
expect(output).toContain("{b()}");
|
|
17
|
-
expect(output).toContain("{c()}");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("should force blocks to be block statements (arrow function)", async () => {
|
|
21
|
-
var output = await JsConfuser.obfuscate(
|
|
22
|
-
`
|
|
23
|
-
var arrowFn = ()=>true;
|
|
24
|
-
`,
|
|
25
|
-
{
|
|
26
|
-
target: "node",
|
|
27
|
-
objectExtraction: true, // <- something needs to enabled
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
expect(output).toContain("return");
|
|
32
|
-
expect(output).toContain("{");
|
|
33
|
-
expect(output).toContain("}");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("should force blocks to be block statements", async () => {
|
|
37
|
-
var output = await JsConfuser.obfuscate(
|
|
38
|
-
`
|
|
39
|
-
if ( a ) b()
|
|
40
|
-
`,
|
|
41
|
-
{
|
|
42
|
-
target: "node",
|
|
43
|
-
objectExtraction: true, // <- something needs to enabled
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
expect(output).toContain("{b()}");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should force explicit member expressions", async () => {
|
|
51
|
-
var output = await JsConfuser.obfuscate(
|
|
52
|
-
`
|
|
53
|
-
console.log('...')
|
|
54
|
-
`,
|
|
55
|
-
{
|
|
56
|
-
target: "node",
|
|
57
|
-
objectExtraction: true, // <- something needs to enabled
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
expect(output).toContain("console['log']");
|
|
62
|
-
});
|