js-confuser 1.6.0 → 1.7.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 +42 -0
- package/README.md +215 -172
- package/dist/constants.js +6 -2
- package/dist/obfuscator.js +0 -6
- package/dist/options.js +4 -4
- package/dist/presets.js +6 -7
- package/dist/templates/crash.js +2 -2
- package/dist/templates/functionLength.js +16 -0
- package/dist/transforms/dispatcher.js +10 -1
- package/dist/transforms/extraction/duplicateLiteralsRemoval.js +95 -59
- package/dist/transforms/extraction/objectExtraction.js +6 -1
- package/dist/transforms/flatten.js +224 -147
- package/dist/transforms/identifier/movedDeclarations.js +38 -85
- package/dist/transforms/identifier/renameVariables.js +94 -41
- package/dist/transforms/lock/lock.js +0 -37
- package/dist/transforms/minify.js +2 -2
- package/dist/transforms/rgf.js +145 -244
- package/dist/transforms/stack.js +42 -1
- package/dist/transforms/transform.js +1 -1
- package/dist/util/gen.js +2 -1
- package/dist/util/identifiers.js +38 -4
- package/dist/util/insert.js +24 -3
- package/docs/ControlFlowFlattening.md +595 -0
- package/{Countermeasures.md → docs/Countermeasures.md} +1 -15
- package/docs/ES5.md +197 -0
- package/{Integrity.md → docs/Integrity.md} +2 -2
- package/docs/RGF.md +419 -0
- package/package.json +2 -2
- package/src/constants.ts +3 -0
- package/src/obfuscator.ts +0 -4
- package/src/options.ts +9 -86
- package/src/presets.ts +6 -7
- package/src/templates/crash.ts +10 -10
- package/src/templates/functionLength.ts +14 -0
- package/src/transforms/dispatcher.ts +15 -1
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +135 -130
- package/src/transforms/extraction/objectExtraction.ts +4 -0
- package/src/transforms/flatten.ts +357 -290
- package/src/transforms/identifier/movedDeclarations.ts +50 -96
- package/src/transforms/identifier/renameVariables.ts +120 -56
- package/src/transforms/lock/lock.ts +1 -42
- package/src/transforms/minify.ts +11 -2
- package/src/transforms/rgf.ts +221 -402
- package/src/transforms/stack.ts +62 -0
- package/src/transforms/transform.ts +6 -2
- package/src/util/gen.ts +7 -2
- package/src/util/identifiers.ts +48 -4
- package/src/util/insert.ts +26 -2
- package/test/code/ES6.src.js +24 -0
- package/test/transforms/dispatcher.test.ts +27 -0
- package/test/transforms/extraction/duplicateLiteralsRemoval.test.ts +21 -8
- package/test/transforms/extraction/objectExtraction.test.ts +35 -15
- package/test/transforms/flatten.test.ts +352 -88
- package/test/transforms/identifier/globalConcealing.test.ts +23 -2
- package/test/transforms/identifier/movedDeclarations.test.ts +37 -9
- package/test/transforms/identifier/renameVariables.test.ts +37 -0
- package/test/transforms/lock/integrity.test.ts +24 -0
- package/test/transforms/lock/lock.test.ts +1 -48
- package/test/transforms/minify.test.ts +19 -0
- package/test/transforms/rgf.test.ts +262 -353
- package/test/transforms/stack.test.ts +52 -0
- package/test/util/identifiers.test.ts +134 -1
- package/test/util/insert.test.ts +57 -3
- package/src/transforms/eval.ts +0 -89
- package/src/transforms/identifier/nameRecycling.ts +0 -280
- package/test/transforms/eval.test.ts +0 -131
- package/test/transforms/identifier/nameRecycling.test.ts +0 -205
|
@@ -12,7 +12,7 @@ test("Variant #1: Move variable 'y' to top", async () => {
|
|
|
12
12
|
movedDeclarations: true,
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
expect(output).toContain("var y;");
|
|
15
|
+
expect(output).toContain("var x=10,y;");
|
|
16
16
|
expect(output).toContain("y=15");
|
|
17
17
|
|
|
18
18
|
var TEST_VARIABLE;
|
|
@@ -34,7 +34,7 @@ test("Variant #2: Move variable 'y' and 'z' to top", async () => {
|
|
|
34
34
|
movedDeclarations: true,
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
expect(output).toContain("var y,z");
|
|
37
|
+
expect(output).toContain("var x=10,y,z;");
|
|
38
38
|
expect(output).toContain("y=15");
|
|
39
39
|
expect(output).toContain("z=5");
|
|
40
40
|
|
|
@@ -44,7 +44,7 @@ test("Variant #2: Move variable 'y' and 'z' to top", async () => {
|
|
|
44
44
|
expect(TEST_VARIABLE).toStrictEqual(30);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
test("Variant #
|
|
47
|
+
test("Variant #3: Don't move 'y' (destructuring)", async () => {
|
|
48
48
|
var code = `
|
|
49
49
|
var x = 10;
|
|
50
50
|
var [y] = [15];
|
|
@@ -64,7 +64,7 @@ test("Variant #2: Don't move 'y' (destructuring)", async () => {
|
|
|
64
64
|
expect(TEST_VARIABLE).toStrictEqual(25);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
test("Variant #
|
|
67
|
+
test("Variant #4: Move 'y' (nested lexical scope)", async () => {
|
|
68
68
|
var code = `
|
|
69
69
|
var x = 10;
|
|
70
70
|
var y = 15;
|
|
@@ -81,7 +81,7 @@ test("Variant #3: Don't move 'y' (nested lexical scope)", async () => {
|
|
|
81
81
|
movedDeclarations: true,
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
expect(output).toContain("var y
|
|
84
|
+
expect(output).toContain("var x=10,y;");
|
|
85
85
|
|
|
86
86
|
var TEST_VARIABLE;
|
|
87
87
|
eval(output);
|
|
@@ -89,7 +89,7 @@ test("Variant #3: Don't move 'y' (nested lexical scope)", async () => {
|
|
|
89
89
|
expect(TEST_VARIABLE).toStrictEqual(20);
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
-
test("Variant #
|
|
92
|
+
test("Variant #5: Move 'y' (for statement initializer)", async () => {
|
|
93
93
|
var code = `
|
|
94
94
|
var x = 10;
|
|
95
95
|
for ( var y = 0; y < 15; y++ ) {
|
|
@@ -111,7 +111,7 @@ test("Variant #4: Move 'y' (for statement initializer)", async () => {
|
|
|
111
111
|
expect(TEST_VARIABLE).toStrictEqual(25);
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
-
test("Variant #
|
|
114
|
+
test("Variant #6: Move 'y' (for-in left-hand initializer)", async () => {
|
|
115
115
|
var code = `
|
|
116
116
|
var x = 10;
|
|
117
117
|
for ( var y in [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] ) {
|
|
@@ -134,7 +134,7 @@ test("Variant #5: Move 'y' (for-in left-hand initializer)", async () => {
|
|
|
134
134
|
expect(TEST_VARIABLE).toStrictEqual(25);
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
-
test("Variant #
|
|
137
|
+
test("Variant #7: Don't move const or let variables", async () => {
|
|
138
138
|
var code = `
|
|
139
139
|
var fillerExpr;
|
|
140
140
|
|
|
@@ -158,7 +158,7 @@ test("Variant #6: Don't move const or let variables", async () => {
|
|
|
158
158
|
expect(TEST_VARIABLE).toStrictEqual(25);
|
|
159
159
|
});
|
|
160
160
|
|
|
161
|
-
test("Variant #
|
|
161
|
+
test("Variant #8: Work with 'use strict'", async () => {
|
|
162
162
|
var code = `
|
|
163
163
|
function myFunction(){
|
|
164
164
|
'use strict';
|
|
@@ -184,3 +184,31 @@ test("Variant #7: Work with 'use strict'", async () => {
|
|
|
184
184
|
|
|
185
185
|
expect(TEST_OUTPUT).toStrictEqual(true);
|
|
186
186
|
});
|
|
187
|
+
|
|
188
|
+
test("Variant #9: Defined variable without an initializer", async () => {
|
|
189
|
+
var code = `
|
|
190
|
+
var x;
|
|
191
|
+
x = 1;
|
|
192
|
+
var y;
|
|
193
|
+
y = 2;
|
|
194
|
+
TEST_OUTPUT = x + y;
|
|
195
|
+
`;
|
|
196
|
+
|
|
197
|
+
var output1 = await JsConfuser(code, {
|
|
198
|
+
target: "node",
|
|
199
|
+
movedDeclarations: true,
|
|
200
|
+
controlFlowFlattening: true,
|
|
201
|
+
duplicateLiteralsRemoval: true,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
var output2 = await JsConfuser(output1, {
|
|
205
|
+
target: "node",
|
|
206
|
+
movedDeclarations: true,
|
|
207
|
+
controlFlowFlattening: true,
|
|
208
|
+
duplicateLiteralsRemoval: true,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
var TEST_OUTPUT;
|
|
212
|
+
eval(output2);
|
|
213
|
+
expect(TEST_OUTPUT).toStrictEqual(3);
|
|
214
|
+
});
|
|
@@ -582,3 +582,40 @@ test("Variant #23: Re-use previously generated names", async () => {
|
|
|
582
582
|
|
|
583
583
|
expect(TEST_OUTPUT).toStrictEqual("Correct Value");
|
|
584
584
|
});
|
|
585
|
+
|
|
586
|
+
test("Variant #24: Reference function name with parameter", async () => {
|
|
587
|
+
var output = await JsConfuser(
|
|
588
|
+
`
|
|
589
|
+
function myFunction(myFunction){
|
|
590
|
+
myFunction.property = "Correct Value";
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
myFunction(myFunction);
|
|
594
|
+
TEST_OUTPUT = myFunction.property;
|
|
595
|
+
`,
|
|
596
|
+
{ target: "node", renameVariables: true }
|
|
597
|
+
);
|
|
598
|
+
|
|
599
|
+
var TEST_OUTPUT;
|
|
600
|
+
eval(output);
|
|
601
|
+
|
|
602
|
+
expect(TEST_OUTPUT).toStrictEqual("Correct Value");
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
test("Variant #25: Reference catch parameter", async () => {
|
|
606
|
+
var output = await JsConfuser(
|
|
607
|
+
`
|
|
608
|
+
try {
|
|
609
|
+
throw "Correct Value";
|
|
610
|
+
} catch ( e ) {
|
|
611
|
+
TEST_OUTPUT = e;
|
|
612
|
+
}
|
|
613
|
+
`,
|
|
614
|
+
{ target: "node", renameVariables: true }
|
|
615
|
+
);
|
|
616
|
+
|
|
617
|
+
var TEST_OUTPUT;
|
|
618
|
+
eval(output);
|
|
619
|
+
|
|
620
|
+
expect(TEST_OUTPUT).toStrictEqual("Correct Value");
|
|
621
|
+
});
|
|
@@ -135,3 +135,27 @@ it("should work on High Preset", async () => {
|
|
|
135
135
|
|
|
136
136
|
expect(TEST_OUTPUT).toStrictEqual("Hello World");
|
|
137
137
|
});
|
|
138
|
+
|
|
139
|
+
it("should work with RGF enabled", async () => {
|
|
140
|
+
var output = await JsConfuser(
|
|
141
|
+
`
|
|
142
|
+
function getTestOutput(){
|
|
143
|
+
return "Hello World";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
TEST_OUTPUT = getTestOutput();
|
|
147
|
+
`,
|
|
148
|
+
{
|
|
149
|
+
target: "node",
|
|
150
|
+
rgf: true,
|
|
151
|
+
lock: {
|
|
152
|
+
integrity: true,
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
var TEST_OUTPUT;
|
|
158
|
+
eval(output);
|
|
159
|
+
|
|
160
|
+
expect(TEST_OUTPUT).toStrictEqual("Hello World");
|
|
161
|
+
});
|
|
@@ -64,6 +64,7 @@ it("should work with endDate and call countermeasures function", async () => {
|
|
|
64
64
|
expect(value).toStrictEqual(true);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
+
// REMOVED FEATURE:
|
|
67
68
|
// it("strings should be encoded when startDate and endDate are given", async () => {
|
|
68
69
|
// var startDate = await JsConfuser.obfuscate(` input("ENCODED_STRING") `, {
|
|
69
70
|
// target: "node",
|
|
@@ -82,54 +83,6 @@ it("should work with endDate and call countermeasures function", async () => {
|
|
|
82
83
|
// expect(value).toStrictEqual("ENCODED_STRING");
|
|
83
84
|
// });
|
|
84
85
|
|
|
85
|
-
it("should work with nativeFunctions and call countermeasures function", async () => {
|
|
86
|
-
var output = await JsConfuser.obfuscate(
|
|
87
|
-
` function countermeasures(){ input(true) } `,
|
|
88
|
-
{
|
|
89
|
-
target: "node",
|
|
90
|
-
lock: {
|
|
91
|
-
nativeFunctions: ["fetch"],
|
|
92
|
-
countermeasures: "countermeasures",
|
|
93
|
-
},
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
// custom function, not "native"
|
|
98
|
-
var fetch = () => {};
|
|
99
|
-
|
|
100
|
-
var value = "never_called";
|
|
101
|
-
function input(valueIn) {
|
|
102
|
-
value = valueIn;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
eval(output);
|
|
106
|
-
expect(value).toStrictEqual(true);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("should work with nativeFunctions and not call countermeasures function when correct", async () => {
|
|
110
|
-
var output = await JsConfuser.obfuscate(
|
|
111
|
-
` function countermeasures(){ input(true) } `,
|
|
112
|
-
{
|
|
113
|
-
target: "node",
|
|
114
|
-
lock: {
|
|
115
|
-
nativeFunctions: ["fetch"],
|
|
116
|
-
countermeasures: "countermeasures",
|
|
117
|
-
},
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
// bound functions return the "[native code]" string
|
|
122
|
-
var fetch = (() => {}).bind(this);
|
|
123
|
-
|
|
124
|
-
var value = "never_called";
|
|
125
|
-
function input(valueIn) {
|
|
126
|
-
value = valueIn;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
eval(output);
|
|
130
|
-
expect(value).toStrictEqual("never_called");
|
|
131
|
-
});
|
|
132
|
-
|
|
133
86
|
it("countermeasures function should still work even with renameVariables enabled", async () => {
|
|
134
87
|
var output = await JsConfuser.obfuscate(
|
|
135
88
|
` function countermeasures(){ input(true) } `,
|
|
@@ -517,3 +517,22 @@ test("Variant #26: Don't break nested redefined function declaration", async ()
|
|
|
517
517
|
|
|
518
518
|
expect(TEST_OUTPUT).toStrictEqual(1);
|
|
519
519
|
});
|
|
520
|
+
|
|
521
|
+
// https://github.com/MichaelXF/js-confuser/issues/91
|
|
522
|
+
test("Variant #27: Preserve function.length property", async () => {
|
|
523
|
+
var output = await JsConfuser(
|
|
524
|
+
`
|
|
525
|
+
function oneParameter(a){};
|
|
526
|
+
var twoParameters = function({a},{b,c},...d){};
|
|
527
|
+
function threeParameters(a,b,c,d = 1,{e},...f){};
|
|
528
|
+
|
|
529
|
+
TEST_OUTPUT = oneParameter.length + twoParameters.length + threeParameters.length;
|
|
530
|
+
`,
|
|
531
|
+
{ target: "node", minify: true }
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
var TEST_OUTPUT;
|
|
535
|
+
eval(output);
|
|
536
|
+
|
|
537
|
+
expect(TEST_OUTPUT).toStrictEqual(6);
|
|
538
|
+
});
|