Skip to content

Commit

Permalink
Fix #77
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelXF committed May 18, 2023
1 parent 10f0b38 commit 78cf2e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transforms/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default class Dispatcher extends Transform {
var illegalFnNames: Set<string> = new Set();

// New Names for Functions
var newFnNames: { [name: string]: string } = {}; // [old name]: randomized name
var newFnNames: { [name: string]: string } = Object.create(null); // [old name]: randomized name

var context = isVarContext(object)
? object
Expand Down Expand Up @@ -469,7 +469,7 @@ export default class Dispatcher extends Transform {
}

var newName = newFnNames[o.name];
if (!newName) {
if (!newName || typeof newName !== "string") {
return;
}

Expand Down
24 changes: 24 additions & 0 deletions test/transforms/dispatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,27 @@ it("should apply to every level of the code", async () => {

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

// https://github.com/MichaelXF/js-confuser/issues/77
it("should work with code that uses toString() function", async () => {
var output = await JsConfuser(
`
function myFunction(){
}
TEST_OUTPUT = toString();
`,
{
target: "node",
dispatcher: true,
}
);

var toString = () => "Correct Value";
var TEST_OUTPUT;

eval(output);

expect(TEST_OUTPUT).toStrictEqual("Correct Value");
});

0 comments on commit 78cf2e5

Please sign in to comment.