DSL VM Reverse Engineering
Overview
Many hardened web applications do not run their anti-bot or risk-control logic
as plain JavaScript. Instead they compile it to a custom bytecode interpreted by
a hand-rolled virtual machine — an IIFE wrapping a switch-based opcode
dispatcher over a single-letter variable array (typically d[]), with a
constant table (typically C[9]). The dispatcher is usually named DG(),
W() or similar. Because the interpreter never appears in source maps and the
bytecode is stored as a numeric constant table, the logic is invisible to
standard static review and survives even after the surrounding JS is
beautified.
This skill is a repeatable, six-phase workflow for reversing such engines:
identify the VM, recover variable and opcode semantics, extract the constant
table, locate exported functions, and — when static analysis is not enough —
capture VM state at runtime. It targets the common AWSCInner family of
risk-control engines but generalizes to any IIFE/switch-based dispatcher.
Source: cherry-picked and translated from zhaoxuya520/reverse-skill
(skills/reverse-engineering/dsl-vm-reverse, MIT license).
When to Use
Trigger phrases:
- "reverse a DSL VM"
- "analyze risk-control engine bytecode"
- "extract opcode table from obfuscated JS"
- "recover VM semantics from an IIFE dispatcher"
- "capture VM state at runtime"
- "reconstruct execution flow of an anti-bot interpreter"
Use this skill when:
- A page's behavior is driven by an interpreter whose
switch dispatch handles
numeric opcodes rather than readable statements.
- You need the meaning of opcodes, operands, or the constant table before you
can reason about what the code does.
- Static beautified JS is not enough and you must capture interpreter state
(variables, return values, module exports) at runtime.
- You are analyzing a WASM-like runtime that is not actual WebAssembly
(
\x00asm magic absent) but a JS bytecode VM.
Prerequisites
- Node.js 18+ for running reconstructed VM code and scripts.
- A browser automation stack for runtime capture: Selenium with CDP access, or
Playwright (
npm i playwright).
- A JS beautifier (prettier, js-beautify) and a code editor with regex search.
- Optional: Chrome DevTools Protocol knowledge for
Input.dispatchMouseEvent.
Workflow
Phase 1: VM Identification (10-30 min)
Confirm the target is a custom DSL VM and not plain JS:
- Check for a WASM payload: scan for the
\x00asm magic bytes and compute the
zero-byte percentage of the script. A high zero-byte ratio with no \x00asm
header points to a custom bytecode blob, not WASM.
- Look for the IIFE pattern
var U=void 0; or equivalent single-letter
hoisting that precedes a switch (d[7]&31) style dispatcher.
- Confirm the dispatcher signature:
function DG(){...} reading and writing a
shared array d[], with a constant table C[9] referenced as C[9][n].
If none of these match, the target is ordinary obfuscated JS — use
js-reverse instead.
Phase 2: Variable Mapping (30-60 min)
Build a variable meaning table before touching opcodes:
- Extract assignments: regex
var\s+(\w+)\s*=\s*(\d+) over the first 2000
characters of the VM body.
- Record the numeric literal bound to each single-letter variable. These
literals are array indices or opcode constants, not real values.
- Map the dispatcher array:
d[7] is typically the instruction pointer /
current opcode slot, d[4]/d[5] arithmetic registers, d[6] the operand
stack, d[8] a scratch register, d[9] a return/throw slot. Verify each
role from its usage across the switch body.
Phase 3: Opcode Extraction and Classification (1-2 hours)
Extract every case N: label from the dispatcher switch. Each case is one
opcode.
Classify each case by its statement shape (see the reference table below):
| Statement shape |
Classification |
d[7]=... (no condition) |
BRANCH |
return ... / throw ... |
RETURN |
W(C[ ... ,null,function(){...}) |
CALL |
new ... |
ALLOC |
try{...}catch(...){...} |
EXCEPTION |
d[x]=d[y][C[n]] / d[x]=d[y]<d[z] |
ARITH / STORE |
P[d[9]]=... |
STORE (data handoff) |
Record, for each opcode number, the classification and a one-line comment
describing its effect. Keep this table in your notes — it becomes the
instruction set reference for Phase 5.
Phase 4: Constant Table Analysis (30-60 min)
- Grep the VM for references to the constant table:
C\[9\]\[(\d+)\].
- Collect the full set of referenced indices — this bounds how much bytecode
the interpreter can address.
- For each referenced index, note the constant value and where it is consumed
(opcode operand, function index, string pool offset).
- The constant table is the bytecode store: exported functions whose bodies
are not present as JS source are implemented as numeric sequences in
C[9].
Phase 5: Exported Function Tracing (1-2 hours)
Find the registration call, e.g. AWSCInner.register(name, moduleName, factory) or an equivalent register() invocation.
Resolve moduleName → the factory function → the object it returns.
If a function name does not exist in the JS source, it is stored as
bytecode in C[9] — note the index range.
Trace the call chain:
AWSCInner._modules['fy'].getToken()
→ W(C[<functionIndex>], null, ...)
→ DG() // interpreter executes the encoded instruction sequence
Convert the traced bytecode range into the reconstructed semantics from
Phase 3 so you can read what the exported function actually computes.
Phase 6: Runtime Injection (when static analysis is insufficient)
If pure static reconstruction stalls (unresolved jumps, dynamic table writes,
state-dependent branches), inject a minimal compatible environment and run the
VM:
// Minimal AWSC-compatible environment
const fakeEnv = {
AWSCInner: {
_modules: {},
register(name, moduleName, factory) {
this._modules[moduleName] = factory();
}
}
};
// Execute the DSL VM code in this sandbox
dslVmCode.call(fakeEnv);
// Read exports
const token = fakeEnv.AWSCInner._modules['fy'].getToken({});
Drive the real page when the VM needs live browser context (see Runtime
Capture below). In either case, log every d[] write at interesting opcodes to
produce a state trace for verification.
Opcode Reference (observed on AWSC-family engines)
| Opcode |
Type |
Characteristic statement |
| 0 |
BRANCH |
d[7]=xxx unconditional jump |
| 1 |
CALL |
W(C[Y],null,function(){...}) embedded call |
| 2 |
ARITH |
d[4]=0, d[7]=72 register assignment |
| 3 |
ARITH |
d[0]=d[1][C[x]], d[5]=d[0]<d[3] compare |
| 4 |
STORE |
d[8]=d[5]in d[4] property/in check |
| 5 |
ARITH |
d[8]=d[4]-d[8] arithmetic |
| 6 |
RETURN |
return gV / throw |
| 7 |
ALLOC |
d[6]=[], d[6][C[8]](...) push |
| 8 |
BRANCH |
d[7]=d[k]?512:425 conditional jump |
| 9 |
STRING |
d[6][C[t]]=d[m], new fh(...) regex |
| 10 |
ALLOC |
argument prep, call-frame creation |
| 11 |
STRING |
new fh("\\s",d[5]) regex match |
| 12 |
STORE |
P[d[9]]=d[4][C[H]](d[3]) data handoff |
| 13 |
CALL |
C[9][113]=d[9] module init |
| 14 |
STRING |
d[8]=d[9]+d[m] string concat |
| 15 |
RETURN |
return EL; |
| 16 |
ALLOC |
var r,P,Z,B... local declarations |
| 17 |
ALLOC |
(Z=[])[C[8]](69,T,445) static array init |
| 18 |
TABLE |
function/type table init |
| 19 |
EXCEPTION |
try{for(var RK=x;... try-catch loop |
| 20 |
DOM |
Is[d[o]] DOM operation |
| 21 |
STORE |
safe global/object property fetch |
| 22 |
STRING |
new fh(r,v) string/regex handling |
| 23 |
BRANCH |
try-catch safe fetch + conditional jump |
| 24 |
CALL |
W(C[2],null,8,z,FL) multi-arg call |
| 25 |
EXCEPTION |
try{...}catch(C){...} catch + jump |
Opcode bit layout (observed): 5-bit opcode | 5-bit sub-opcode | operand.
Decoded in JS as d[7]&31 (opcode), d[7]>>5&31 (sub-opcode). Verify the
layout per sample before relying on it.
Runtime Capture
Option A: Selenium + CDP native events (recommended, highest success)
from selenium import webdriver
driver = webdriver.Chrome()
# Inject anti-detection before any script runs
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": r"""
Object.defineProperty(navigator, 'webdriver', {get: () => false});
Object.defineProperty(navigator, 'plugins', {get: () => [1,2,3,4,5]});
Object.defineProperty(navigator, 'languages', {get: () => ['zh-CN','zh','en']});
"""
})
# Send trusted CDP mouse events
driver.execute_cdp_cmd("Input.dispatchMouseEvent", {
"type": "mousePressed",
"x": 549.5, "y": 441.2,
"button": "left", "buttons": 1,
"clickCount": 1, "pointerType": "mouse"
})
Option B: Playwright headless browser
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
// Observe API traffic while the VM runs
await page.route('**/api/**', async route => { await route.continue_(); });
await page.goto('https://target-page.com');
// Wait until the DSL VM finished initializing
await page.waitForFunction(() => {
return window.AWSCInner &&
window.AWSCInner._modules &&
window.AWSCInner._modules['fy'];
});
// Trigger the flow that runs the bytecode
await page.mouse.move(500, 400);
await page.mouse.down();
// ... interaction sequence ...
await page.mouse.up();
await browser.close();
})();
Option C: Pure protocol replay (very low success — avoid)
DSL VM tokens are usually bound to the browser context (TLS JA3 fingerprint,
IP, cookies, request headers). Replaying the captured token outside the browser
lets the server detect the context mismatch. Do not default to a pure
protocol approach.
Common Status Codes (AWSC-family)
| Code |
Meaning |
Handling |
| 0 |
Verification passed |
Extract sessionId + sig |
| 300 |
Risk-control blocked |
Blocked; cannot pass |
| 8778 |
Verification failed, retry |
Retry the operation |
| 8776 |
Action too fast, retry |
Add delay, then retry |
| 69634 |
Generic failure |
Check request parameters |
Verification
Run this self-check before claiming the reversal is complete:
When NOT to Use
- The code is ordinary obfuscated JavaScript with no interpreter — use
js-reverse instead.
- The target is real WebAssembly (has
\x00asm magic) — WASM tooling applies.
- You only need the request/response contract, not the VM semantics — protocol
analysis is faster and sufficient.
Anti-Rationalization Table
| Rationalization |
Reality |
| "The switch is too long; I'll only read the opcodes I hit first." |
An incomplete opcode table misreads later bytecode. Classify all case N: labels before concluding semantics. |
| "I beautified the JS, so the logic is now readable." |
Beautifying does not decode bytecode. The logic lives in the C[9] table + dispatcher, not the source formatting. |
| "I'll just replay the captured token with curl." |
Tokens are context-bound (JA3, IP, cookies). Server-side context mismatch detection defeats pure protocol replay. |
| "The variable names are meaningless, so I can skip mapping them." |
The numeric literals bound to those variables are the indices and constants the VM needs — skipping the map guarantees misreads. |
| "One captured output is enough evidence." |
A single match can be luck. Verify against at least two independent captures before claiming correctness. |
1---2name: dsl-vm-reverse3description: Use when reverse JavaScript-based custom DSL/VM interpreters, non-standard4 WASM-like runtimes, and risk-control engines. Use when analyzing IIFE or switch-based5 opcode dispatchers, extracting instruction tables, recovering bytecode semantics,6 capturing VM state at runtime, or reconstructing execution flow.7domain: cybersecurity8subdomain: web-application-security9tags:10- javascript11- reverse-engineering12- dsl13- vm14- anti-bot15- obfuscation16- risk-control17- web-application-security18version: '1.0'19author: oyi7720license: Apache-2.021nist_csf:22- DE.AE-0223- RS.AN-0324- ID.RA-0125- DE.CM-0126category: cybersecurity27metadata:28 source: https://skillmd.com/skills/oyi77/dsl-vm-reverse29---303132# DSL VM Reverse Engineering3334## Overview3536Many hardened web applications do not run their anti-bot or risk-control logic37as plain JavaScript. Instead they compile it to a custom bytecode interpreted by38a hand-rolled virtual machine — an IIFE wrapping a `switch`-based opcode39dispatcher over a single-letter variable array (typically `d[]`), with a40constant table (typically `C[9]`). The dispatcher is usually named `DG()`,41`W()` or similar. Because the interpreter never appears in source maps and the42bytecode is stored as a numeric constant table, the logic is invisible to43standard static review and survives even after the surrounding JS is44beautified.4546This skill is a repeatable, six-phase workflow for reversing such engines:47identify the VM, recover variable and opcode semantics, extract the constant48table, locate exported functions, and — when static analysis is not enough —49capture VM state at runtime. It targets the common `AWSCInner` family of50risk-control engines but generalizes to any IIFE/switch-based dispatcher.5152Source: cherry-picked and translated from `zhaoxuya520/reverse-skill`53(`skills/reverse-engineering/dsl-vm-reverse`, MIT license).5455## When to Use5657**Trigger phrases:**58- "reverse a DSL VM"59- "analyze risk-control engine bytecode"60- "extract opcode table from obfuscated JS"61- "recover VM semantics from an IIFE dispatcher"62- "capture VM state at runtime"63- "reconstruct execution flow of an anti-bot interpreter"6465Use this skill when:6667- A page's behavior is driven by an interpreter whose `switch` dispatch handles68 numeric opcodes rather than readable statements.69- You need the meaning of opcodes, operands, or the constant table before you70 can reason about what the code does.71- Static beautified JS is not enough and you must capture interpreter state72 (variables, return values, module exports) at runtime.73- You are analyzing a WASM-like runtime that is not actual WebAssembly74 (`\x00asm` magic absent) but a JS bytecode VM.7576## Prerequisites7778- Node.js 18+ for running reconstructed VM code and scripts.79- A browser automation stack for runtime capture: Selenium with CDP access, or80 Playwright (`npm i playwright`).81- A JS beautifier (prettier, js-beautify) and a code editor with regex search.82- Optional: Chrome DevTools Protocol knowledge for `Input.dispatchMouseEvent`.8384## Workflow8586### Phase 1: VM Identification (10-30 min)8788Confirm the target is a custom DSL VM and not plain JS:89901. Check for a WASM payload: scan for the `\x00asm` magic bytes and compute the91 zero-byte percentage of the script. A high zero-byte ratio with no `\x00asm`92 header points to a custom bytecode blob, not WASM.932. Look for the IIFE pattern `var U=void 0;` or equivalent single-letter94 hoisting that precedes a `switch (d[7]&31)` style dispatcher.953. Confirm the dispatcher signature: `function DG(){...}` reading and writing a96 shared array `d[]`, with a constant table `C[9]` referenced as `C[9][n]`.9798If none of these match, the target is ordinary obfuscated JS — use99`js-reverse` instead.100101### Phase 2: Variable Mapping (30-60 min)102103Build a variable meaning table before touching opcodes:1041051. Extract assignments: regex `var\s+(\w+)\s*=\s*(\d+)` over the first 2000106 characters of the VM body.1072. Record the numeric literal bound to each single-letter variable. These108 literals are array indices or opcode constants, not real values.1093. Map the dispatcher array: `d[7]` is typically the instruction pointer /110 current opcode slot, `d[4]`/`d[5]` arithmetic registers, `d[6]` the operand111 stack, `d[8]` a scratch register, `d[9]` a return/throw slot. Verify each112 role from its usage across the switch body.113114### Phase 3: Opcode Extraction and Classification (1-2 hours)1151161. Extract every `case N:` label from the dispatcher switch. Each case is one117 opcode.1182. Classify each case by its statement shape (see the reference table below):119120 | Statement shape | Classification |121 |---|---|122 | `d[7]=...` (no condition) | BRANCH |123 | `return ...` / `throw ...` | RETURN |124 | `W(C[` ... `,null,function(){...})` | CALL |125 | `new ...` | ALLOC |126 | `try{...}catch(...){...}` | EXCEPTION |127 | `d[x]=d[y][C[n]]` / `d[x]=d[y]<d[z]` | ARITH / STORE |128 | `P[d[9]]=...` | STORE (data handoff) |1291303. Record, for each opcode number, the classification and a one-line comment131 describing its effect. Keep this table in your notes — it becomes the132 instruction set reference for Phase 5.133134### Phase 4: Constant Table Analysis (30-60 min)1351361. Grep the VM for references to the constant table: `C\[9\]\[(\d+)\]`.1372. Collect the full set of referenced indices — this bounds how much bytecode138 the interpreter can address.1393. For each referenced index, note the constant value and where it is consumed140 (opcode operand, function index, string pool offset).1414. The constant table is the bytecode store: exported functions whose bodies142 are not present as JS source are implemented as numeric sequences in143 `C[9]`.144145### Phase 5: Exported Function Tracing (1-2 hours)1461471. Find the registration call, e.g. `AWSCInner.register(name, moduleName,148 factory)` or an equivalent `register()` invocation.1492. Resolve `moduleName` → the factory function → the object it returns.1503. If a function name does not exist in the JS source, it is stored as151 bytecode in `C[9]` — note the index range.1524. Trace the call chain:153154 ```javascript155 AWSCInner._modules['fy'].getToken()156 → W(C[<functionIndex>], null, ...)157 → DG() // interpreter executes the encoded instruction sequence158 ```1591605. Convert the traced bytecode range into the reconstructed semantics from161 Phase 3 so you can read what the exported function actually computes.162163### Phase 6: Runtime Injection (when static analysis is insufficient)164165If pure static reconstruction stalls (unresolved jumps, dynamic table writes,166state-dependent branches), inject a minimal compatible environment and run the167VM:168169```javascript170// Minimal AWSC-compatible environment171const fakeEnv = {172 AWSCInner: {173 _modules: {},174 register(name, moduleName, factory) {175 this._modules[moduleName] = factory();176 }177 }178};179180// Execute the DSL VM code in this sandbox181dslVmCode.call(fakeEnv);182183// Read exports184const token = fakeEnv.AWSCInner._modules['fy'].getToken({});185```186187Drive the real page when the VM needs live browser context (see Runtime188Capture below). In either case, log every `d[]` write at interesting opcodes to189produce a state trace for verification.190191## Opcode Reference (observed on AWSC-family engines)192193| Opcode | Type | Characteristic statement |194|---|---|---|195| 0 | BRANCH | `d[7]=xxx` unconditional jump |196| 1 | CALL | `W(C[Y],null,function(){...})` embedded call |197| 2 | ARITH | `d[4]=0`, `d[7]=72` register assignment |198| 3 | ARITH | `d[0]=d[1][C[x]]`, `d[5]=d[0]<d[3]` compare |199| 4 | STORE | `d[8]=d[5]in d[4]` property/in check |200| 5 | ARITH | `d[8]=d[4]-d[8]` arithmetic |201| 6 | RETURN | `return gV` / `throw` |202| 7 | ALLOC | `d[6]=[]`, `d[6][C[8]](...)` push |203| 8 | BRANCH | `d[7]=d[k]?512:425` conditional jump |204| 9 | STRING | `d[6][C[t]]=d[m]`, `new fh(...)` regex |205| 10 | ALLOC | argument prep, call-frame creation |206| 11 | STRING | `new fh("\\s",d[5])` regex match |207| 12 | STORE | `P[d[9]]=d[4][C[H]](d[3])` data handoff |208| 13 | CALL | `C[9][113]=d[9]` module init |209| 14 | STRING | `d[8]=d[9]+d[m]` string concat |210| 15 | RETURN | `return EL;` |211| 16 | ALLOC | `var r,P,Z,B...` local declarations |212| 17 | ALLOC | `(Z=[])[C[8]](69,T,445)` static array init |213| 18 | TABLE | function/type table init |214| 19 | EXCEPTION | `try{for(var RK=x;...` try-catch loop |215| 20 | DOM | `Is[d[o]]` DOM operation |216| 21 | STORE | safe global/object property fetch |217| 22 | STRING | `new fh(r,v)` string/regex handling |218| 23 | BRANCH | try-catch safe fetch + conditional jump |219| 24 | CALL | `W(C[2],null,8,z,FL)` multi-arg call |220| 25 | EXCEPTION | `try{...}catch(C){...}` catch + jump |221222Opcode bit layout (observed): 5-bit opcode | 5-bit sub-opcode | operand.223Decoded in JS as `d[7]&31` (opcode), `d[7]>>5&31` (sub-opcode). Verify the224layout per sample before relying on it.225226## Runtime Capture227228### Option A: Selenium + CDP native events (recommended, highest success)229230```python231from selenium import webdriver232233driver = webdriver.Chrome()234235# Inject anti-detection before any script runs236driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {237 "source": r"""238 Object.defineProperty(navigator, 'webdriver', {get: () => false});239 Object.defineProperty(navigator, 'plugins', {get: () => [1,2,3,4,5]});240 Object.defineProperty(navigator, 'languages', {get: () => ['zh-CN','zh','en']});241 """242})243244# Send trusted CDP mouse events245driver.execute_cdp_cmd("Input.dispatchMouseEvent", {246 "type": "mousePressed",247 "x": 549.5, "y": 441.2,248 "button": "left", "buttons": 1,249 "clickCount": 1, "pointerType": "mouse"250})251```252253### Option B: Playwright headless browser254255```javascript256const { chromium } = require('playwright');257258(async () => {259 const browser = await chromium.launch();260 const page = await browser.newPage();261262 // Observe API traffic while the VM runs263 await page.route('**/api/**', async route => { await route.continue_(); });264265 await page.goto('https://target-page.com');266267 // Wait until the DSL VM finished initializing268 await page.waitForFunction(() => {269 return window.AWSCInner &&270 window.AWSCInner._modules &&271 window.AWSCInner._modules['fy'];272 });273274 // Trigger the flow that runs the bytecode275 await page.mouse.move(500, 400);276 await page.mouse.down();277 // ... interaction sequence ...278 await page.mouse.up();279 await browser.close();280})();281```282283### Option C: Pure protocol replay (very low success — avoid)284285DSL VM tokens are usually bound to the browser context (TLS JA3 fingerprint,286IP, cookies, request headers). Replaying the captured token outside the browser287lets the server detect the context mismatch. **Do not default to a pure288protocol approach.**289290## Common Status Codes (AWSC-family)291292| Code | Meaning | Handling |293|---|---|---|294| 0 | Verification passed | Extract `sessionId` + `sig` |295| 300 | Risk-control blocked | Blocked; cannot pass |296| 8778 | Verification failed, retry | Retry the operation |297| 8776 | Action too fast, retry | Add delay, then retry |298| 69634 | Generic failure | Check request parameters |299300## Verification301302Run this self-check before claiming the reversal is complete:303304- [ ] Confirmed VM identification (IIFE + single-letter vars + `DG()`-style305 dispatcher, no `\x00asm` magic).306- [ ] Extracted the variable mapping table (`var X=<number>` literals decoded).307- [ ] Extracted and classified the full opcode list from `case N:` labels.308- [ ] Analyzed the `C[9]` constant table reference range.309- [ ] Located the exported-function registration point and traced at least one310 export to its bytecode range.311- [ ] When static analysis was insufficient, attempted runtime injection and312 recorded a state trace.313- [ ] Reproduced one real output (token, signature, or computed value) and314 compared it against a live page capture — the outputs must match.315- [ ] Documented the opcode table and VM layout in the case notes for reuse.316317## When NOT to Use318319- The code is ordinary obfuscated JavaScript with no interpreter — use320 `js-reverse` instead.321- The target is real WebAssembly (has `\x00asm` magic) — WASM tooling applies.322- You only need the request/response contract, not the VM semantics — protocol323 analysis is faster and sufficient.324325## Anti-Rationalization Table326327| Rationalization | Reality |328|---|---|329| "The switch is too long; I'll only read the opcodes I hit first." | An incomplete opcode table misreads later bytecode. Classify all `case N:` labels before concluding semantics. |330| "I beautified the JS, so the logic is now readable." | Beautifying does not decode bytecode. The logic lives in the `C[9]` table + dispatcher, not the source formatting. |331| "I'll just replay the captured token with curl." | Tokens are context-bound (JA3, IP, cookies). Server-side context mismatch detection defeats pure protocol replay. |332| "The variable names are meaningless, so I can skip mapping them." | The numeric literals bound to those variables are the indices and constants the VM needs — skipping the map guarantees misreads. |333| "One captured output is enough evidence." | A single match can be luck. Verify against at least two independent captures before claiming correctness. |