js-confuser 1.5.1 → 1.5.3

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,18 @@
1
+ # `1.5.3`
2
+ Shuffle fix
3
+
4
+ - Fixed [#48](https://github.com/MichaelXF/js-confuser/issues/48)
5
+ - - Shuffle was re-assigning `const` variables, fixed in this version.
6
+
7
+ # `1.5.2`
8
+ Mini fixes
9
+
10
+ - Fixed [#41](https://github.com/MichaelXF/js-confuser/issues/41)
11
+ - - Obfuscator mishandled switch statements with a `default` case
12
+
13
+ - Fixed [#43](https://github.com/MichaelXF/js-confuser/issues/43)
14
+ - - Obfuscator mishandled variable destructuring in for-loops
15
+
1
16
  # `1.5.1`
2
17
  Object Extraction Fix
3
18
 
@@ -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];
@@ -126,7 +126,7 @@ class Shuffle extends _transform.default {
126
126
  if (varDeclarator.type == "VariableDeclarator") {
127
127
  var varDec = parents[2];
128
128
 
129
- if (varDec.type == "VariableDeclaration") {
129
+ if (varDec.type == "VariableDeclaration" && varDec.kind !== "const") {
130
130
  var body = parents[3];
131
131
 
132
132
  if (varDec.declarations.length == 1 && Array.isArray(body) && varDeclarator.id.type === "Identifier" && varDeclarator.init === object) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-confuser",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
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 (
@@ -149,7 +149,7 @@ export default class Shuffle extends Transform {
149
149
  var varDeclarator = parents[0];
150
150
  if (varDeclarator.type == "VariableDeclarator") {
151
151
  var varDec = parents[2];
152
- if (varDec.type == "VariableDeclaration") {
152
+ if (varDec.type == "VariableDeclaration" && varDec.kind !== "const") {
153
153
  var body = parents[3];
154
154
  if (
155
155
  varDec.declarations.length == 1 &&
@@ -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
+ })
@@ -89,3 +89,29 @@ it("should shuffle arrays based on hash and unshuffle incorrect if changed", asy
89
89
 
90
90
  expect(different).toStrictEqual(true);
91
91
  });
92
+
93
+ // https://github.com/MichaelXF/js-confuser/issues/48
94
+ it("Should properly apply to const variables", async () => {
95
+ var code = `
96
+ const TEST_ARRAY = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
97
+
98
+ input(TEST_ARRAY);
99
+ `;
100
+
101
+ var output = await JsConfuser(code, {
102
+ target: "browser",
103
+ shuffle: true,
104
+ });
105
+
106
+ expect(output).toContain("TEST_ARRAY=function");
107
+ expect(output).not.toContain("1,2,3,4,5,6,7,8,9");
108
+
109
+ var value;
110
+ function input(valueIn) {
111
+ value = valueIn;
112
+ }
113
+
114
+ eval(output);
115
+
116
+ expect(value).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
117
+ });