js-confuser 1.6.0 → 1.7.0
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 +23 -0
- package/README.md +215 -170
- 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 +4 -1
- package/dist/transforms/extraction/duplicateLiteralsRemoval.js +89 -58
- 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 +139 -246
- 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 +37 -3
- package/dist/util/insert.js +24 -3
- package/docs/ControlFlowFlattening.md +595 -0
- package/{Countermeasures.md → docs/Countermeasures.md} +1 -15
- package/{Integrity.md → docs/Integrity.md} +2 -2
- package/docs/RGF.md +419 -0
- package/package.json +1 -1
- 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 +5 -1
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +130 -129
- 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 +214 -404
- 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 +43 -2
- package/src/util/insert.ts +26 -2
- package/test/code/ES6.src.js +24 -0
- package/test/transforms/flatten.test.ts +352 -88
- package/test/transforms/identifier/movedDeclarations.test.ts +37 -9
- package/test/transforms/identifier/renameVariables.test.ts +37 -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 +113 -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
|
@@ -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
|
+
});
|
|
@@ -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
|
+
});
|