Overview
The global state is a core runtime structure that tracks execution context, tape positions, and runtime values throughout the obfuscated JavaScript execution. Understanding the global state is crucial for reverse engineering the control flow.Global State Structure
The global state is implemented as an array (globalState) that serves as a central data store for the execution engine.
Key State Indices
globalState[35] - Execution Context
globalState[35] - Execution Context
The execution context of the tape system. This is the most frequently accessed state index.Contains:Example usage:
globalStateWriteIndex- Where to write the next valueglobalStateReadIndex- Where to read the next value- Bit manipulation values
- Array length tracking
- Tape position pointers
- Current execution context metadata
From README.md:170: “globalState[35]: is the execution context of the tape. This may contain the globalStateWriteIndex, globalStateReadIndex, bits for manipulation, length of the array, etc… basically all sorts of things that point to the tape for the current execution context.”
State Tracking System
Thepre-transform-code.js file provides utilities for tracking state changes during execution:
State Capture Functions
mitmproxy/src/javascript/pre-transform-code.js
Name of the function being tracked
The current global state array
Change Detection
ThegetGlobalStateChanges function compares two state snapshots:
mitmproxy/src/javascript/pre-transform-code.js
Map where:
- Key: Global state index that changed
- Value:
[oldValue, newValue]tuple
Filtering Noise
mitmproxy/src/javascript/pre-transform-code.js
globalState[35] changed, since it changes on every function call (execution context updates).
State Logging
Console Logger
mitmproxy/src/javascript/pre-transform-code.js
Circular Reference Handling
mitmproxy/src/javascript/pre-transform-code.js
State Variables from Transform Pipeline
The deobfuscation process identifies these state-related variables:Write Operations
globalStateWriteIndex- Primary write indexglobalStateWriteStringValue- String value being written- Various specific write indices for operations
Read Operations
globalStateReadIndex- Primary read indexglobalStateReadIndex1- First operand read indexglobalStateReadIndex2- Second operand read indexglobalStateReadValueIndex- Index for reading valuesglobalStateReadObjectKeyIndex- Index for reading object keysglobalStateReadObjectIndex- Index for reading objects
Context Management
globalStateContexts- Stack of execution contextsglobalStateContextValues- Values in current contextglobalStateEvalStringIndex- Index for eval operationsglobalStateErrorIndex- Error handling indexlatestGlobalStateContext- Most recent context
Specific State Indices
Debugging State
When Chrome is started with logging flags:State Monitoring Best Practices
Avoid tracking globalState[35] changes alone - Since it changes on every function call, filter it out to see meaningful state changes.
Track State Before and After Functions
Track State Before and After Functions
Print Only Meaningful Changes
Print Only Meaningful Changes
Tape Keywords Tracking
The state system also tracks tape keywords:mitmproxy/src/javascript/pre-transform-code.js
From README.md:179: “When the devtool is open the tapeKeywords[27269]: ”” is added, indicating the obfuscated code detects DevTools.
State Array Access Patterns
Writing Values
Reading Values
Context Operations
Related Concepts
- Tape System - The bytecode that manipulates global state
- Transform Scripts - How state variables are renamed during deobfuscation
