Environment:2akouwu Reverify Unicorn Engine
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Reverse_Engineering, Verification |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
CPU emulation environment using the Unicorn engine (>= 2.0) for real instruction-level x86/x64 execution in behavioral equivalence testing.
Description
This environment provides the Unicorn CPU emulator, which is required for `behavioral_equiv` — the strongest form of tool-grounded verification that runs original binary code and a candidate over shared inputs and compares outputs. Unicorn emulates every instruction on x86 (32-bit) and x86_64 (64-bit) architectures with correct register conventions (System V and Microsoft x64 calling conventions). Without Unicorn installed, `behavioral_equiv` returns `inconclusive` rather than producing a false verdict.
Usage
Use this environment for behavioral equivalence testing: running a function at a given offset in the binary and a candidate (byte sequence or expression) over the same inputs, comparing return-register values. This is the execution-based metric behind ExeBench / LLM4Decompile re-executability.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Cross-platform | Unicorn is a C library with Python bindings |
| Hardware | Any CPU | Emulation is software-based |
| Disk | Minimal | No disk I/O during emulation |
Dependencies
System Packages
- Python >= 3.8
Python Packages
- `unicorn` >= 2.0 (installed via `pip install "reverify[unicorn]"` or `pip install unicorn>=2.0`)
Credentials
No credentials required.
Quick Install
# Install unicorn engine
pip install "reverify[unicorn]"
# or directly:
pip install unicorn>=2.0
Code Evidence
Engine detection from `backends.py:25-31`:
try:
import unicorn # noqa: F401
HAS_UNICORN = True
UNICORN_VERSION = getattr(unicorn, "__version__", "?")
except Exception: # pragma: no cover
HAS_UNICORN = False
UNICORN_VERSION = None
Fail-closed guard in `behavioral_equiv` from `behavior.py:226-227`:
if not HAS_UNICORN:
return {"status": "inconclusive", "detail": "unicorn not installed", "tested": 0}
Runtime guard in `run_function` from `behavior.py:135-136`:
if not HAS_UNICORN:
raise RuntimeError("unicorn required for behavioral execution")
Architecture support with calling conventions from `behavior.py:81-86`:
_DEFAULT_ARG_REGS = {
"x86_64": ["rdi", "rsi", "rdx", "rcx", "r8", "r9"], # System V
"x86_64_ms": ["rcx", "rdx", "r8", "r9"], # Microsoft x64
"x86": ["edi", "esi", "edx", "ecx"], # 32-bit cdecl
"x86_ms": ["ecx", "edx", "eax", "ebp"], # 32-bit Microsoft
}
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `inconclusive: unicorn not installed` | Unicorn package missing | `pip install "reverify[unicorn]"` |
| `RuntimeError: unicorn required for behavioral execution` | Called `run_function` without Unicorn | Install unicorn or use `behavioral_equiv` (which fails gracefully) |
| `ValueError: arch='x86' is 32-bit but bits=64` | Arch/width mismatch | Pass `bits=32` for 32-bit arch or omit `bits` to auto-derive |
Compatibility Notes
- Architectures: x86 (32-bit) and x86_64 (64-bit) supported. The `bits` parameter must match `arch` — a 64-bit register name written into a 32-bit Unicorn instance is a silent no-op, so mismatches are explicitly rejected.
- Calling conventions: System V (default for x86_64/x86) and Microsoft x64/cdecl supported via `arg_regs` override.
- Without Unicorn: `behavioral_equiv` degrades to `inconclusive` — it never produces a false verdict. Pure-Python expression evaluation (`eval_expr`) still works for expression candidates.