js-confuser 1.5.2 → 1.5.4

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,16 @@
1
+ # `1.5.4`
2
+ Small fix
3
+
4
+ - Fixed [#45](https://github.com/MichaelXF/js-confuser/issues/45)
5
+ - - Opaque predicates fixed to not this cause error
6
+
7
+
8
+ # `1.5.3`
9
+ Shuffle fix
10
+
11
+ - Fixed [#48](https://github.com/MichaelXF/js-confuser/issues/48)
12
+ - - Shuffle was re-assigning `const` variables, fixed in this version.
13
+
1
14
  # `1.5.2`
2
15
  Mini fixes
3
16
 
@@ -132,7 +132,7 @@ class OpaquePredicates extends _transform.default {
132
132
 
133
133
  var cloned = (0, _insert.clone)(expr);
134
134
 
135
- if (object.type == "SwitchCase") {
135
+ if (object.type == "SwitchCase" && object.test) {
136
136
  var matching = (0, _gen.Identifier)((0, _random.choice)(["undefined", "null"]));
137
137
  var test = object.test;
138
138
 
@@ -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.2",
3
+ "version": "1.5.4",
4
4
  "description": "JavaScript Obfuscation Tool.",
5
5
  "main": "dist/index.js",
6
6
  "types": "index.d.ts",
@@ -199,8 +199,8 @@ export default class OpaquePredicates extends Transform {
199
199
  }
200
200
 
201
201
  var cloned = clone(expr);
202
- if (object.type == "SwitchCase") {
203
- var matching = Identifier(choice(["undefined", "null"]));
202
+ if (object.type == "SwitchCase" && object.test) {
203
+ var matching: Node = Identifier(choice(["undefined", "null"]));
204
204
 
205
205
  var test = object.test;
206
206
 
@@ -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 &&
@@ -16,3 +16,28 @@ it("should append logical expressions", async () => {
16
16
 
17
17
  expect(output).not.toContain("(test)");
18
18
  });
19
+
20
+ // https://github.com/MichaelXF/js-confuser/issues/45
21
+ it("should work on default Switch cases", async ()=>{
22
+ var code = `
23
+
24
+ switch (0) {
25
+ default:
26
+ input(true);
27
+ }
28
+ `;
29
+
30
+ var output = await JsConfuser(code, {
31
+ target: "browser",
32
+ opaquePredicates: true,
33
+ });
34
+
35
+ var value;
36
+ function input(valueIn){
37
+ value = valueIn;
38
+ }
39
+
40
+ eval(output);
41
+
42
+ expect(value).toStrictEqual(true);
43
+ })
@@ -89,3 +89,28 @@ 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
+
108
+ var value;
109
+ function input(valueIn) {
110
+ value = valueIn;
111
+ }
112
+
113
+ eval(output);
114
+
115
+ expect(value).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
116
+ });