js-confuser 1.5.8 → 1.5.9
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 +37 -0
- package/dist/index.js +45 -4
- package/dist/obfuscator.js +10 -5
- package/dist/options.js +2 -3
- package/dist/order.js +3 -3
- package/dist/transforms/antiTooling.js +1 -1
- package/dist/transforms/controlFlowFlattening/expressionObfuscation.js +4 -2
- package/dist/transforms/dispatcher.js +3 -3
- package/dist/transforms/es5/antiClass.js +6 -2
- package/dist/transforms/es5/antiDestructuring.js +1 -1
- package/dist/transforms/eval.js +11 -0
- package/dist/transforms/extraction/duplicateLiteralsRemoval.js +4 -4
- package/dist/transforms/extraction/objectExtraction.js +6 -1
- package/dist/transforms/flatten.js +73 -50
- package/dist/transforms/hexadecimalNumbers.js +34 -9
- package/dist/transforms/identifier/movedDeclarations.js +1 -1
- package/dist/transforms/minify.js +22 -6
- package/dist/transforms/rgf.js +4 -4
- package/dist/transforms/stack.js +1 -1
- package/dist/transforms/string/stringConcealing.js +2 -2
- package/dist/traverse.js +0 -8
- package/dist/util/compare.js +2 -2
- package/dist/util/insert.js +20 -6
- package/package.json +1 -1
- package/src/index.ts +57 -19
- package/src/obfuscator.ts +6 -1
- package/src/options.ts +10 -2
- package/src/order.ts +3 -3
- package/src/transforms/antiTooling.ts +1 -1
- package/src/transforms/controlFlowFlattening/expressionObfuscation.ts +14 -2
- package/src/transforms/dispatcher.ts +4 -3
- package/src/transforms/es5/antiClass.ts +10 -1
- package/src/transforms/es5/antiDestructuring.ts +1 -1
- package/src/transforms/eval.ts +18 -0
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +5 -5
- package/src/transforms/extraction/objectExtraction.ts +12 -5
- package/src/transforms/flatten.ts +181 -128
- package/src/transforms/hexadecimalNumbers.ts +37 -9
- package/src/transforms/identifier/movedDeclarations.ts +1 -1
- package/src/transforms/minify.ts +37 -5
- package/src/transforms/rgf.ts +4 -3
- package/src/transforms/stack.ts +3 -1
- package/src/transforms/string/stringConcealing.ts +2 -2
- package/src/traverse.ts +1 -8
- package/src/types.ts +9 -1
- package/src/util/compare.ts +2 -2
- package/src/util/insert.ts +37 -8
- package/test/code/ES6.src.js +14 -0
- package/test/code/NewFeatures.test.ts +19 -0
- package/test/index.test.ts +13 -1
- package/test/transforms/antiTooling.test.ts +30 -0
- package/test/transforms/controlFlowFlattening/controlFlowFlattening.test.ts +22 -0
- package/test/transforms/dispatcher.test.ts +24 -0
- package/test/transforms/es5/antiClass.test.ts +33 -0
- package/test/transforms/eval.test.ts +53 -0
- package/test/transforms/extraction/objectExtraction.test.ts +21 -0
- package/test/transforms/flatten.test.ts +146 -3
- package/test/transforms/identifier/renameVariables.test.ts +26 -0
- package/test/transforms/minify.test.ts +66 -0
- package/test/transforms/rgf.test.ts +56 -0
- package/test/transforms/string/stringConcealing.test.ts +33 -0
- package/test/util/compare.test.ts +23 -1
|
@@ -288,6 +288,62 @@ input(console.log, result)
|
|
|
288
288
|
|
|
289
289
|
expect(output).not.toContain("new Function");
|
|
290
290
|
});
|
|
291
|
+
|
|
292
|
+
it("should work with Control Flow Flattening and Duplicate Literals Removal enabled", async () => {
|
|
293
|
+
var output = await JsConfuser.obfuscate(
|
|
294
|
+
`
|
|
295
|
+
var x = [1,1,1,1,1,1,1,1,1,1];
|
|
296
|
+
|
|
297
|
+
function myFunction(){
|
|
298
|
+
return 1;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
input( myFunction() ); // 1
|
|
302
|
+
`,
|
|
303
|
+
{
|
|
304
|
+
target: "node",
|
|
305
|
+
controlFlowFlattening: true,
|
|
306
|
+
duplicateLiteralsRemoval: true,
|
|
307
|
+
rgf: true,
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
var value = "never_called";
|
|
312
|
+
function input(valueIn) {
|
|
313
|
+
value = valueIn;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
eval(output);
|
|
317
|
+
|
|
318
|
+
expect(value).toStrictEqual(1);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("should work with String Encoding enabled", async () => {
|
|
322
|
+
var output = await JsConfuser.obfuscate(
|
|
323
|
+
`
|
|
324
|
+
function myFunction(){
|
|
325
|
+
var val1 = "\\x43\\x6F\\x72\\x72\\x65\\x63\\x74\\x20\\x56\\x61\\x6C\\x75\\x65"; // "Correct Value"
|
|
326
|
+
var val2 = "Correct Value";
|
|
327
|
+
return val1 === val2;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
TEST_OUTPUT = myFunction(); // true
|
|
331
|
+
`,
|
|
332
|
+
{
|
|
333
|
+
target: "node",
|
|
334
|
+
rgf: true,
|
|
335
|
+
stringEncoding: true,
|
|
336
|
+
}
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
// Ensure RGF applied
|
|
340
|
+
expect(output).toContain("new Function");
|
|
341
|
+
|
|
342
|
+
var TEST_OUTPUT;
|
|
343
|
+
eval(output);
|
|
344
|
+
|
|
345
|
+
expect(TEST_OUTPUT).toStrictEqual(true);
|
|
346
|
+
});
|
|
291
347
|
});
|
|
292
348
|
|
|
293
349
|
describe("RGF with the 'all' mode", () => {
|
|
@@ -182,3 +182,36 @@ it("should not encode constructor key", async () => {
|
|
|
182
182
|
|
|
183
183
|
expect(TEST_VAR).toStrictEqual(100);
|
|
184
184
|
});
|
|
185
|
+
|
|
186
|
+
// https://github.com/MichaelXF/js-confuser/issues/82
|
|
187
|
+
it("should work inside the Class Constructor function", async () => {
|
|
188
|
+
var code = `
|
|
189
|
+
class MyClass1 {}
|
|
190
|
+
class MyClass2 extends MyClass1 {
|
|
191
|
+
constructor(){
|
|
192
|
+
super();
|
|
193
|
+
this["myString1"] = true;
|
|
194
|
+
this["myString2"] = true;
|
|
195
|
+
this["myString3"] = true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
var instance = new MyClass2();
|
|
200
|
+
|
|
201
|
+
TEST_OUTPUT = instance.myString1 === true; // true
|
|
202
|
+
`;
|
|
203
|
+
|
|
204
|
+
var output = await JsConfuser(code, {
|
|
205
|
+
target: "node",
|
|
206
|
+
stringConcealing: true,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// Ensure the strings got encrypted properly
|
|
210
|
+
expect(output).not.toContain("myString");
|
|
211
|
+
|
|
212
|
+
// Ensure the code works
|
|
213
|
+
var TEST_OUTPUT = false;
|
|
214
|
+
eval(output);
|
|
215
|
+
|
|
216
|
+
expect(TEST_OUTPUT).toStrictEqual(true);
|
|
217
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isEquivalent } from "../../src/util/compare";
|
|
1
|
+
import { isEquivalent, isValidIdentifier } from "../../src/util/compare";
|
|
2
2
|
import { Identifier } from "../../src/util/gen";
|
|
3
3
|
|
|
4
4
|
it("should compare nodes correctly", () => {
|
|
@@ -10,3 +10,25 @@ it("should compare nodes correctly", () => {
|
|
|
10
10
|
isEquivalent(Identifier("name"), Identifier("different_name"))
|
|
11
11
|
).toStrictEqual(false);
|
|
12
12
|
});
|
|
13
|
+
|
|
14
|
+
describe("isValidIdentifier", () => {
|
|
15
|
+
test("Variant #1: Basic examples", () => {
|
|
16
|
+
// true examples
|
|
17
|
+
expect(isValidIdentifier("myClass")).toStrictEqual(true);
|
|
18
|
+
expect(isValidIdentifier("MyClass")).toStrictEqual(true);
|
|
19
|
+
expect(isValidIdentifier("$myObject")).toStrictEqual(true);
|
|
20
|
+
expect(isValidIdentifier("_myObject")).toStrictEqual(true);
|
|
21
|
+
expect(isValidIdentifier("myObject2")).toStrictEqual(true);
|
|
22
|
+
expect(isValidIdentifier("_0")).toStrictEqual(true);
|
|
23
|
+
|
|
24
|
+
// false examples
|
|
25
|
+
expect(isValidIdentifier("0")).toStrictEqual(false);
|
|
26
|
+
expect(isValidIdentifier("0myInvalidVar")).toStrictEqual(false);
|
|
27
|
+
expect(isValidIdentifier("^")).toStrictEqual(false);
|
|
28
|
+
expect(isValidIdentifier("%")).toStrictEqual(false);
|
|
29
|
+
expect(isValidIdentifier("invalid*Var")).toStrictEqual(false);
|
|
30
|
+
expect(isValidIdentifier("invalid!")).toStrictEqual(false);
|
|
31
|
+
expect(isValidIdentifier("my invalid var")).toStrictEqual(false);
|
|
32
|
+
expect(isValidIdentifier("my-invalid-var")).toStrictEqual(false);
|
|
33
|
+
});
|
|
34
|
+
});
|