agentleFS
xAmirHamza77xAmirHamza77/ReverseOps-Skill/skills/reverse-engineering/dsl-vm-reverse/SKILL.md

dsl-vm-reverse

Skill4 starsChanged 4 months agoMITView on GitHub

For reversing custom WASM virtual machines / risk-control engines implemented in JavaScript Use this skill when the target file matches any of the following traits: Each instruction is encoded as a 32-bit integer:

2 other projects use a version of this, 2 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when the target file matches any of the following traits:

    line 21

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

🔄 DSL Custom VM Reversing (DSL VM Reverse Engineering)

For reversing custom WASM virtual machines / risk-control engines implemented in JavaScript


Table of Contents

  • 1. Scope
  • 2. DSL VM Identification Traits
  • 3. General Reversing Workflow
  • 4. Opcode Extraction and Classification
  • 5. Runtime Capture Approaches
  • 6. Common Status Codes
  • 7. Skill Self-Check List

1. Scope

Use this skill when the target file matches any of the following traits:

#TraitDescription
1IIFE opening + many single-letter variable names!function(){var U=void 0,y=parseInt,E0=Function,...}
2Contains DG() or a similar function with a switch-case loopInterpreter main loop; d[7]&31 decodes the opcode
3Large file (500KB+) but zero-byte ratio < 1%Not standard WASM; pure JS
4Contains C[number] constant-table referencesC[9][xxx] function table/string table
5Single-line minified code583KB one-liner, obfuscated variable names

Exclusion Rules

ConditionNot this skillGo to
File starts with \x00asmStandard WASM binaryreverse-engineering/languages.md
File contains WASM magic as Uint8Array([0,97,115,109])Embedded WASMExtract the .wasm, then move to IDA/Ghidra
Standard Webpack bundle (function(e,t,n){...})Plain JSjs-reverse/
Zero-byte ratio > 20%WASM binaryreverse-engineering/languages.md

2. DSL VM Identification Traits

Code Traits

// Trait 1: IIFE entry; single-letter variables map to numeric constants
!function(){
    var U=void 0, y=parseInt, E0=Function, AN=Uint8Array;
    var E=15, l=10, m=12, x=16, S=13, $=11;
    // Numeric constants are mapped to variable names, replacing raw numbers
    ...
}

// Trait 2: Interpreter main loop DG()
function DG(C, d, ...) {
    var d = [];  // Array simulating the WASM stack/locals
    for (d[7] = x; d[7] !== U;) {
        var aE = d[7] & 31;         // Low 5 bits = opcode
        var O = d[7] >> 5 & 31;      // High 5 bits = sub-operation
        switch (aE) {
            case 0: /* ... */ d[7] = 612; break;
            case 1: /* ... */
            // ... N cases
        }
    }
}

// Trait 3: Constant table C[9] stores function indices and strings
// C[9][0] = ["pc"]      → function parameter descriptors
// C[9][667] = "string"  → string constants
// C[9][x] = number      → function indices

// Trait 4: W(C[index], null, ...) call pattern
// W = Function.prototype.call.bind(call)
// All builtin functions are invoked via C[index] indexing

// Trait 5: Instruction encoding format
// d[7] = opcode(bit 0-4) | subop(bit 5-9) | operand(bit 10+)

Opcode Encoding Format

Each instruction is encoded as a 32-bit integer:

bit 0-4:   opcode (0-N)
bit 5-9:   sub-operation (0-31)
bit 10-31: operand/immediate

Decoding:
  aE = d[7] & 31        → opcode
  O  = d[7] >> 5 & 31   → sub-operation
  d[other] = d[7] >> 10  → operand

3. General Reversing Workflow

Phase 1: File Classification (5 minutes)

# Check whether this is a DSL VM
python3 << 'EOF'
with open('target.js', 'rb') as f:
    head = f.read(100)

# 1. Check for the WASM magic
if head[:4] == b'\x00asm':
    print("standard WASM binary")
    exit()

