js-confuser 1.6.0 → 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.
Files changed (59) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +215 -170
  3. package/dist/constants.js +6 -2
  4. package/dist/obfuscator.js +0 -6
  5. package/dist/options.js +4 -4
  6. package/dist/presets.js +6 -7
  7. package/dist/templates/crash.js +2 -2
  8. package/dist/templates/functionLength.js +16 -0
  9. package/dist/transforms/dispatcher.js +4 -1
  10. package/dist/transforms/extraction/duplicateLiteralsRemoval.js +89 -58
  11. package/dist/transforms/flatten.js +224 -147
  12. package/dist/transforms/identifier/movedDeclarations.js +38 -85
  13. package/dist/transforms/identifier/renameVariables.js +94 -41
  14. package/dist/transforms/lock/lock.js +0 -37
  15. package/dist/transforms/minify.js +2 -2
  16. package/dist/transforms/rgf.js +139 -246
  17. package/dist/transforms/stack.js +42 -1
  18. package/dist/transforms/transform.js +1 -1
  19. package/dist/util/gen.js +2 -1
  20. package/dist/util/identifiers.js +37 -3
  21. package/dist/util/insert.js +24 -3
  22. package/docs/ControlFlowFlattening.md +595 -0
  23. package/{Countermeasures.md → docs/Countermeasures.md} +1 -15
  24. package/{Integrity.md → docs/Integrity.md} +2 -2
  25. package/docs/RGF.md +419 -0
  26. package/package.json +1 -1
  27. package/src/constants.ts +3 -0
  28. package/src/obfuscator.ts +0 -4
  29. package/src/options.ts +9 -86
  30. package/src/presets.ts +6 -7
  31. package/src/templates/crash.ts +10 -10
  32. package/src/templates/functionLength.ts +14 -0
  33. package/src/transforms/dispatcher.ts +5 -1
  34. package/src/transforms/extraction/duplicateLiteralsRemoval.ts +130 -129
  35. package/src/transforms/flatten.ts +357 -290
  36. package/src/transforms/identifier/movedDeclarations.ts +50 -96
  37. package/src/transforms/identifier/renameVariables.ts +120 -56
  38. package/src/transforms/lock/lock.ts +1 -42
  39. package/src/transforms/minify.ts +11 -2
  40. package/src/transforms/rgf.ts +214 -404
  41. package/src/transforms/stack.ts +62 -0
  42. package/src/transforms/transform.ts +6 -2
  43. package/src/util/gen.ts +7 -2
  44. package/src/util/identifiers.ts +43 -2
  45. package/src/util/insert.ts +26 -2
  46. package/test/code/ES6.src.js +24 -0
  47. package/test/transforms/flatten.test.ts +352 -88
  48. package/test/transforms/identifier/movedDeclarations.test.ts +37 -9
  49. package/test/transforms/identifier/renameVariables.test.ts +37 -0
  50. package/test/transforms/lock/lock.test.ts +1 -48
  51. package/test/transforms/minify.test.ts +19 -0
  52. package/test/transforms/rgf.test.ts +262 -353
  53. package/test/transforms/stack.test.ts +52 -0
  54. package/test/util/identifiers.test.ts +113 -1
  55. package/test/util/insert.test.ts +57 -3
  56. package/src/transforms/eval.ts +0 -89
  57. package/src/transforms/identifier/nameRecycling.ts +0 -280
  58. package/test/transforms/eval.test.ts +0 -131
  59. package/test/transforms/identifier/nameRecycling.test.ts +0 -205
@@ -582,3 +582,40 @@ test("Variant #23: Re-use previously generated names", async () => {
582
582
 
583
583
  expect(TEST_OUTPUT).toStrictEqual("Correct Value");
584
584
  });
