Overview
The transform scripts use jscodeshift to perform Abstract Syntax Tree (AST) transformations on obfuscated JavaScript code. The transformation pipeline consists of 11 sequential transforms that progressively deobfuscate and refactor the code.Transform Pipeline
All transforms are chained together inrefactor-obfuscated-code-jscodeshift-chained.js and executed sequentially:
Base Transformer Class
All transformers extend theAstTransformer base class:
mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-common.js
The sequential step number in the transformation pipeline
The jscodeshift AST collection to transform
Whether to write intermediate output files for debugging
Base name for output files (defaults to
deobfuscated-output)Transform Stages
0. Void0Transformer
0. Void0Transformer
Converts Implementation:
void 0 expressions to undefined literals.Location: mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-0.js:101. UnaryExpressionTransformer
1. UnaryExpressionTransformer
Simplifies unary expressions like Operators:
!0 and !1 to boolean literals.Location: mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-1.js:13!0→true!1→false
2. RefactorVariableTransformer
2. RefactorVariableTransformer
Renames obfuscated variable names to meaningful identifiers based on a 288-entry mapping.Location:
mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-2.js:296Key variable mappings:_0x588211→globalState_0x478891→tape_0x4951e9→functions_0x38dc1b→modules_0xfe71f0→globalStateWriteIndex_0x551c19→globalStateReadIndex1_0x20e93a→globalStateReadIndex2
3. VariableReplacementTransformer
3. VariableReplacementTransformer
Replaces and removes redundant variable declarations.Location:
mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-3.js:13Replacements:_0x49b7bf→globalStateContextValues_0x173146→window
x = x.4. ParameterRefactorTransformer
4. ParameterRefactorTransformer
Renames function parameters to meaningful names, with scope-aware renaming.Location:
mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-4.js:45Key parameter mappings:_0x343255→tapeBase64_0x58916a→base64Tape_0x2a2310→globalStateContexts_0x2461da→['keywordArray', 'keywordArray', 'index'](scope-specific)
5. FunctionRefactorTransformer
5. FunctionRefactorTransformer
Renames obfuscated function names to descriptive identifiers.Location:
mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-5.js:19Function mappings:_0x21f1e2→getModule_0x2facc3→bootstrapModule_0x50286d→initialiseState_0x68e20a→executeFunctionAtExecutionIndex_0x4fdfce→executeFunction_0x50ee92→base64ToBytes_0x5953e4→createPaddedBinaryString
6. RemoveKeywordsTransformer
6. RemoveKeywordsTransformer
Removes keyword array lookup operations that are no longer needed after deobfuscation.Location:
mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-6.jsThis transform cleans up artifact references to the obfuscated keyword lookup system.7. BracketToDotNotationTransformer
7. BracketToDotNotationTransformer
Converts bracket notation to dot notation for common property access.Location: Converted properties:
mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-7.js:12push, shift, code, length, call, exports, charCodeAt, fromCharCode, toString, charAt, substr, indexOf, pow, pop, apply, slice, from, repeat, bind, prototype, and more.8. RemovedUnusedParametersTransformer
8. RemovedUnusedParametersTransformer
Removes unused function parameters identified during analysis.Location:
mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-8.jsCleans up parameters marked as unused in the refactoring process.9. RemovedClosestTransformer
9. RemovedClosestTransformer
Removes unnecessary closest selector patterns or wrapper functions.Location:
mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-9.js10. RemoveStaleIdentifierTransformer
10. RemoveStaleIdentifierTransformer
Final cleanup pass to remove any remaining stale or unused identifiers.Location:
mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-10.jsUsage
Running the Transform Pipeline
Path to the obfuscated JavaScript file
Path where deobfuscated output will be written
Whether to output intermediate files after each transform step
Development Workflow
For continuous development with automatic recompilation:.js files and automatically reruns the transformation pipeline.
Output Files
WhenoutputIntermediateSteps is enabled, each transformer generates a separate output file:
deobfuscated-output-0.js- After Void0Transformerdeobfuscated-output-1.js- After UnaryExpressionTransformerdeobfuscated-output-2.js- After RefactorVariableTransformer- … and so on through step 10
Intermediate output files are useful for debugging transformation issues. You can inspect the AST state at each stage to identify where unexpected transformations occur.
AST Visualization
For developing new transforms or debugging issues, use AST Explorer to visualize and test transformations interactively.Code Generation
The final AST is converted back to JavaScript using:- jscodeshift - Converts the AST collection to source code
- esprima - Parses the source into a standard ESTree AST
- escodegen - Generates formatted JavaScript code
