emu-mcp

MCP stdio सर्वर के माध्यम से नेटिव फ़ंक्शनों का सुरक्षित अनुकरण करें और रिवर्स-इंजीनियरिंग परिकल्पनाओं को सत्यापित करें।

दस्तावेज़

emu-mcp

CI Release License: MIT Python 3.10+

emu-mcp is an MCP server that lets an AI verify reverse-engineering guesses by emulating single functions in isolation with Unicorn. No syscalls, filesystem, or network are emulated; unknown calls stop execution and report their address.

Turkish / Türkçe: emu-mcp, Unicorn motoru ile tek bir fonksiyonu izole olarak emulate eden bir MCP sunucusudur. Reverse engineering tahminlerini doğrulamak için kullanılır. Hiçbir syscall, dosya sistemi veya ağ emüle edilmez; bilinmeyen çağrılar durdurulur ve adresi raporlanır.


✨ What's New in v0.1.1

  • 🪟 Microsoft x64 (PE) calling convention: rcx/rdx/r8/r9 + xmm0..xmm3, 32-byte shadow space
  • ⚡ AVX/VEX support: AVX-compiled binaries (GCC 15) now emulate correctly
  • 🛡 Input limits: bounded max_insns, timeout_ms, args, trace pages
  • 🧪 48 tests (Linux + Windows, Python 3.10–3.12)
  • 📋 Lint & type checks (ruff + mypy) in CI

Why

When reverse-engineering a binary, you form hypotheses about what a function does. emu-mcp lets you run that function with known inputs in an isolated emulator and check the result, instead of trusting the guess.

Supported architectures: x86, x64, arm, arm64.


Features

  • Parse ELF / PE / Mach-O binaries with LIEF and auto-detect architecture.
  • Emulate a single function with arguments passed per calling convention: System V AMD64 for ELF/Mach-O x64, Microsoft x64 for PE, cdecl for x86, AAPCS for ARM and AAPCS64 for ARM64.
  • Pre-write memory inputs, read/write memory, stub libc/API calls.
  • Trace executed addresses and memory reads/writes (paginated with limit/offset).
  • Hard limits on instruction count and wall-clock time to prevent runaway emulation.
  • x86/x64 stack alignment (RSP 8 mod 16) and ARM SP alignment.
  • Floating-point (XMM) argument and return-value stub support.
  • Clean, machine-readable JSON output suitable for AI agents.
  • No syscalls, filesystem, or network are emulated.
  • Unknown calls stop execution and report their address.

Install

emu-mcp is distributed from GitHub; it is not published on PyPI.

From GitHub (pinned release)

pip install "emu-mcp @ git+https://github.com/RivaExits0/emu-mcp.git@v0.1.1"

From Source

git clone https://github.com/RivaExits0/emu-mcp.git
cd emu-mcp
pip install -e .[dev]    # or just `pip install -e .` for production

System requirements (Linux): gcc-x86-64-linux-gnu and binutils for building test binaries. On Windows, cross-compilation is not required for the test suite.


Run

emu-mcp
# or
python -m emu_mcp

The server speaks MCP over stdio.


Claude Desktop Integration

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "emu-mcp": {
      "command": "emu-mcp",
      "args": [],
      "env": {}
    }
  }
}

Windows: If installed via pip, emu-mcp should be on PATH. Otherwise use full path: C:\\path\\to\\emu-mcp\\.venv\\Scripts\\emu-mcp.exe.


OpenCode Integration

Add to opencode.json:

{
  "mcp": {
    "emu": {
      "type": "local",
      "command": ["emu-mcp"],
      "enabled": true
    }
  }
}

MCP Tools

ToolDescriptionWhen to call
emu_load(path, arch=None)Parse a binary and map its segments into Unicorn memory.First, before any emulation.
emu_run(func_addr, args=[], mem_inputs={}, max_insns=100000, timeout_ms=5000)Emulate one function, return value + registers.After emu_load.
emu_trace(func_addr, args=[], mem_inputs={}, limit=50, offset=0, max_insns=100000, timeout_ms=5000)Trace addresses and memory access (paginated).After emu_run to see execution flow.
`emu_read_mem(addr, length, fmt="hex""ascii")`Read up to 4096 bytes from emulated memory.
emu_write_mem(addr, data_hex)Write hex data to emulated memory.To set up inputs before emu_run.
emu_hook_call(addr, return_value, name=None)Stub a call (malloc, strlen, …) with a fixed return value.To avoid calling unsupported libc functions.
emu_reset()Reset the emulation session (clear memory, registers, hooks).Between unrelated emulations.

