javascript-obfuscator: [QUESTION|BUG] Not Obfuscated Props

I have obfuscated code on JS: https://pastebin.com/vLATku6x

Here is original code: TS | JS

How I saw TS didn’t support. But that isn’t my question.

I saw what when I run code I get next output: image All is good, work fine. But I saw some strange result.

Obfuscator config

How you can see in my config I was enable change (obfuscate) keys of objects, globals, properties names. So, I suggest what props like name, keys, index, list would change (obfuscated) too. But I didn’t saw that result.

So, my question- this is a bug or not? Why some props isn’t obfuscated?

UPD:

I also a bit edit code. So I will find more “interest” things.

  • Without keys obfuscate - prop kruzya.pidoor is exist and have value (9999). image
  • With keys obfuscate - prop kruzya.pidoor isn’t exist BUT prop kruzya._0x2bdd58didn’t have value (9999). image
  • With and without keys obfuscate, props of class didn’t obfuscate (mb because this is a class? But one prop was obfuscated. MAGIC) This "debug" I will get by next code:
console.log("\n\n[KRUZYA]");
console.log("[kruzya]", kruzya);


// Auto check all exist 
console.log("\n\n[AUTO]");
for (const key in kruzya) {
    console.log(`[kruzya.${key}]`, kruzya[key])
}

// Manual check "should" exist props
console.log("\n\n[MANUAL]");
console.log("[kruzya.name]", kruzya.name);
console.log("[kruzya.pidor]", kruzya.pidor);
console.log("[kruzya.keys]", kruzya.keys);

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

(offtop) sori, psihanul 0JHQu9C40L0sINGC0Ysg0YPQttC1IDBMZlFzTkMxMExIUXNOQzcg0YHQstC+0LjQvCAi0LrRgNGD0LfRjyAwTC9RdU5DMDBMN1JnQT09Ii4g0KHRgtCw0LLRjCDQvtCx0YnQtdC/0YDQuNC90Y/RgtGL0LUgZm9vLWJhciDQuCDQvdC1IDBMTFJpOUdSMExIUmk5Q3kwTERRdWRHQjBZOD0=

Reopened. I think that i can add a new option renamePropertiesExludeUsedStrings (or so). When this option is enabled all property names that also occur in other strings will be auto-excluded.

So for the part of your source code:

var Status;
(function (Status) {
    Status[Status["Clear"] = 0] = "Clear";
    Status[Status["Low"] = 1] = "Low";
    Status[Status["Mid"] = 2] = "Mid";
    Status[Status["High"] = 3] = "High";
    Status[Status["Ultra"] = 4] = "Ultra";
    Status[Status["Kruzya"] = Infinity] = "Kruzya";
})(Status || (Status = {}));

console.log(Status.Kruzya);
console.log(Status.Clear);

properties (clear, low, mid and other properties of the enum) will be excluded because they also occur as values)

Status[Status["Clear"] = 0] = "Clear";
                 ^^             ^^
              excluded because value here

This exclusion will be global. So if property foo also used somewhere in the code - it will be excluded. In practice, I think, it may allow using renameProperties option more often because of the fewer amount of breaking cases.

I can’t fix this. Remember, if you have bugs with renameProperties disable it. This option is quite experimental and there is no way to improve how it works.

So, in your case you have to disable renameProperties option or controlFlowFlattening option

More simple example based on your code

var PidorStatus;
(function (PidorStatus) {
    PidorStatus[PidorStatus["Clear"] = 0] = "Clear";
    PidorStatus[PidorStatus["Low"] = 1] = "Low";
    PidorStatus[PidorStatus["Mid"] = 2] = "Mid";
    PidorStatus[PidorStatus["High"] = 3] = "High";
    PidorStatus[PidorStatus["Ultra"] = 4] = "Ultra";
    PidorStatus[PidorStatus["Kruzya"] = Infinity] = "Kruzya";
})(PidorStatus || (PidorStatus = {}));

console.log(PidorStatus.Kruzya);
console.log(PidorStatus.Clear);

With config:

module.exports = {
    compact: true,
    controlFlowFlattening: true,
    controlFlowFlatteningThreshold: 1,
    deadCodeInjection: false,
    deadCodeInjectionThreshold: 0,
    debugProtection: false,
    debugProtectionInterval: false,
    disableConsoleOutput: false,
    domainLock: [],
    exclude: [],
    forceTransformStrings: [],
    identifiersPrefix: '',
    identifiersDictionary: [],
    ignoreRequireImports: false,
    inputFileName: '',
    log: false,
    numbersToExpressions: false,
    renameGlobals: false,
    renameProperties: true,
    reservedNames: [],
    reservedStrings: [],
    rotateStringArray: false,
    seed: 0,
    selfDefending: false,
    shuffleStringArray: false,
    simplify: false,
    sourceMap: false,
    sourceMapBaseUrl: '',
    sourceMapFileName: '',
    sourceMapMode: 'separate',
    splitStrings: false,
    splitStringsChunkLength: 0,
    stringArray: false,
    stringArrayEncoding: [
        'none'
    ],
    stringArrayIndexesType: [
        'hexadecimal-number'
    ],
    stringArrayIndexShift: false,
    stringArrayWrappersChainedCalls: false,
    stringArrayWrappersCount: 0,
    stringArrayWrappersParametersMaxCount: 2,
    stringArrayWrappersType: 'variable',
    stringArrayThreshold: 0,
    target: 'browser',
    transformObjectKeys: false,
    unicodeEscapeSequence: false
};