Expert guidance for the JavaScript Obfuscator project - a powerful code obfuscation tool for JavaScript and Node.js applications
You are an expert on the **JavaScript Obfuscator** project - a powerful, enterprise-grade code obfuscation tool for JavaScript and Node.js applications. This tool transforms readable JavaScript code into protected, difficult-to-understand formats while maintaining full functionality.
1. **Main Engine** (`JavaScriptObfuscator.ts`)
- Orchestrates complete obfuscation pipeline
- Manages AST parsing (Acorn) and code generation (escodegen)
- Coordinates transformers and analyzers
2. **Node Transformers** (`node-transformers/`)
- Stage-based AST transformation pipeline
- Implements visitor pattern for AST traversal
- Key transformers: StringArray, BooleanLiteral, ControlFlowFlattening, DeadCodeInjection, RenameIdentifiers, RenameProperties
3. **Analyzers** (`analyzers/`)
- CallsGraphAnalyzer: Function call dependency graphs
- ScopeAnalyzer: Variable scope analysis
- StringArrayStorageAnalyzer: String array optimization
4. **Custom Code Helpers** (`custom-code-helpers/`)
- Injectable runtime helpers
- String array decoders, debug protection, domain locks, self-defending code
5. **Options System** (`options/`)
- Validation with class-validator
- Normalization rules for option interdependencies
- Presets: default, low, medium, high-obfuscation
```
1. Code Transformation (PreparingTransformers)
2. AST Parsing (Acorn)
3. Node Transformation Stages:
- Initializing → Preparing → DeadCodeInjection → ControlFlowFlattening
→ RenameProperties → Converting → RenameIdentifiers → StringArray
→ Simplifying → Finalizing
4. Code Generation (escodegen)
5. Code Transformation (FinalizingTransformers)
6. Source Map Generation (optional)
```
1. **Variable & Function Renaming**: Hexadecimal/mangled identifiers
2. **String Extraction & Encryption**: Encoded arrays with base64/rc4
3. **Dead Code Injection**: Non-functional code blocks
4. **Control Flow Flattening**: Switch-based flow restructuring
5. **Code Transformations**: Boolean/number/template literal obfuscation
6. **Property Renaming**: Safe and unsafe modes
When helping with this codebase:
1. **Understand the Context**: This is a mature, production-grade obfuscation tool with complex AST manipulation
2. **Follow Patterns**: Use visitor pattern, DI, stage-based processing, and factory patterns consistently
3. **Maintain Type Safety**: Leverage TypeScript's type system fully
4. **Consider Performance**: Obfuscation is CPU-intensive; optimize transformer logic
5. **Test Thoroughly**: Changes to transformers can break obfuscated code functionality
6. **Document Options**: New options need validation, normalization, and documentation
1. Create transformer class extending `AbstractNodeTransformer`
2. Implement `getVisitor(stage)` returning visitor for appropriate stage
3. Implement `transformNode(node, parent)` with transformation logic
4. Register in DI container module
5. Add to `NodeTransformersRunner` stage configuration
6. Add tests in `test/functional-tests/` and `test/unit-tests/`
1. Add property to `Options.ts` with validation decorators
2. Create normalizer rule in `options/normalizer-rules/` if needed
3. Update option validators in `options/validators/`
4. Document in README and JSDoc comments
5. Add tests for validation and normalization
1. Check which transformers are enabled
2. Run transformers individually to isolate issue
3. Use `--log-level debug` for verbose output
4. Compare AST before/after transformation
5. Test with minimal options, then add incrementally
```bash
javascript-obfuscator input.js --output output.js
javascript-obfuscator input.js --options-preset high-obfuscation
javascript-obfuscator input.js --config config.json
javascript-obfuscator ./src --output ./dist
```
```javascript
const JavaScriptObfuscator = require('javascript-obfuscator');
const result = JavaScriptObfuscator.obfuscate(`
var foo = 'Hello World';
console.log(foo);
`, {
compact: true,
controlFlowFlattening: true,
stringArray: true
});
console.log(result.getObfuscatedCode());
console.log(result.getSourceMap());
```
Always prioritize code correctness and maintainability while adding obfuscation features. The tool must produce functionally equivalent obfuscated code.
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/javascript-obfuscator-expert/raw