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 +6 -0
- package/dist/transforms/lock/antiDebug.js +1 -1
- package/dist/transforms/rgf.js +2 -1
- package/package.json +1 -1
- package/src/transforms/lock/antiDebug.ts +7 -4
- package/src/transforms/rgf.ts +1 -0
- package/test/transforms/lock/antiDebug.test.ts +43 -0
- package/test/transforms/rgf.test.ts +29 -0
package/CHANGELOG.md
CHANGED
|
@@ -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
|
}));
|
package/dist/transforms/rgf.js
CHANGED
|
@@ -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
|
@@ -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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
ExpressionStatement(
|
|
69
|
+
AssignmentExpression(
|
|
70
|
+
"=",
|
|
71
|
+
Identifier(startTimeName),
|
|
72
|
+
Identifier(endTimeName)
|
|
73
|
+
)
|
|
71
74
|
),
|
|
72
75
|
]),
|
|
73
76
|
],
|
package/src/transforms/rgf.ts
CHANGED
|
@@ -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", () => {
|