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.
Files changed (94) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/README.md +7 -6
  3. package/dist/options.js +5 -1
  4. package/dist/parser.js +1 -2
  5. package/dist/presets.js +2 -2
  6. package/dist/transforms/calculator.js +48 -60
  7. package/dist/transforms/controlFlowFlattening/controlFlowFlattening.js +482 -95
  8. package/dist/transforms/controlFlowFlattening/expressionObfuscation.js +4 -0
  9. package/dist/transforms/controlFlowFlattening/{switchCaseObfucation.js → switchCaseObfuscation.js} +2 -2
  10. package/dist/transforms/deadCode.js +1 -1
  11. package/dist/transforms/dispatcher.js +14 -13
  12. package/dist/transforms/extraction/duplicateLiteralsRemoval.js +5 -10
  13. package/dist/transforms/flatten.js +5 -1
  14. package/dist/transforms/hideInitializingCode.js +17 -2
  15. package/dist/transforms/identifier/globalConcealing.js +46 -25
  16. package/dist/transforms/identifier/movedDeclarations.js +69 -68
  17. package/dist/transforms/identifier/renameVariables.js +22 -98
  18. package/dist/transforms/identifier/variableAnalysis.js +133 -0
  19. package/dist/transforms/label.js +11 -2
  20. package/dist/transforms/lock/antiDebug.js +32 -13
  21. package/dist/transforms/lock/lock.js +13 -2
  22. package/dist/transforms/minify.js +117 -120
  23. package/dist/transforms/opaquePredicates.js +4 -2
  24. package/dist/transforms/preparation/preparation.js +8 -0
  25. package/dist/transforms/renameLabels.js +17 -3
  26. package/dist/transforms/rgf.js +8 -3
  27. package/dist/transforms/shuffle.js +25 -9
  28. package/dist/transforms/stack.js +5 -9
  29. package/dist/transforms/string/encoding.js +209 -0
  30. package/dist/transforms/string/stringCompression.js +10 -10
  31. package/dist/transforms/string/stringConcealing.js +94 -65
  32. package/dist/transforms/string/stringSplitting.js +7 -7
  33. package/dist/transforms/transform.js +10 -0
  34. package/dist/traverse.js +1 -35
  35. package/dist/util/gen.js +3 -1
  36. package/dist/util/identifiers.js +9 -19
  37. package/dist/util/insert.js +6 -40
  38. package/dist/util/scope.js +17 -0
  39. package/package.json +2 -2
  40. package/src/options.ts +19 -3
  41. package/src/parser.ts +1 -2
  42. package/src/presets.ts +2 -2
  43. package/src/transforms/calculator.ts +87 -91
  44. package/src/transforms/controlFlowFlattening/controlFlowFlattening.ts +742 -142
  45. package/src/transforms/controlFlowFlattening/expressionObfuscation.ts +6 -0
  46. package/src/transforms/controlFlowFlattening/{switchCaseObfucation.ts → switchCaseObfuscation.ts} +6 -2
  47. package/src/transforms/deadCode.ts +8 -0
  48. package/src/transforms/dispatcher.ts +29 -14
  49. package/src/transforms/extraction/duplicateLiteralsRemoval.ts +43 -19
  50. package/src/transforms/flatten.ts +15 -2
  51. package/src/transforms/hideInitializingCode.ts +432 -406
  52. package/src/transforms/identifier/globalConcealing.ts +148 -46
  53. package/src/transforms/identifier/movedDeclarations.ts +78 -101
  54. package/src/transforms/identifier/renameVariables.ts +21 -96
  55. package/src/transforms/identifier/variableAnalysis.ts +124 -0
  56. package/src/transforms/label.ts +20 -2
  57. package/src/transforms/lock/antiDebug.ts +69 -26
  58. package/src/transforms/lock/lock.ts +37 -3
  59. package/src/transforms/minify.ts +154 -130
  60. package/src/transforms/opaquePredicates.ts +25 -3
  61. package/src/transforms/preparation/preparation.ts +8 -1
  62. package/src/transforms/renameLabels.ts +26 -3
  63. package/src/transforms/rgf.ts +6 -1
  64. package/src/transforms/shuffle.ts +87 -29
  65. package/src/transforms/stack.ts +6 -8
  66. package/src/transforms/string/encoding.ts +310 -0
  67. package/src/transforms/string/stringCompression.ts +37 -24
  68. package/src/transforms/string/stringConcealing.ts +157 -160
  69. package/src/transforms/string/stringSplitting.ts +12 -8
  70. package/src/transforms/transform.ts +15 -2
  71. package/src/traverse.ts +1 -31
  72. package/src/util/gen.ts +5 -3
  73. package/src/util/identifiers.ts +20 -20
  74. package/src/util/insert.ts +12 -78
  75. package/src/util/scope.ts +9 -0
  76. package/test/{transforms/compare.test.ts → compare.test.ts} +2 -2
  77. package/test/index.test.ts +109 -1
  78. package/test/templates/template.test.ts +14 -0
  79. package/test/transforms/controlFlowFlattening/controlFlowFlattening.test.ts +392 -10
  80. package/test/transforms/dispatcher.test.ts +30 -0
  81. package/test/transforms/flatten.test.ts +28 -0
  82. package/test/transforms/hideInitializingCode.test.ts +336 -336
  83. package/test/transforms/identifier/globalConcealing.test.ts +1 -2
  84. package/test/transforms/identifier/movedDeclarations.test.ts +137 -112
  85. package/test/transforms/identifier/renameVariables.test.ts +124 -13
  86. package/test/transforms/lock/antiDebug.test.ts +43 -0
  87. package/test/transforms/lock/selfDefending.test.ts +68 -0
  88. package/test/transforms/minify.test.ts +137 -0
  89. package/test/transforms/renameLabels.test.ts +33 -0
  90. package/test/transforms/rgf.test.ts +29 -0
  91. package/test/transforms/string/stringSplitting.test.ts +33 -0
  92. package/test/util/identifiers.test.ts +105 -17
  93. package/dist/util/expr.js +0 -60
  94. package/src/util/expr.ts +0 -56
