decompileHow to REA Native Binaries: Mach-O, PE & ELF with Hopper and Ghidra
Decompile compiled machine instructions across Apple Silicon (ARM64), Intel (x86_64), and MIPS into structured C pseudocode: extract function dossiers, traverse cross-references (xrefs), and synthesize verified clean-room algorithms.
In this official REA guide for Native Binaries (Mach-O, PE, ELF), AI coding agents (Claude Code, Cursor, Windsurf) execute 'rea decompile ./binary 0x1000 --provider hopper --json' to safely extract file layout, symbols, and code logic without launching unverified binaries.
The Problem & Target Artifact
Algorithm recovery and protocol reverse engineering: A classic game or closed-source system binary contains a complex proprietary calculation. You need to decompile the assembly into standalone, readable C that can be tested and verified against original inputs.
Natural Language Agent Instructions
Copy and paste this prompt directly into your AI coding agent when REA is registered via Model Context Protocol (MCP):
Decompile the function at 0x00401a20 in ./dxball.exe using Hopper. Explain the mathematical logic in plain English, and generate a standalone C function that reproduces the behavior.Run REA Analysis Command
Execute the following command in your terminal or inspect the MCP JSON-RPC call executed by your agent:
rea decompile ./binary 0x1000 --provider hopper --jsonWhat REA Extracts & Returns
Reconstructed Verified C Function (DX-Ball Sound Pan)
The verified findings and synthesized clean-room structures generated from this investigation:
// Standalone C reconstruction passing 3,205 x86 test cases
int calculate_sound_pan(int ball_x_coord, int screen_width) {
if (screen_width <= 0) return 0;
int normalized = (ball_x_coord * 20000) / screen_width - 10000;
if (normalized < -10000) normalized = -10000;
if (normalized > 10000) normalized = 10000;
return normalized;
}Headless Unix Domain Sockets & Sleigh P-Code Pipelines
REA communicates with Hopper via an embedded Python bridge over a low-latency Unix domain socket (~/.rea/hopper_bridge.sock), returning function dossiers in single-digit milliseconds. For Ghidra, REA invokes analyzeHeadless with ReaGhidraBridge.java, binding directly to FlatProgramAPI and DecompInterface with strict timeout and garbage-collection controls.