javascript-obfuscator混淆
安装
npm install javascript-obfuscator -g
配置
重度混淆,性能低
性能下降50-100%
{ "compact": true, "controlFlowFlattening": true, "controlFlowFlatteningThreshold": 0.75, // 设置为0到1之间的值 "deadCodeInjection": true, "deadCodeInjectionThreshold": 0.4, // 设置为0到1之间的值 "debugProtection": true, "debugProtectionInterval": 1000, // 设置为一个正整数,表示毫秒数 "disableConsoleOutput": true, "identifierNamesGenerator": "hexadecimal", "log": false, "numbersToExpressions": true, "renameGlobals": false, "rotateStringArray": true, "selfDefending": true, "shuffleStringArray": true, "simplify": true, "splitStrings": true, "splitStringsChunkLength": 5, "stringArray": true, "stringArrayEncoding": ["rc4"], // 确保编码类型是有效的 "stringArrayIndexShift": true, "stringArrayWrappersCount": 5, "stringArrayWrappersChainedCalls": true, "stringArrayWrappersParametersMaxCount": 5, "stringArrayWrappersType": "function", "stringArrayThreshold": 0.75, // 设置为0到1之间的值 "transformObjectKeys": true, "unicodeEscapeSequence": false
}
中度压缩,最佳性能
性能下降30-35%
{ "compact": true, "controlFlowFlattening": true, "controlFlowFlatteningThreshold": 0.75, "deadCodeInjection": true, "deadCodeInjectionThreshold": 0.4, "debugProtection": false, "disableConsoleOutput": true, "identifierNamesGenerator": "hexadecimal", "log": false, "numbersToExpressions": true, "renameGlobals": false, "rotateStringArray": true, "selfDefending": true, "shuffleStringArray": true, "simplify": true, "splitStrings": true, "splitStringsChunkLength": 10, "stringArray": true, "stringArrayEncoding": ["base64"], "stringArrayIndexShift": true, "stringArrayWrappersCount": 2, "stringArrayWrappersChainedCalls": true, "stringArrayWrappersParametersMaxCount": 4, "stringArrayWrappersType": "function", "stringArrayThreshold": 0.75, "transformObjectKeys": true, "unicodeEscapeSequence": false
}
轻度压缩,高性能
性能略低于压缩之前
{ "compact": true, "controlFlowFlattening": false, "deadCodeInjection": false, "debugProtection": false, "disableConsoleOutput": true, "identifierNamesGenerator": "hexadecimal", "log": false, "numbersToExpressions": false, "renameGlobals": false, "rotateStringArray": true, "selfDefending": true, "shuffleStringArray": true, "simplify": true, "splitStrings": false, "stringArray": true, "stringArrayEncoding": [], // 你可以根据需要添加支持的编码算法,如 ["base64", "rc4"] "stringArrayIndexShift": true, "stringArrayWrappersCount": 1, "stringArrayWrappersChainedCalls": true, "stringArrayWrappersParametersMaxCount": 2, "stringArrayWrappersType": "variable", "stringArrayThreshold": 0.75, "unicodeEscapeSequence": false
}
默认值,高性能
{ "compact": true, "controlFlowFlattening": false, "deadCodeInjection": false, "debugProtection": false, "disableConsoleOutput": false, "identifierNamesGenerator": "hexadecimal", "log": false, "numbersToExpressions": false, "renameGlobals": false, "rotateStringArray": true, "selfDefending": false, "shuffleStringArray": true, "simplify": true, "splitStrings": false, "stringArray": true, "stringArrayEncoding": [], "stringArrayIndexShift": true, "stringArrayWrappersCount": 1, "stringArrayWrappersChainedCalls": true, "stringArrayWrappersParametersMaxCount": 2, "stringArrayWrappersType": "variable", "stringArrayThreshold": 0.75, "unicodeEscapeSequence": false
}
执行
混淆整个目录里的js
javascript-obfuscator ./js --output ./js/obfuscated --config obfuscator.json
混淆单个js
javascript-obfuscator index.af5ba3a0.js --output index.af5ba3a011111.js --config obfuscator.json