Tool: emu_load

Example call:

{"tool": "emu_load", "args": {"path": "tests/sample_x64", "arch": null}}

Example output:

{
  "format": "elf",
  "arch": "x64",
  "entry": "0x401000",
  "segments": [
    {"vaddr": "0x400000", "memsz": 0x2000, "filesz": 0x1f00, "offset": 0}
  ],
  "base_address": "0x400000"
}

Tool: emu_run

Example call:

{"tool": "emu_run", "args": {"func_addr": "0x4011d0", "args": [5, 7], "max_insns": 100000}}

Example output:

{
  "return_value": 12,
  "stop_reason": "returned",
  "instruction_count": 11,
  "registers": {"rax": 12, "rip": "0x4011db", ...}
}

Tool: emu_trace

Example call:

{"tool": "emu_trace", "args": {"func_addr": "0x4011d0", "args": [5, 7], "limit": 50, "offset": 0}}

Example output:

stop: returned, insns: 11
called addresses:
  0x4011d0
  0x4011d4
  0x4011d5
  0x4011d8

Supported Architectures

ArchitectureCalling ConventionStatus
x86 (32-bit)cdecl✅
x64 ELF / Mach-OSystem V AMD64✅
x64 PE (Windows)Microsoft x64 (rcx/rdx/r8/r9, shadow space)✅
ARM (32-bit)AAPCS✅
ARM64 (AArch64)AAPCS64✅

The convention is selected automatically from the binary format; emu_load reports it in the abi field.


Testing

# Build test binaries (Linux only)
make all

# Run test suite
pytest -q
# or
make test

# Run demo
make demo
# or
python examples/demo.py

Runs tests/test_emu.py, tests/test_hard.py, and examples/demo.py.

The hard suite covers:

  • Recursion (factorial)
  • Function pointers (indirect calls)
  • Stack arguments (many-arg functions)
  • Structs by pointer
  • In-place memory modification
  • Nested calls
  • Libc hooks (strcmp)
  • Floating point (XMM registers)
  • Error cases (unmapped memory, instruction limit)

Demo

make demo

Expected output:

=== Demo 1: add(5, 7) ===
result=12 stop=returned insns=11
...
ALL DEMO CHECKS PASSED

Architecture

src/emu_mcp/
├── server.py      MCP tool definitions (stdio transport)
├── emulator.py    Unicorn engine, calling conventions, hooks, tracing
├── loader.py      LIEF-based binary parsing and segment mapping
└── platform_utils.py  Cross-platform paths, subprocess, file I/O

Pagination (limit / offset)

emu_trace supports limit and offset for long trace lists:

  • limit: maximum number of trace lines to return (default 50, max 10,000)
  • offset: number of trace lines to skip (default 0)

Limits

Every tool call is bounded so a bad input cannot hang the server:

LimitValue
max_insns1 .. 10,000,000 (default 100,000)
timeout_ms1 .. 60,000 (default 5,000)
argsat most 64 values
emu_trace limit1 .. 10,000 (default 50)
emu_read_mem length0 .. 4096
emu_write_mem data1 .. 65,536 bytes
mem_inputs total1 MiB

Security Notes

  • No syscalls, filesystem, or network are emulated.
  • Unknown calls stop execution and report their address.
  • Instruction count (max_insns) and wall-clock timeouts are bounded and validated before execution.
  • Memory is isolated per session; emu_reset clears state.
  • Inputs are validated at the MCP boundary (func_addr, argument count, trace page size); invalid values return error: ... without starting emulation.

Limitations

  • No real syscall emulation; unknown calls stop execution.
  • No filesystem or network access inside the emulator.
  • Floating-point support is limited to XMM/SIMD argument registers.
  • x86 uses cdecl; stdcall/fastcall are not selected automatically.

🔗 Related Projects

  • forge-mcp — Game modding toolkit (hex, PE, APK, Unity, Unreal, tables). Use for hex editing, signature generation, APK repacking.
  • henry-mcp — Static compatibility analysis for EXE/DLL/APK/Kotlin. Use for checking module compatibility.
  • crash-mcp — Crash dump analysis (ELF core + Windows minidump). Use for post-mortem debugging.

📦 Release

  • Latest: v0.1.1
  • Install from release: pip install git+https://github.com/RivaExits0/emu-mcp.git@v0.1.1

Create Release

git tag -a v0.1.1 -m "emu-mcp v0.1.1: Bounded tool inputs"
git push origin v0.1.1

License

MIT — see LICENSE.