Development Workflow
Watch Mode for Rapid Development
For ease of development, you can automatically recompile transforms when source files change:This command watches for changes in any
*.js files (excluding obfuscated-original.js and deobfuscated.js) and automatically recompiles the deobfuscation transform.Working with Test Files
Place the obfuscated JavaScript inmitmproxy/src/javascript/obfuscated-original.js to test your transforms in isolation.
Debugging State
Chrome Debug Logs
If you start Chrome with the--enable-logging --v=1 flags, you can view console output without opening the browser:
<user-data-dir>/chrome_debug.log.
Viewing JSON Output
To extract just the JSON output from debug logs:Pre-Transform Debugging Utilities
Thepre-transform-code.js file contains several debugging utilities that are injected into the deobfuscated code:
Console Logger
State Printer
Circular Reference Handling
The debugging utilities handle circular object references automatically:Function State Tracking
Global State Debugging
Understanding Global State
TheglobalState[35] is the execution context of the tape, containing:
globalStateWriteIndexglobalStateReadIndex- Bits for manipulation
- Array length
- Pointers to the tape for the current execution context
Detecting Global State Changes
The debugging utilities can detect and report changes in global state:AST Debugging
Using AST Explorer
For manipulating JavaScript AST, use https://astexplorer.net/ to:- Visualize AST structure
- Test jscodeshift transforms
- Understand node types and properties
Debugger Statements
The ChainedTransformer includes a debugger statement for stepping through transforms:Browser Recommendations
Useful Extensions
- Clear Cache Extension: Quickly clear cache from toolbar or with keyboard shortcuts
- Avoid using
obfuscated-code-logger.jsexcessively as it adds significant noise to console logs
Common Debugging Scenarios
Scenario 1: Transform Not Working
Check intermediate outputs
Check intermediate outputs
Enable intermediate file output to see the result of each transform step:This creates files like
deobfuscated-output-0.js, deobfuscated-output-1.js, etc.Verify AST matching
Verify AST matching
Use AST Explorer to verify your node matching patterns are correct. The actual AST structure may differ from expectations.
Scenario 2: Global State Changes
Track state modifications
Track state modifications
Insert
beforeFunctionState and afterFunctionState calls around suspicious functions to track state changes.Filter noise
Filter noise
Modify
isChangeMapEmpty to ignore specific global state indices that change frequently but aren’t relevant to your investigation.Scenario 3: DevTools Detection
When DevTools is open,
tapeKeywords[27269]: "" is added to the tape. This is bet365’s anti-debugging mechanism.Output Directory Structure
The/output directory contains:
<timestamp>-received-<index>.js: Original obfuscated code intercepted<timestamp>-deobfuscated-<index>.js: Deobfuscated code<timestamp>-sent-<index>.js: Final beautified code sent to browser<timestamp>-received-<index>.css: CSS files
Testing Your Changes
After making changes to transforms:- Clear the output directory
- Restart mitmproxy
- Reload the bet365 page
- Check the generated files in
/output - Verify the deobfuscated code is valid JavaScript
