js-confuser 1.5.1 → 1.5.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 CHANGED
@@ -1,3 +1,12 @@
1
+ # `1.5.2`
2
+ Mini fixes
3
+
4
+ - Fixed [#41](https://github.com/MichaelXF/js-confuser/issues/41)
5
+ - - Obfuscator mishandled switch statements with a `default` case
6
+
7
+ - Fixed [#43](https://github.com/MichaelXF/js-confuser/issues/43)
8
+ - - Obfuscator mishandled variable destructuring in for-loops
9
+
1
10
  # `1.5.1`
2
11
  Object Extraction Fix
3
12
 
@@ -28,7 +28,7 @@ class SwitchCaseObfuscation extends _transform.default {
28
28
  }
29
29
 
30
30
  match(object, parents) {
31
- return object.type == "SwitchStatement" && !object.cases.find(x => !(x.test.type == "Literal" && typeof x.test.value === "number" && Math.abs(x.test.value) < 100000));
31
+ return object.type == "SwitchStatement" && !object.cases.find(x => !(x.test && typeof x.test === "object" && x.test.type == "Literal" && typeof x.test.value === "number" && Math.abs(x.test.value) < 100000));
32
32
  }
33
33
 
34
34
  transform(object, parents) {
@@ -457,7 +457,7 @@ class Minify extends _transform.default {
457
457
  } // check for redundant patterns
458
458
 
459
459
 
460
- if (object.id.type == "ArrayPattern" && object.init.type == "ArrayExpression") {
460
+ if (object.id.type == "ArrayPattern" && object.init && typeof object.init === "object" && object.init.type == "ArrayExpression") {
461
461
  if (object.id.elements.length == 1 && object.init.elements.length == 1) {
462
462
  object.id = object.id.elements[0];
463
463
  object.init = object.init.elements[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-confuser",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "JavaScript Obfuscation Tool.",
5
5
  "main": "dist/index.js",
6
6
  "types": "index.d.ts",
@@ -27,6 +27,8 @@ export default class SwitchCaseObfuscation extends Transform {
27
27
  !object.cases.find(
28
28
  (x) =>
29
29
  !(
30
+ x.test &&
31
+ typeof x.test === "object" &&
30
32
  x.test.type == "Literal" &&
31
33
  typeof x.test.value === "number" &&
32
34
  Math.abs(x.test.value) < 100_000
@@ -595,6 +595,8 @@ export default class Minify extends Transform {
595
595
  // check for redundant patterns
596
596
  if (
597
597
  object.id.type == "ArrayPattern" &&
598
+ object.init &&
599
+ typeof object.init === "object" &&
598
600
  object.init.type == "ArrayExpression"
599
601
  ) {
600
602
  if (
@@ -74,3 +74,47 @@ it("should not obfuscate switch statements with complex discriminants (SwitchCas
74
74
 
75
75
  eval(output);
76
76
  });
77
+
78
+ // https://github.com/MichaelXF/js-confuser/issues/41
79
+ it("Not apply to switch statements with default cases", async ()=>{
80
+
81
+ var code = `
82
+ var array = [];
83
+
84
+ function runOnce(stateParam){
85
+ switch(stateParam){
86
+ case 1: array.push(1, 2, 3); break;
87
+ case 2: array.push(4, 5, 6); break;
88
+ case 3: array.push(7, 8, 9); break;
89
+ default: array.push(10); break;
90
+ }
91
+ }
92
+
93
+ runOnce(1);
94
+ runOnce(2);
95
+ runOnce(3);
96
+ runOnce(-1); // default case
97
+
98
+ input(array);
99
+ `;
100
+
101
+ var output = await JsConfuser(code, {
102
+ target: "browser",
103
+ controlFlowFlattening: true,
104
+ });
105
+
106
+ expect(
107
+ output.includes("case 1:") &&
108
+ output.includes("case 2:") &&
109
+ output.includes("case 3:")
110
+ ).toStrictEqual(true);
111
+
112
+ function input(array) {
113
+ expect(array).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
114
+ }
115
+
116
+ eval(output);
117
+
118
+
119
+
120
+ });
@@ -299,3 +299,25 @@ test("Variant #15: Removing implied 'return'", async () => {
299
299
 
300
300
  expect(output2).toContain("return");
301
301
  });
302
+
303
+ // https://github.com/MichaelXF/js-confuser/issues/43
304
+ test("Variant #16: Handle deconstructuring in for loop", async ()=>{
305
+ // Valid
306
+ var output = await JsConfuser(
307
+ `
308
+ for(const [a] of [[1]]) {
309
+ input(a);
310
+ }
311
+ `,
312
+ { target: "node", minify: true }
313
+ );
314
+
315
+ var value;
316
+ function input(valueIn){
317
+ value = valueIn;
318
+ }
319
+
320
+ eval(output);
321
+
322
+ expect(value).toStrictEqual(1);
323
+ })