emu-mcp
Emula funciones nativas de forma segura y valida hipótesis de ingeniería inversa mediante un servidor MCP stdio.
Documentación
emu-mcp
emu-mcp is a Model Context Protocol (MCP) server for checking reverse-engineering hypotheses by emulating one function at a time with Unicorn. Load an ELF, PE, or Mach-O binary, provide known arguments and memory, and inspect the return value, registers, execution trace, or memory changes.
The server is intentionally an emulator rather than a full process runtime: it does not emulate syscalls, filesystem access, or network access. Calls to unmapped or otherwise unsupported code stop execution and report the address.
Turkish / Türkçe: emu-mcp, reverse-engineering tahminlerini doğrulamak için Unicorn ile tek tek fonksiyonları emulate eden bir MCP sunucusudur. Syscall, dosya sistemi veya ağ emüle edilmez; bilinmeyen çağrılar durdurulur ve adresi raporlanır.
What it supports
- Binary formats: ELF, PE, and Mach-O, parsed with LIEF.
- Architectures: x86, x64, ARM, and ARM64.
- Calling conventions: cdecl (x86), System V AMD64 (ELF/Mach-O x64), Microsoft x64 (PE x64), AAPCS (ARM), and AAPCS64 (ARM64). The convention is selected from the loaded binary and returned as
abibyemu_load. - Inputs and inspection: pre-write memory inputs, persistent memory reads and writes, register results, and paginated code/memory-access traces.
- Stubs: fixed-return hooks for libc/API calls that are not emulated.
- Floating point: floating-point arguments and return values through the supported SIMD/XMM registers.
- Bounded execution: instruction-count and wall-clock limits are validated for every emulation call.
Install
emu-mcp is currently distributed from GitHub and is not published on PyPI. Python 3.10 or newer is required.
Install a tagged release
python -m pip install "emu-mcp @ git+https://github.com/RivaExits0/emu-mcp.git@v0.1.1"
Install from a checkout
git clone https://github.com/RivaExits0/emu-mcp.git
cd emu-mcp
python -m pip install -e .
For the test suite, install the development extra:
python -m pip install -e ".[dev]"
On Linux, the binary-building tests and demo use x86_64-linux-gnu-gcc and binutils. The CI job also installs i686, ARM, and AArch64 cross-compilers so the ABI tests can exercise those targets. Windows does not require cross-compilation for its test run.
Run the MCP server
The packaged console entrypoint is:
emu-mcp
The equivalent module invocation is:
python -m emu_mcp.server
The server uses MCP stdio transport. It is intended to be started by an MCP client; it does not expose an HTTP or SSE transport.
Client configuration
Claude Desktop
Add the following to claude_desktop_config.json after installing emu-mcp into an environment on the client’s PATH:
{
"mcpServers": {
"emu-mcp": {
"command": "emu-mcp",
"args": [],
"env": {}
}
}
}
On Windows, use the full path to the executable if it is not on PATH, for example:
{
"mcpServers": {
"emu-mcp": {
"command": "C:\\path\\to\\.venv\\Scripts\\emu-mcp.exe",
"args": [],
"env": {}
}
}
}
OpenCode
Add the following to opencode.json:
{
"mcp": {
"emu": {
"type": "local",
"command": ["emu-mcp"],
"enabled": true
}
}
}
MCP tools
Call emu_load first. A successful load resets the previous session and maps the binary’s loadable segments. Use emu_reset between unrelated analyses.
| Tool | Purpose |
|---|---|
emu_load(path, arch=None) | Parse an ELF, PE, or Mach-O binary with LIEF, map its segments, and report format, architecture, ABI, segment count, and symbol count. Architecture is auto-detected unless arch is supplied (x86, x64, arm, or arm64). |
emu_run(func_addr, args=[], mem_inputs={}, max_insns=100000, timeout_ms=5000) | Emulate one function and return return_value, all captured registers, instruction_count, and stop_reason. mem_inputs maps hexadecimal or decimal addresses to hexadecimal bytes. |
emu_trace(func_addr, args=[], mem_inputs={}, limit=50, offset=0, max_insns=100000, timeout_ms=5000) | Emulate a function and return the stop reason, executed addresses, and memory read/write counts with a paginated address list. |
emu_read_mem(addr, length, fmt="hex") | Read up to 4096 bytes from emulated memory as lowercase hex or ASCII (fmt is hex or ascii). |
emu_write_mem(addr, data_hex) | Write hexadecimal bytes to emulated memory. The write remains available in the current session and returns the number of bytes written. |
emu_hook_call(addr, return_value, name=None) | Stub a call at addr, skip its body, and return a fixed value. A float return value is placed in the supported floating-point return register. |
emu_reset() | Unload the binary and clear memory, registers, hooks, and session state. Returns reset ok. |
Tool results are text: successful structured results from emu_load, emu_run, and emu_hook_call are JSON strings; errors are returned with an error: prefix.
Minimal tool sequence
The following illustrates the intended order. Function addresses must belong to the loaded binary; obtain them from the binary’s symbols or another analysis tool.
{"tool":"emu_load","args":{"path":"tests/sample_x64"}}
{"tool":"emu_run","args":{"func_addr":"0x4011d0","args":[5,7]}}
{"tool":"emu_trace","args":{"func_addr":"0x4011d0","args":[5,7],"limit":50,"offset":0}}
A typical emu_run result is JSON in the tool’s text payload:
{
"return_value": 12,
"stop_reason": "returned",
"instruction_count": 11,
"registers": {"rax": 12, "rip": "0x4011db"}
}
Limits and safety boundaries
Every tool call is bounded or size-limited as follows:
| Input | Accepted range or default |
|---|---|
max_insns | 1..10,000,000; default 100,000 |
timeout_ms | 1..60,000; default 5,000 |
args | At most 64 values |
emu_trace.limit | 1..10,000; default 50 |
emu_trace.offset | 0 or greater; default 0 |
emu_read_mem.length | 0..4,096 |
emu_write_mem data | At most 65,536 bytes |
mem_inputs total | At most 1 MiB |
The emulator maps binary segments and session memory into Unicorn; it does not provide the loaded code with host syscalls, host filesystem access, or host network access. Unknown or unmapped calls do not become real library calls: execution stops and reports the failure address. These boundaries are not a substitute for a separate security sandbox when analyzing untrusted binaries or inputs.
Important limitations:
- This is single-function emulation, not complete operating-system or process emulation.
- External dependencies must be represented with
emu_hook_call; no real libc/API implementation is loaded automatically. - Floating-point support is limited to the implemented SIMD/XMM argument and return-register paths.
- x86 uses cdecl; stdcall and fastcall are not selected automatically.
- A loaded session is process-local.
emu_resetclears it, and a newemu_loadstarts from a clean session.
Development and testing
Install development dependencies and build the Linux fixtures:
python -m pip install -e ".[dev]"
make all
Run the complete Python test suite:
pytest -q
# or
make test
make test builds the default fixtures, runs python3 -m pytest -q, and then runs python3 tests/test_hard.py explicitly. The test suite covers MCP-over-stdio registration and results, session reset behavior, limits, ELF emulation, recursion, indirect calls, stack arguments, structs by pointer, nested calls, memory modification, libc hooks, floating-point registers, and error handling.
Run the end-to-end demo:
make demo
# or
python examples/demo.py
The CI checks can be run locally with the corresponding optional tools:
python -m pip install -e ".[lint]"
ruff check src tests
mypy src/emu_mcp
Project layout
src/emu_mcp/
├── server.py MCP tool definitions and stdio entrypoint
├── emulator.py Unicorn engine, calling conventions, hooks, and tracing
├── loader.py LIEF parsing and segment mapping
└── platform_utils.py Cross-platform paths, subprocesses, and file I/O helpers
License
MIT — see LICENSE.