js-confuser 1.4.0 → 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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # `1.4.1`
2
+ AntiDebug Fix
3
+
4
+ - Fixed [#28](https://github.com/MichaelXF/js-confuser/issues/28)
5
+ - - AntiDebug was causing syntax errors in some scenarios, fixed in this version.
6
+
1
7
  # `1.4.0`
2
8
  Confusing Control Flow
3
9
 
@@ -43,7 +43,7 @@ class AntiDebug extends _transform.default {
43
43
  var startTimeName = this.getPlaceholder();
44
44
  var endTimeName = this.getPlaceholder();
45
45
  var isDevName = this.getPlaceholder();
46
- var functionDeclaration = (0, _gen.FunctionDeclaration)(fnName, [], [...(0, _template.default)("\n var ".concat(startTimeName, " = new Date();\n debugger;\n var ").concat(endTimeName, " = new Date();\n var ").concat(isDevName, " = ").concat(endTimeName, "-").concat(startTimeName, " > 1000;\n ")).compile(), (0, _gen.IfStatement)((0, _gen.Identifier)(isDevName), this.options.lock.countermeasures ? this.lock.getCounterMeasuresCode() : [(0, _gen.WhileStatement)((0, _gen.Identifier)(isDevName), [(0, _gen.AssignmentExpression)("=", (0, _gen.Identifier)(startTimeName), (0, _gen.Identifier)(endTimeName))])], null)]);
46
+ var functionDeclaration = (0, _gen.FunctionDeclaration)(fnName, [], [...(0, _template.default)("\n var ".concat(startTimeName, " = new Date();\n debugger;\n var ").concat(endTimeName, " = new Date();\n var ").concat(isDevName, " = ").concat(endTimeName, "-").concat(startTimeName, " > 1000;\n ")).compile(), (0, _gen.IfStatement)((0, _gen.Identifier)(isDevName), this.options.lock.countermeasures ? this.lock.getCounterMeasuresCode() : [(0, _gen.WhileStatement)((0, _gen.Identifier)(isDevName), [(0, _gen.ExpressionStatement)((0, _gen.AssignmentExpression)("=", (0, _gen.Identifier)(startTimeName), (0, _gen.Identifier)(endTimeName)))])], null)]);
47
47
  tree.body.unshift(...DevToolsDetection.compile({
48
48
  functionName: fnName
49
49
  }));
@@ -209,7 +209,8 @@ class RGF extends _transform.default {
209
209
  lock: {
210
210
  integrity: false
211
211
  },
212
- eval: false
212
+ eval: false,
213
+ hideInitializingCode: false
213
214
  });
214
215
  var transforms = Object.values(obfuscator.transforms).filter(x => x.priority > this.priority);
215
216
  var embeddedFunction = { ...object,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-confuser",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "JavaScript Obfuscation Tool.",
5
5
  "main": "dist/index.js",
6
6
  "types": "index.d.ts",
@@ -4,6 +4,7 @@ import { isBlock } from "../../traverse";
4
4
  import {
5
5
  AssignmentExpression,
6
6
  DebuggerStatement,
7
+ ExpressionStatement,
7
8
  FunctionDeclaration,
8
9
  Identifier,
9
10
  IfStatement,
@@ -64,10 +65,12 @@ export default class AntiDebug extends Transform {
64
65
  ? this.lock.getCounterMeasuresCode()
65
66
  : [
66
67
  WhileStatement(Identifier(isDevName), [
67
- AssignmentExpression(
68
- "=",
69
- Identifier(startTimeName),
70
- Identifier(endTimeName)
68
+ ExpressionStatement(
69
+ AssignmentExpression(
70
+ "=",
71
+ Identifier(startTimeName),
72
+ Identifier(endTimeName)
73
+ )
71
74
  ),
72
75
  ]),
73
76
  ],
@@ -260,6 +260,7 @@ export default class RGF extends Transform {
260
260
  integrity: false,
261
261
  },
262
262
  eval: false,
263
+ hideInitializingCode: false,
263
264
  });
264
265
  var transforms = Object.values(obfuscator.transforms).filter(
265
266
  (x) => x.priority > this.priority
@@ -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
+ });
@@ -125,6 +125,35 @@ describe("RGF", () => {
125
125
 
126
126
  expect(value).toStrictEqual("Hello World");
127
127
  });
128
+
129
+ it("should work with hideInitializingCode enabled", async () => {
130
+ var output = await JsConfuser.obfuscate(
131
+ `
132
+ function abc(x, y){
133
+ return x + y;
134
+ }
135
+
136
+ var result = abc(10, 50);
137
+ input(console.log, result)
138
+ `,
139
+ {
140
+ target: "node",
141
+ identifierGenerator: "randomized",
142
+ hideInitializingCode: true,
143
+ rgf: true,
144
+ compact: false,
145
+ renameVariables: true,
146
+ }
147
+ );
148
+
149
+ var value = "never_called";
150
+ function input(_, valueIn) {
151
+ value = valueIn;
152
+ }
153
+
154
+ eval(output);
155
+ expect(value).toStrictEqual(60);
156
+ });
128
157
  });
129
158
 
130
159
  describe("RGF with the 'all' mode", () => {