Skip to content

Commit

Permalink
Fix #82
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelXF committed May 18, 2023
1 parent ab8f69e commit f02547a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transforms/string/stringConcealing.ts
Expand Up @@ -214,15 +214,15 @@ export default class StringConcealing extends Transform {
if (Math.random() > 0.5) {
callExpr = CallExpression(
MemberExpression(Identifier(fnName), Identifier("apply"), false),
[ThisExpression(), ArrayExpression([Literal(index)])]
[Identifier("undefined"), ArrayExpression([Literal(index)])]
);
}

// use `.call`
else if (Math.random() > 0.5) {
callExpr = CallExpression(
MemberExpression(Identifier(fnName), Identifier("call"), false),
[ThisExpression(), Literal(index)]
[Identifier("undefined"), Literal(index)]
);
}

Expand Down
33 changes: 33 additions & 0 deletions test/transforms/string/stringConcealing.test.ts
Expand Up @@ -182,3 +182,36 @@ it("should not encode constructor key", async () => {

expect(TEST_VAR).toStrictEqual(100);
});

// https://github.com/MichaelXF/js-confuser/issues/82
it("should work inside the Class Constructor function", async () => {
var code = `
class MyClass1 {}
class MyClass2 extends MyClass1 {
constructor(){
super();
this["myString1"] = true;
this["myString2"] = true;
this["myString3"] = true;
}
}
var instance = new MyClass2();
TEST_OUTPUT = instance.myString1 === true; // true
`;

var output = await JsConfuser(code, {
target: "node",
stringConcealing: true,
});

// Ensure the strings got encrypted properly
expect(output).not.toContain("myString");

// Ensure the code works
var TEST_OUTPUT = false;
eval(output);

expect(TEST_OUTPUT).toStrictEqual(true);
});

0 comments on commit f02547a

Please sign in to comment.