simple-javascript-obf
v0.1.1
Published
Modular JavaScript obfuscator with optional VM and CFF
Maintainers
Readme
js-obf
A modular JavaScript obfuscation CLI with control-flow flattening (CFF) and optional VM virtualization.
Features
- CLI input/output for Node.js and browser-targeted bundles
- AST-level obfuscation: variable renaming, string encryption (Base64 + custom stream cipher / polymorphic variants), dead-code injection, control-flow flattening
- Always runs Terser compression on output
- Optional VM virtualization (covers common syntax; see limitations)
- Optional anti-hook runtime guard (detects tampering of common built-ins)
- VM opcode mapping randomization and mask obfuscation, fake opcode injection (configurable via
vm.opcodeShuffle/vm.fakeOpcodes) - VM bytecode runtime decryption (can be disabled via
vm.bytecodeEncrypt) - VM const pool runtime decryption (can be disabled via
vm.constsEncrypt) - Highly modular plugin architecture for easy extension
Install
npm installUsage
node bin/js-obf input.js -o output.js --preset high --vm --seed my-seedSupports stdin (use - as input):
cat input.js | node bin/js-obf - -o output.jsInteractive script
Use the interactive script to choose features and specify input file/directory and output directory:
bash bin/obf.shIf an input directory is provided, it will recursively obfuscate all .js files and overwrite them, automatically ignoring node_modules (also tolerates common misspellings of that directory name).
CLI options
-o, --output <file>Output file--preset <high|balanced|low>Preset strength (defaulthigh)--no-renameDisable variable renaming--no-stringsDisable string encryption--no-cffDisable control-flow flattening--no-deadDisable dead-code injection--vmEnable VM virtualization (see limitations)--vm-include name1,name2Only virtualize the specified function names--vm-opcode-shuffleEnable VM opcode random mapping (default on)--no-vm-opcode-shuffleDisable VM opcode random mapping--vm-fake-opcodes <0-1>Fake opcode injection probability (default 0.15)--vm-bytecodeEnable VM bytecode runtime decryption (default on)--no-vm-bytecodeDisable VM bytecode runtime decryption--vm-constsEnable VM const pool runtime decryption (default on)--no-vm-constsDisable VM const pool runtime decryption--vm-downlevelAllow VM to downlevellet/consttovar--anti-hookEnable anti-hook runtime guard--anti-hook-lockEnable anti-hook and freeze built-in prototype chains--seed <value>PRNG seed--ecma <version>Terser output ECMAScript version (default 2015)--sourcemapEmit source map--compactCompact output
Default output is ES2015 to preserve let/const. For ES5, set --ecma 5.
VM virtualization coverage
VM supports most common syntax while keeping performance and memory overhead reasonable:
- Control flow:
if/else,for/while/do-while,switch,break/continue - Exceptions:
try/catch/finally(supportsthrow) async/await(only insideasyncfunctions)- Variables:
var(let/constare skipped by default; use--vm-downlevelto force) - Parameters: defaults, rest params, parameter destructuring (object/array)
- Expressions: literals, member access, function calls, object/array literals,
new, template strings, etc.
VM limitations
- Generator function bodies are not virtualized (functions containing
yieldare skipped, but you can declare generators inside normal functions) - Optional chaining / nullish coalescing (
?./??) not supported spread(call/array/object) and object rest destructuring not supported- Destructuring assignment expressions are not supported (only parameter/variable declaration destructuring)
- Complex or unsupported nodes are skipped for that function
- VM uses the
Functionconstructor to create closures; CSP-restricted environments may not run
Structure
src/index.js: core APIsrc/pipeline.js: plugin pipelinesrc/plugins/*: obfuscation pluginssrc/utils/*: utilities and RNGbin/js-obf: CLI entry
License
MIT License. See LICENSE.
Third-Party Notices
Some dependencies require preserving author and license notices. See THIRD_PARTY_NOTICES.md.
