Code obfuscation
What is obfuscation?
- During JS compilation, code is transformed with junk instructions and control-flow changes to protect source code
Getting started
- After upgrading the EC iOS IDEA plugin to 5.0.0+, an
obfuscator.jsonfile is created under the project module - Obfuscation is off by default — set
binPathcorrectly in the JSON config
Install and configure the obfuscator
Install Node.js
Install npm install -g javascript-obfuscator
- On Windows, run in cmd or PowerShell
- Reference: https://www.npmjs.com/package/javascript-obfuscator
- Or search for javascript-obfuscator installation guides
npm install -g javascript-obfuscator
npm install -g class-validator
Configuration
- Default settings below are tested and working. See the tool site for more: [https://www.npmjs.com/package/javascript-obfuscator]
nodeBinPath: path to Node.jsnode.exe— see exampleobfuscatorBinPath: path to thejavascript-obfuscatorexecutable- After installing Node.js, global modules are usually at:
C:\Users\Administrator\AppData\Roaming\npm\node_modules(check withnpm root -g; username varies) - Copy the full path to
javascript-obfuscatorundernode_modules
{
"nodeBinPath": "D:\\programe\\nodejs\\node.exe",
"obfuscatorBinPath": "C:\\Users\\Administrator\\AppData\\Roaming\\npm\\node_modules\\javascript-obfuscator\\bin\\javascript-obfuscator",
"target": "node",
"compact": false, // compress code
"log": true, // show log output
"optionsPreset": "high-obfuscation", // obfuscation level
"deadCodeInjection": false,
"simplify": false,
"seed": 10, // random seed count
"controlFlowFlattening": true,
"controlFlowFlatteningThreshold": 1,
"unicodeEscapeSequence": false,
"stringArray": true,
"stringArrayRotate": false,
"stringArrayShuffle": false,
"stringArrayThreshold": 1,
"stringArrayWrappersCount": 5,
"stringArrayEncoding": ["rc4"],
"stringArrayCallsTransform": false,
"selfDefending": false,
"splitStrings": false,
"splitStringsChunkLength": 1
}
Notes
- If
obfuscatorBinPathis set and the file exists, obfuscation runs by default for both JS and dex compile modes - Clear
obfuscatorBinPathor deleteobfuscator.jsonto disable obfuscation during compile - Obfuscation increases bundle size — avoid very long single files; split into modules
- Custom settings may break scripts after obfuscation — restore defaults if that happens
- Enable
logto see obfuscation details during compile - Obfuscation is CPU-heavy — disable during daily dev; enable for release or packaging