@@ -1,134 +1,159 @@
1
1
  import JsConfuser from "../../../src/index";
2
2
 
3
- it("should move variable declarations to the top of the lexical block", async () => {
4
- var output = await JsConfuser.obfuscate(
5
- `
6
- console.log("...")
7
- var a = 1, b = 2;
8
- console.log(a)
9
- `,
10
- {
11
- target: "node",
12
- movedDeclarations: true,
13
- }
14
- );
15
-
16
- expect(output).toContain("var a,b;");
17
- expect(output).toContain("a=1,b=2");
3
+ test("Variant #1: Move variable 'y' to top", async () => {
4
+ var code = `
5
+ var x = 10;
6
+ var y = 15;
7
+ TEST_VARIABLE = x + y;
8
+ `;
9
+
10
+ var output = await JsConfuser.obfuscate(code, {
11
+ target: "node",
12
+ movedDeclarations: true,
13
+ });
14
+
15
+ expect(output).toContain("var y;");
16
+ expect(output).toContain("y=15");
17
+
18
+ var TEST_VARIABLE;
19
+ eval(output);
20
+
21
+ expect(TEST_VARIABLE).toStrictEqual(25);
18
22
  });
19
23
 
20
- it("should still execute properly", async () => {
21
- var output = await JsConfuser.obfuscate(
22
- `
24
+ test("Variant #2: Move variable 'y' and 'z' to top", async () => {
25
+ var code = `
26
+ var x = 10;
27
+ var y = 15;
28
+ var z = 5;
29
+ TEST_VARIABLE = x + y + z;
30
+ `;
23
31
 
24
- function add(n1, n2){
25
- return n1 + n2;
26
- }
32
+ var output = await JsConfuser.obfuscate(code, {
33
+ target: "node",
34
+ movedDeclarations: true,
35
+ });
27
36
 
28
- var a = 6, b = 4;
37
+ expect(output).toContain("var y,z");
38
+ expect(output).toContain("y=15");
39
+ expect(output).toContain("z=5");
29
40
 
30
- input( add(a, b) );
31
- `,
32
- {
33
- target: "node",
34
- movedDeclarations: true,
35
- }
36
- );
41
+ var TEST_VARIABLE;
42
+ eval(output);
43
+
44
+ expect(TEST_VARIABLE).toStrictEqual(30);
45
+ });
37
46
 
38
- expect(output).toContain("var a,b;");
47
+ test("Variant #2: Don't move 'y' (destructuring)", async () => {
48
+ var code = `
49
+ var x = 10;
50
+ var [y] = [15];
51
+ TEST_VARIABLE = x + y;
52
+ `;
39
53
 
40
- var value = "never_called";
41
- function input(valueIn) {
42
- value = valueIn;
43
- }
54
+ var output = await JsConfuser.obfuscate(code, {
55
+ target: "node",
56
+ movedDeclarations: true,
57
+ });
44
58
 
59
+ expect(output).toContain("var [y]=[15];");
60
+
61
+ var TEST_VARIABLE;
45
62
  eval(output);
46
63
 
47
- expect(value).toStrictEqual(10);
64
+ expect(TEST_VARIABLE).toStrictEqual(25);
48
65
  });
49
66
 
50
- it("should not move declarations in for statements", async () => {
51
- var output = await JsConfuser.obfuscate(
52
- `
53
- for ( var i = 0; i < 10; i++ ) {
54
-
55
- }
56
- `,
57
- {
58
- target: "node",
59
- movedDeclarations: true,
60
- }
61
- );
62
-
63
- expect(output).toContain("for(var i=0;");
64
- });
67
+ test("Variant #3: Don't move 'y' (nested lexical scope)", async () => {
68
+ var code = `
69
+ var x = 10;
70
+ var y = 15;
65
71
 
66
- it("should not move redefined names", async () => {
67
- var output = await JsConfuser.obfuscate(
68
- `
69
- var a;
70
- var output;
71
72
  (function(){
72
- var a;
73
- var output;
73
+ y = 10;
74
74
  })();
75
- `,
76
- {
77
- target: "node",
78
- movedDeclarations: true,
79
- }
80
- );
81
-
82
- expect(output).toContain("var a;var output;");
75
+
76
+ TEST_VARIABLE = x + y;
77
+ `;
78
+
79
+ var output = await JsConfuser.obfuscate(code, {
80
+ target: "node",
81
+ movedDeclarations: true,
82
+ });
83
+
84
+ expect(output).toContain("var y=15");
85
+
86
+ var TEST_VARIABLE;
87
+ eval(output);
88
+
89
+ expect(TEST_VARIABLE).toStrictEqual(20);
90
+ });
91
+
92
+ test("Variant #4: Move 'y' (for statement initializer)", async () => {
93
+ var code = `
94
+ var x = 10;
95
+ for ( var y = 0; y < 15; y++ ) {
96
+
97
+ } // y ends as 15
98
+ TEST_VARIABLE = x + y;
99
+ `;
100
+
101
+ var output = await JsConfuser.obfuscate(code, {
102
+ target: "node",
103
+ movedDeclarations: true,
104
+ });
105
+
106
+ expect(output).not.toContain("var y=0;");
107
+
108
+ var TEST_VARIABLE;
109
+ eval(output);
110
+
111
+ expect(TEST_VARIABLE).toStrictEqual(25);
83
112
  });
84
113
 
85
- it("should not move declarations in switch cases", async () => {
86
- var output = await JsConfuser.obfuscate(
87
- `
88
- var b = 0;
89
- switch(b){
90
- case 0:
91
- var a = 0;
92
- break;
93
- case 1:
94
- a = 1;
95
- break;
96
- }
97
- `,
98
- {
99
- target: "node",
100
- movedDeclarations: true,
101
- }
102
- );
103
-
104
- expect(output).toContain("var a=0;");
114
+ test("Variant #5: Move 'y' (for-in left-hand initializer)", async () => {
115
+ var code = `
116
+ var x = 10;
117
+ for ( var y in [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] ) {
118
+
119
+ } // y ends as "15"
120
+ TEST_VARIABLE = x + parseInt(y);
121
+ `;
122
+
123
+ var output = await JsConfuser.obfuscate(code, {
124
+ target: "node",
125
+ movedDeclarations: true,
126
+ });
127
+
128
+ expect(output).not.toContain("var y in");
129
+ expect(output).toContain("y in");
130
+
131
+ var TEST_VARIABLE;
132
+ eval(output);
133
+
134
+ expect(TEST_VARIABLE).toStrictEqual(25);
105
135
  });
106
136
 
107
- it("should not move declarations in nested switch cases", async () => {
108
- var output = await JsConfuser.obfuscate(
109
- `
110
- var i = 1;
111
- while(i > 0){
112
- var b = 0;
113
- switch(b){
114
- case 0:
115
- var a = 0;
116
- break;
117
- case 1:
118
- a = 1;
119
- break;
120
- }
121
-
122
- i--;
123
- }
124
-
125
-
126
- `,
127
- {
128
- target: "node",
129
- movedDeclarations: true,
130
- }
131
- );
132
-
133
- expect(output).toContain("var a=0;");
137
+ test("Variant #6: Don't move const or let variables", async () => {
138
+ var code = `
139
+ var fillerExpr;
140
+
141
+ let x = 10;
142
+ const y = 15;
143
+
144
+ TEST_VARIABLE = x + y;
145
+ `;
146
+
147
+ var output = await JsConfuser.obfuscate(code, {
148
+ target: "node",
149
+ movedDeclarations: true,
150
+ });
151
+
152
+ expect(output).toContain("let x=10");
153
+ expect(output).toContain("const y=15");
154
+
155
+ var TEST_VARIABLE;
156
+ eval(output);
157
+
158
+ expect(TEST_VARIABLE).toStrictEqual(25);
134
159
  });
@@ -1,6 +1,6 @@
1
1
  import JsConfuser from "../../../src/index";
2
2
 
3
- it("should rename variables properly", async () => {
3
+ test("Variant #1: Rename variables properly", async () => {
4
4
  var code = "var TEST_VARIABLE = 1;";
5
5
  var output = await JsConfuser(code, {
6
6
  target: "browser",
@@ -13,7 +13,7 @@ it("should rename variables properly", async () => {
13
13
  expect(output).not.toContain("TEST_VARIABLE");
14
14
  });
15
15
 
16
- it("should not rename global accessors", async () => {
16
+ test("Variant #2: Don't rename global accessors", async () => {
17
17
  var code = `
18
18
  var TEST_VARIABLE = 1;
19
19
  success(TEST_VARIABLE); // success should not be renamed
@@ -38,7 +38,7 @@ it("should not rename global accessors", async () => {
38
38
  expect(passed).toStrictEqual(true);
39
39
  });
40
40
 
41
- it("should rename shadowed variables properly", async () => {
41
+ test("Variant #3: Rename shadowed variables properly", async () => {
42
42
  var code = `
43
43
  var TEST_VARIABLE = 1;
44
44
 
@@ -66,7 +66,7 @@ it("should rename shadowed variables properly", async () => {
66
66
  expect(value).toStrictEqual(10);
67
67
  });
68
68
 
69
- it("should not rename member properties", async () => {
69
+ test("Variant #4: Don't rename member properties", async () => {
70
70
  var code = `
71
71
 
72
72
  var TEST_OBJECT = { TEST_PROPERTY: 100 }
@@ -92,7 +92,7 @@ it("should not rename member properties", async () => {
92
92
  expect(value).toStrictEqual(100);
93
93
  });
94
94
 
95
- it("should handle variable defined with let (1)", async () => {
95
+ test("Variant #5: Handle variable defined with let (1)", async () => {
96
96
  var code = `
97
97
 
98
98
  // lexically bound
@@ -117,7 +117,7 @@ it("should handle variable defined with let (1)", async () => {
117
117
  expect(value).toStrictEqual(100);
118
118
  });
119
119
 
120
- it("should handle variable defined with let (2)", async () => {
120
+ test("Variant #6: Handle variable defined with let (2)", async () => {
121
121
  var code = `
122
122
 
123
123
  // lexically bound
@@ -145,7 +145,7 @@ it("should handle variable defined with let (2)", async () => {
145
145
  expect(value).toStrictEqual(100);
146
146
  });
147
147
 
148
- it("should handle variable defined with let (3)", async () => {
148
+ test("Variant #7: Handle variable defined with let (3)", async () => {
149
149
  var code = `
150
150
 
151
151
  // lexically bound
@@ -179,7 +179,7 @@ it("should handle variable defined with let (3)", async () => {
179
179
  expect(value).toStrictEqual(100);
180
180
  });
181
181
 
182
- it("should not rename null (reservedIdentifiers)", async () => {
182
+ test("Variant #8: Don't rename null (reservedIdentifiers)", async () => {
183
183
  var code = `
184
184
  input(null)
185
185
  `;
@@ -199,7 +199,7 @@ it("should not rename null (reservedIdentifiers)", async () => {
199
199
  expect(value).toStrictEqual(null);
200
200
  });
201
201
 
202
- it("should not rename exported names", async () => {
202
+ test("Variant #9: Don't rename exported names", async () => {
203
203
  var code = `
204
204
  export function abc(){
205
205
 
@@ -215,7 +215,7 @@ it("should not rename exported names", async () => {
215
215
  expect(output).toContain("abc");
216
216
  });
217
217
 
218
- it("should call renameVariables callback properly (variables)", async () => {
218
+ test("Variant #10: Call renameVariables callback properly (variables)", async () => {
219
219
  var code = `
220
220
  var myVariable = 1;
221
221
  `;
@@ -233,7 +233,7 @@ it("should call renameVariables callback properly (variables)", async () => {
233
233
  expect(input).toEqual(["myVariable", true]);
234
234
  });
235
235
 
236
- it("should call renameVariables callback properly (variables, nested)", async () => {
236
+ test("Variant #11: Call renameVariables callback properly (variables, nested)", async () => {
237
237
  var code = `
238
238
  (function(){
239
239
  var myVariable = 1;
@@ -253,7 +253,7 @@ it("should call renameVariables callback properly (variables, nested)", async ()
253
253
  expect(input).toEqual(["myVariable", false]);
254
254
  });
255
255
 
256
- it("should call renameVariables callback properly (function declaration)", async () => {
256
+ test("Variant #12: Call renameVariables callback properly (function declaration)", async () => {
257
257
  var code = `
258
258
  function myFunction(){
259
259
 
@@ -273,7 +273,7 @@ it("should call renameVariables callback properly (function declaration)", async
273
273
  expect(input).toEqual(["myFunction", true]);
274
274
  });
275
275
 
276
- it("should allow excluding custom variables from being renamed", async () => {
276
+ test("Variant #13: Allow excluding custom variables from being renamed", async () => {
277
277
  var code = `
278
278
  var myVariable1 = 1;
279
279
  var myVariable2 = 1;
@@ -290,3 +290,114 @@ it("should allow excluding custom variables from being renamed", async () => {
290
290
  expect(output).toContain("myVariable1");
291
291
  expect(output).not.toContain("myVariable2");
292
292
  });
293
+
294
+ test("Variant #14: should not break global variable references", async () => {
295
+ /**
296
+ * In this case `b` is a global variable,
297
+ *
298
+ * "mangled" names are a,b,c,d...
299
+ *
300
+ * therefore make sure `b` is NOT used as it breaks program
301
+ */
302
+ var code = `
303
+ var a = "";
304
+
305
+ function myFunction(param1, param2){
306
+ b(param1);
307
+ }
308
+
309
+ myFunction("Hello World");
310
+ `;
311
+
312
+ var output = await JsConfuser(code, {
313
+ target: "node",
314
+ renameVariables: true,
315
+ renameGlobals: true,
316
+ identifierGenerator: "mangled",
317
+ });
318
+
319
+ expect(output).not.toContain("b(b)");
320
+
321
+ var value;
322
+ function b(valueIn) {
323
+ value = valueIn;
324
+ }
325
+
326
+ eval(output);
327
+
328
+ expect(value).toStrictEqual("Hello World");
329
+ });
330
+
331
+ test("Variant #15: Function parameter default value", async () => {
332
+ /**
333
+ * In this case `b` is a global variable,
334
+ *
335
+ * "mangled" names are a,b,c,d...
336
+ *
337
+ * therefore make sure `b` is NOT used as it breaks program
338
+ */
339
+ var code = `
340
+ var a = "Filler Variables";
341
+ var b = "Hello World";
342
+ var c = "Another incorrect string";
343
+
344
+ function myFunction(param1 = ()=>{
345
+ return b;
346
+ }){
347
+ var b = param1();
348
+ if(false){
349
+ a,c;
350
+ }
351
+ input(b);
352
+ }
353
+
354
+ myFunction();
355
+ `;
356
+
357
+ var output = await JsConfuser(code, {
358
+ target: "node",
359
+ renameVariables: true,
360
+ renameGlobals: true,
361
+ identifierGenerator: "mangled",
362
+ });
363
+
364
+ var value;
365
+ function input(valueIn) {
366
+ value = valueIn;
367
+ }
368
+
369
+ eval(output);
370
+
371
+ expect(value).toStrictEqual("Hello World");
372
+ });
373
+
374
+ // https://github.com/MichaelXF/js-confuser/issues/24
375
+ test("Variant #16: Function with multiple parameters and a default value", async () => {
376
+ var code = `
377
+ function FuncA(param1, param2 = FuncB){
378
+ param2()
379
+ }
380
+
381
+ function FuncB(){
382
+ input("Success!");
383
+ }
384
+
385
+ FuncA();
386
+ `;
387
+
388
+ var output = await JsConfuser(code, {
389
+ target: "node",
390
+ renameVariables: true,
391
+ renameGlobals: true,
392
+ identifierGenerator: "mangled",
393
+ });
394
+
395
+ var value;
396
+ function input(valueIn) {
397
+ value = valueIn;
398
+ }
399
+
400
+ eval(output);
401
+
402
+ expect(value).toStrictEqual("Success!");
403
+ });
@@ -21,3 +21,46 @@ it("add a background interval", async () => {
21
21
 
22
22
  expect(output).toContain("setInterval");
23
23
  });
24
+
25
+ it("should place syntax-correct code", async () => {
26
+ for (var i = 0; i < 50; i++) {
27
+ var output = await JsConfuser.obfuscate(
28
+ `
29
+ /**
30
+ * GitHub: https://github.com/MichaelXF/js-confuser
31
+ * NPM: https://www.npmjs.com/package/js-confuser
32
+ *
33
+ * Welcome to Js Confuser
34
+ *
35
+ * You can obfuscate the code with the top right button 'Obfuscate'.
36
+ *
37
+ * You can customize the obfuscator with the button 'Options'.
38
+ * (Set the target to 'node' for NodeJS apps)
39
+ *
40
+ * Happy Hacking!
41
+ */
42
+
43
+ function greet(name){
44
+ var output = "Hello " + name + "!";
45
+ }
46
+
47
+ greet("Internet User");
48
+
49
+ `,
50
+ {
51
+ compact: true,
52
+ controlFlowFlattening: 0.25,
53
+ identifierGenerator: "randomized",
54
+ lock: { antiDebug: true },
55
+ minify: true,
56
+ target: "node",
57
+ }
58
+ );
59
+
60
+ try {
61
+ eval(output);
62
+ } catch (e) {
63
+ expect(e).toStrictEqual(undefined);
64
+ }
65
+ }
66
+ });
@@ -0,0 +1,68 @@
1
+ import JsConfuser from "../../../src/index";
2
+
3
+ test("Variant #1: SelfDefending should forcibly enable `compact`", async () => {
4
+ var output = await JsConfuser.obfuscate(`console.log(1)`, {
5
+ target: "node",
6
+ compact: false,
7
+ lock: {
8
+ selfDefending: true,
9
+ },
10
+ });
11
+
12
+ expect(output).not.toContain("\n");
13
+ });
14
+
15
+ test("Variant #2: SelfDefending should not crash when unchanged", async () => {
16
+ var output = await JsConfuser.obfuscate(
17
+ `
18
+ function caught(){
19
+ TEST_CAUGHT = true;
20
+ }
21
+ TEST_VAR = 100;
22
+ `,
23
+ {
24
+ target: "node",
25
+ lock: {
26
+ selfDefending: true,
27
+ countermeasures: "caught",
28
+ },
29
+ }
30
+ );
31
+
32
+ var TEST_VAR, TEST_CAUGHT;
33
+
34
+ eval(output);
35
+
36
+ expect(TEST_VAR).toStrictEqual(100);
37
+ expect(TEST_CAUGHT).toStrictEqual(undefined);
38
+ });
39
+
40
+ test("Variant #2: SelfDefending should crash when changed", async () => {
41
+ var output = await JsConfuser.obfuscate(
42
+ `
43
+ function caught(){
44
+ TEST_CAUGHT = true;
45
+ }
46
+ TEST_VAR = 100;
47
+ `,
48
+ {
49
+ target: "node",
50
+ lock: {
51
+ selfDefending: true,
52
+ countermeasures: "caught",
53
+ },
54
+ }
55
+ );
56
+
57
+ // Re-run through obfuscator without compact = new lines = crash should occur
58
+ var output2 = await JsConfuser.obfuscate(output, {
59
+ target: "node",
60
+ compact: false,
61
+ });
62
+
63
+ var TEST_VAR, TEST_CAUGHT;
64
+
65
+ eval(output2);
66
+
67
+ expect(TEST_CAUGHT).toStrictEqual(true);
68
+ });