Description
This project very good, so I use it in many of my projects, so I recommend the following suggestions here:
- Multiple file processing
- Preferred quote style for strings -- I very like use double quotes ^_^
- When we turn on
String Array
, our array can consider using a singleUnicode Escape Sequence
. The remaining strings can be considered separately. - Substitute
void 0
if there is a variable namedundefined
in scope (variable name will be mangled, typically reduced to a single character)
An example of a combination of obfuscate() options:
var SourceCodeList = {
"test_1.js": "function hi(){console.log(\"Hello World!\");}hi();",
"test_2.js": "console.log(\"Welcome use a free and efficient obfuscator for JavaScript\");"
};
var options = {
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.75,
deadCodeInjection: true,
deadCodeInjectionThreshold: 0.4,
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
identifierNamesGenerator: 'hexadecimal',
renameGlobals: false,
rotateStringArray: true,
selfDefending: true,
shuffleStringArray: true,
splitStrings: true,
splitStringsChunkLength: '10',
stringArray: true,
stringArrayEncoding: 'base64',
stringArrayThreshold: 0.75,
transformObjectKeys: true,
unicodeEscapeSequence: false
};
var obfuscationResult = JavaScriptObfuscator.obfuscate(SourceCodeList, options);
console.log(obfuscationResult.getObfuscatedCode());
Third point comparison
Before:
var _0x2e7f=['Hello\x20World!','log'];(function(_0x53d6b3,_0x2e7f7e){var _0x41301a=function(_0x3ed08d){while(--_0x3ed08d){_0x53d6b3['push'](_0x53d6b3['shift']());}};_0x41301a(++_0x2e7f7e);}(_0x2e7f,0x1c4));var _0x4130=function(_0x53d6b3,_0x2e7f7e){_0x53d6b3=_0x53d6b3-0x0;var _0x41301a=_0x2e7f[_0x53d6b3];return _0x41301a;};function hi(){console[_0x4130('0x1')](_0x4130('0x0'));}hi();
After:
var _0x2e7f=['\x6c\x6f\x67','\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21'];(function(_0x53d6b3,_0x2e7f7e){var _0x41301a=function(_0x3ed08d){while(--_0x3ed08d){_0x53d6b3['push'](_0x53d6b3['shift']());}};_0x41301a(++_0x2e7f7e);}(_0x2e7f,0x1c4));var _0x4130=function(_0x53d6b3,_0x2e7f7e){_0x53d6b3=_0x53d6b3-0x0;var _0x41301a=_0x2e7f[_0x53d6b3];return _0x41301a;};function hi(){console[_0x4130('0x1')](_0x4130('0x0'));}hi();