# 2. Check the zero-byte ratio
data = open('target.js', 'rb').read()
zero_pct = data.count(b'\x00') / len(data) * 100
print(f"zero-byte ratio: {zero_pct:.1f}%")

if zero_pct > 20:
    print("WASM binary")
elif head[:2] == b'!f':
    # Check for the single-letter variable pattern
    if b'var U=void 0' in head or b'U=void 0,y=parseInt' in head:
        print("→ DSL VM!")
    else:
        print("plain JS IIFE")
EOF

Phase 2: Variable Mapping Table Extraction (10 minutes)

import re

with open('target.js', 'r', errors='replace') as f:
    s = f.read()

# Extract var X=number mappings from the first 2000 characters
mappings = re.findall(r'var\s+(\w+)\s*=\s*(\d+)', s[:2000])
print('Constant mappings:')
for name, val in mappings:
    print(f"  {name:4s} = {val:3d} (0x{int(val):02x})")

Phase 3: Opcode Extraction and Classification (15 minutes)

# 1. Extract all cases
all_cases = re.findall(r'case\s+(\d+):', s)
unique = sorted(set(int(c) for c in all_cases))

print(f"Total cases: {len(all_cases)}")
print(f"Unique opcodes: {len(unique)}: {unique}")

# 2. Classify each opcode
for op in unique:
    idx = s.find(f'case {op}:')
    snippet = s[idx:idx+200]
    if 'd[7]=' in snippet:
        op_type = 'BRANCH'
    elif 'return' in snippet:
        op_type = 'RETURN'
    elif 'W(C[' in snippet:
        op_type = 'CALL'
    elif 'new' in snippet:
        op_type = 'ALLOC'
    elif 'try' in snippet or 'catch' in snippet:
        op_type = 'EXCEPTION'
    else:
        op_type = 'ARITH/STORE'
    print(f"  opcode {op:2d}: {op_type}")

Phase 4: Constant Table Analysis (30 minutes)

const_refs = re.findall(r'C\[9\]\[(\d+)\]', s)
unique_refs = sorted(set(int(x) for x in const_refs))

print(f"C[9] references: {len(unique_refs)} indices")
print(f"Range: {min(unique_refs)} - {max(unique_refs)}")

# Analyze the context of each reference
for ref in unique_refs[:20]:
    idx = s.find(f'C[9][{ref}]')
    ctx = s[max(0,idx-50):idx+80]
    clean = ''.join(c if c.isprintable() else ' ' for c in ctx)
    print(f"  C[9][{ref}] → {clean}")

Phase 5: Exported Function Tracing (1-2 hours)

Exported functions (such as getToken) are located via the following path:

1. Find the AWSCInner.register() or similar registration call
2. Identify the registered module and factory function
3. Find the object returned by the factory → exported function definition location
4. If the function name is not in the JS → it is stored as bytecode in the C[9] constant table
5. Trace the call chain:
   AWSCInner._modules['fy'].getToken()
   → W(C[function_index], null, ...)
   → DG() interpreter executes the encoded instruction sequence

Phase 6: Runtime Injection (if pure static analysis is insufficient)

// Inject a minimal AWSC-compatible environment
const fakeEnv = {
    AWSCInner: {
        _modules: {},
        register(name, moduleName, factory) {
            this._modules[moduleName] = factory();
        }
    }
};

// Execute the DSL VM code
dslVmCode();

// Obtain the export
const token = fakeEnv.AWSCInner._modules['fy'].getToken({});

4. Opcode Extraction and Classification

Reference Opcode Mapping Table (based on prior cases)

