js-confuser icon indicating copy to clipboard operation
js-confuser copied to clipboard

Rename Variables breaks with statement

Open MichaelXF opened this issue 1 year ago • 5 comments

Config and Small code sample

Config:

{
  target: "node",
  renameVariables: true
}

Code:

var a = "Incorrect value";
with ({ a: "Correct Value" }) {
  console.log(a);
}

// "Correct Value"

Obfuscated Code:

var Tru_whk = "Incorrect value";
with ({ ["a"]: "Correct Value" }) {
  console["log"](Tru_whk);
}

// "Incorrect value"

Additional context

Might be easiest to disable renaming fully in with statements or not support it entirely. Since any object can be passed in, theres no way for the obfuscator to know if the name will be shadowed or not.

MichaelXF avatar Aug 11 '24 17:08 MichaelXF

But then sadly you have a bunch of __p_7812057763_flat___p_1597929504_dLR_4__JS_PREDICT____JS_PREDICT__

Mrgaton avatar Oct 11 '24 22:10 Mrgaton

@MichaelXF At leat can you make only rename confuser generated variables and only pre mangle my code

Mrgaton avatar Oct 19 '24 17:10 Mrgaton

@MichaelXF please make a version for 1.7.4 with the option just to mangle the obfuscator generated variables and don't touch the code ones cause I want to have a minified version of obfuscated code. I cant just minify the output code because it has global variables and if I minify the obfuscated code will rename them.

Mrgaton avatar Nov 11 '24 10:11 Mrgaton

All obfuscated variables start with "__p_". You can use a custom Rename Variables function to only change them. Also Rename Variables only changes names that are defined within the code, it will not change global variables (such as console, Math, or jQuery, unless you explicitly define them)

Source Code: https://github.com/MichaelXF/js-confuser/blob/19d74ddaa084f234df1c4874efb6f13f842133aa/src/constants.ts#L84

const options = {
  target: "node",
  renameVariables: (varName) => varName.startsWith("__p_"),
};

Other options may still change variable names, and some dead code snippets contain variables without the placeholder prefix.

MichaelXF avatar Nov 12 '24 02:11 MichaelXF

what I mean is to add a temporary option to minify obfuscated generated code only, without breaking anything, cause minifiers I need to specify top level to be able to do it but I have some variables that I don't want to be top level.

Mrgaton avatar Feb 25 '25 10:02 Mrgaton