585
+
586
+ test("Variant #24: Reference function name with parameter", async () => {
587
+ var output = await JsConfuser(
588
+ `
589
+ function myFunction(myFunction){
590
+ myFunction.property = "Correct Value";
591
+ }
592
+
593
+ myFunction(myFunction);
594
+ TEST_OUTPUT = myFunction.property;
595
+ `,
596
+ { target: "node", renameVariables: true }
597
+ );
598
+
599
+ var TEST_OUTPUT;
600
+ eval(output);
601
+
602
+ expect(TEST_OUTPUT).toStrictEqual("Correct Value");
603
+ });
604
+
605
+ test("Variant #25: Reference catch parameter", async () => {
606
+ var output = await JsConfuser(
607
+ `
608
+ try {
609
+ throw "Correct Value";
610
+ } catch ( e ) {
611
+ TEST_OUTPUT = e;
612
+ }
613
+ `,
614
+ { target: "node", renameVariables: true }
615
+ );
616
+
617
+ var TEST_OUTPUT;
618
+ eval(output);
619
+
620
+ expect(TEST_OUTPUT).toStrictEqual("Correct Value");
621
+ });
@@ -64,6 +64,7 @@ it("should work with endDate and call countermeasures function", async () => {
64
64
  expect(value).toStrictEqual(true);
65
65
  });
66
66
 
67
+ // REMOVED FEATURE:
67
68
  // it("strings should be encoded when startDate and endDate are given", async () => {
68
69
  // var startDate = await JsConfuser.obfuscate(` input("ENCODED_STRING") `, {
69
70
  // target: "node",
@@ -82,54 +83,6 @@ it("should work with endDate and call countermeasures function", async () => {
82
83
  // expect(value).toStrictEqual("ENCODED_STRING");
83
84
  // });
84
85
 
85
- it("should work with nativeFunctions and call countermeasures function", async () => {
86
- var output = await JsConfuser.obfuscate(
87
- ` function countermeasures(){ input(true) } `,
88
- {
89
- target: "node",
90
- lock: {
91
- nativeFunctions: ["fetch"],
92
- countermeasures: "countermeasures",
93
- },
94
- }
95
- );
96
-
97
- // custom function, not "native"
98
- var fetch = () => {};
99
-
100
- var value = "never_called";
101
- function input(valueIn) {
102
- value = valueIn;
103
- }
104
-
105
- eval(output);
106
- expect(value).toStrictEqual(true);
107
- });
108
-
109
- it("should work with nativeFunctions and not call countermeasures function when correct", async () => {
110
- var output = await JsConfuser.obfuscate(
111
- ` function countermeasures(){ input(true) } `,
112
- {
113
- target: "node",
114
- lock: {
115
- nativeFunctions: ["fetch"],
116
- countermeasures: "countermeasures",
117
- },
118
- }
119
- );
120
-
121
- // bound functions return the "[native code]" string
122
- var fetch = (() => {}).bind(this);
123
-
124
- var value = "never_called";
125
- function input(valueIn) {
126
- value = valueIn;
127
- }
128
-
129
- eval(output);
130
- expect(value).toStrictEqual("never_called");
131
- });
132
-
133
86
  it("countermeasures function should still work even with renameVariables enabled", async () => {
134
87
  var output = await JsConfuser.obfuscate(
135
88
  ` function countermeasures(){ input(true) } `,
@@ -517,3 +517,22 @@ test("Variant #26: Don't break nested redefined function declaration", async ()
517
517
 
518
518
  expect(TEST_OUTPUT).toStrictEqual(1);
519
519
  });
520
+
521
+ // https://github.com/MichaelXF/js-confuser/issues/91
522
+ test("Variant #27: Preserve function.length property", async () => {
523
+ var output = await JsConfuser(
524
+ `
525
+ function oneParameter(a){};
526
+ var twoParameters = function({a},{b,c},...d){};
527
+ function threeParameters(a,b,c,d = 1,{e},...f){};
528
+
529
+ TEST_OUTPUT = oneParameter.length + twoParameters.length + threeParameters.length;
530
+ `,
531
+ { target: "node", minify: true }
532
+ );
533
+
534
+ var TEST_OUTPUT;
535
+ eval(output);
536
+
537
+ expect(TEST_OUTPUT).toStrictEqual(6);
538
+ });