OpcodeOperation typeCharacteristics
0BRANCHd[7]=xxx unconditional jump
1CALLW(C[Y],null,function(){...}) embedded function call
2ARITHd[4]=0, d[7]=72 variable assignment
3ARITHd[0]=d[1][C[x]], d[5]=d[0]<d[3] comparison operations
4STOREd[8]=d[5]in d[4] property access/existence check
5ARITHd[8]=d[4]-d[8] arithmetic operations
6RETURNreturn gV, throw return/throw exception
7ALLOCd[6]=[], d[6][C[8]](...) push operation
8BRANCHd[7]=d[k]?512:425 conditional jump
9STRINGd[6][C[t]]=d[m], new fh(...) regex
10ALLOCFunction argument preparation, call-stack creation
11STRINGnew fh("\\s",d[5]) regex matching
12STOREP[d[9]]=d[4][C[H]](d[3]) data passing
13CALLC[9][113]=d[9] module initialization
14STRINGd[8]=d[9]+d[m] string concatenation
15RETURNreturn EL; function return
16ALLOCvar r,P,Z,B... local variable declarations
17ALLOC(Z=[])[C[8]](69,T,445) static array initialization
18TABLEFunction table/type table initialization
19EXCEPTIONtry{for(var RK=x;... try-catch loop
20DOMIs[d[o]] DOM operations
21STORESafely reading global/object properties
22STRINGnew fh(r,v) string/regex handling
23BRANCHtry...catch safe access + conditional jump
24CALLW(C[2],null,8,z,FL) multi-argument function call
25EXCEPTIONtry{...}catch(C){...} exception catch + jump

5. Runtime Capture Approaches

Approach A: Selenium + CDP Native Events (recommended; highest success rate)

from selenium import webdriver

driver = webdriver.Chrome()

# Inject anti-detection
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']});
    """
})

# Dispatch CDP native mouse events
driver.execute_cdp_cmd("Input.dispatchMouseEvent", {
    "type": "mousePressed",
    "x": 549.5, "y": 441.2,
    "button": "left", "buttons": 1,
    "clickCount": 1, "pointerType": "mouse"
})

Approach B: Playwright Headless Browser

const { chromium } = require('playwright');

async function run() {
    const browser = await chromium.launch();
    const page = await browser.newPage();

    // Intercept network requests
    await page.route('**/api/**', async route => {
        await route.continue_();
    });

    await page.goto('https://target-page.com');

    // Wait for DSL VM initialization
    await page.waitForFunction(() => {
        return window.AWSCInner &&
               window.AWSCInner._modules &&
               window.AWSCInner._modules['fy'];
    });

    // Perform actions
    await page.mouse.move(500, 400);
    await page.mouse.down();
    // ... action sequence
    await page.mouse.up();
}

Approach C: Pure Protocol Replay (very low success rate)

Tokens generated by DSL VMs are usually tightly bound to browser context (TLS JA3 fingerprint, IP, cookies, request headers, etc.); once detached from the browser, the server can detect context mismatch. Pure-protocol approaches are not recommended.


6. Common Status Codes

CodeMeaningHandling
0Verification passed ✅Extract sessionId + sig
300Risk-control interceptionBlocked; cannot pass
8778Verification failed, retry requiredRetry the operation
8776Operation too fast, retry requiredAdd delay and retry
69634Generic failureCheck whether parameters are correct

7. Skill Self-Check List

  • Did I complete DSL VM identification (IIFE + single-letter variables + DG() interpreter)?
  • Did I extract the variable mapping table (var X=number)?
  • Did I extract the opcode list and classify it?
  • Did I analyze the reference range of the C[9] constant table?
  • Did I locate the exported-function registration point?
  • When pure static analysis was insufficient, did I try the runtime injection approach?
  • After the task, did I write back to field-journal?
  • Were new tools/new scenarios discovered → update routing.md?

Routing Registration

TypeRoute
Target type: WASM / DSL VM / custom instruction setreverse-engineering/dsl-vm-reverse/SKILL.md
User intent: "DSL VM / risk-control engine reversing"This skill
Toolchain: Playwright / Selenium CDPBrowser injection approaches

Path Crossings

DSL VM reversing path:
  reverse-engineering/dsl-vm-reverse/ → Phase 1-6 workflow
  ↓ If runtime data capture is needed
  browser-automation/ → Playwright/Selenium CDP
  ↓ If API protocol-layer analysis is needed
  js-reverse/ → Observe→Capture→Rebuild

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.