Implementation:0sec labs 0 Decompile Backends
| Knowledge Sources | |
|---|---|
| Domains | Binary_Analysis, Decompilation |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Wrapper for external decompiler backends (Ghidra, rizin, angr) that lifts compiled binaries into an intermediate representation for static analysis.
Description
The contract.analyze function is the 0verse decompiler backend interface. It dispatches to one of three backends — Ghidra (primary, via pyghidra/jpype1), rizin (free alternative via r2ghidra), or angr (lazy import, optional) — to produce an ILAdapter. The adapter exposes decompiled C code (meta.decompiled_c), an instruction list, a call graph, and recovered sink addresses. This is a Wrapper Doc: the actual decompilation is performed by external tools; 0verse provides the unified Protocol interface and pipeline wiring.
Usage
Use this when you need to decompile a binary for static analysis. The backend is selected via the backend parameter or the ZEROVERSE_BACKEND environment variable (auto selects the first available, preferring Ghidra).
Code Reference
Source Location
- Repository: 0security
- File: 0verse/src/zeroverse/backends/contract.py, 0verse/src/zeroverse/pipeline.py:L578-1060
Signature
class DecompilerContract:
def analyze(
self,
path: str | Path,
*,
name: str = "auto", # ghidra | rizin | angr | auto
timeout: int = 120, # seconds; env ZEROVERSE_BACKEND_TIMEOUT
) -> ILAdapter | None: ...
class ILAdapter(Protocol):
meta: DecompilationMeta # decompiled_c: dict[str, str], callgraph, etc.
def all_insts(self) -> list[Inst]: ...
Import
from zeroverse.backends.contract import DecompilerContract
from zeroverse.pipeline import run # scan() calls decompile internally
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| path | Path | Yes | Binary file path to decompile |
| name | str | No | Backend name: ghidra, rizin, angr, or auto (default auto) |
| timeout | int | No | Decompiler timeout in seconds (default 120) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | None | Adapter with decompiled C, instruction list, call graph; None on backend failure |
Usage Examples
Via the scan API (automatic backend selection)
from zeroverse.api import scan, ScanOptions
# scan() handles decompilation internally via the contract
result = scan("/usr/bin/vulnerable", opts=ScanOptions(backend="ghidra"))
for f in result.findings:
print(f"{f.bug_class}: {f.function} (confirmed={f.confirmed})")
Explicit backend selection
import os
os.environ["GHIDRA_INSTALL_DIR"] = "/opt/ghidra"
os.environ["ZEROVERSE_BACKEND"] = "ghidra"
from zeroverse.api import scan
result = scan("./target_binary")