Linux & KernelEnvironment: Hopper Disassembler (macOS/Linux) or NSA Ghidra (All platforms)MCP Tool: decompile

How 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.

AI Overview Direct AnswerHow to REA: Native Binaries (Mach-O, PE, ELF) Quickstart Summary

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.

Investigation ScenarioReal-World Objective

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.

Target Artifact: Mach-O (macOS/iOS), PE (.exe / .dll on Windows), or ELF (Linux).
AI PromptClaude Code / Cursor / Windsurf

Natural Language Agent Instructions

Copy and paste this prompt directly into your AI coding agent when REA is registered via Model Context Protocol (MCP):

Prompt Template:Select All to Copy
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.
ExecutionTerminal & MCP Tool Call

Run REA Analysis Command

Execute the following command in your terminal or inspect the MCP JSON-RPC call executed by your agent:

CLI Command Execution
rea decompile ./binary 0x1000 --provider hopper --json

What REA Extracts & Returns

Function dossier: caller/callee cross-references (xrefs), stack frame layout, and local variables
Assembly instruction sequence with mnemonic decoding and register operand tracking
High-level pseudocode generation with control-flow graph (CFG) structuring
Semantic reduction from 300MB raw disassembly down to 10KB dense Evidence slices

Reconstructed Verified C Function (DX-Ball Sound Pan)

The verified findings and synthesized clean-room structures generated from this investigation:

Reconstructed Verified C Function (DX-Ball Sound Pan)
// 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;
}
Internal MechanicsProduction Engineering

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.

Security Guardrails & Analysis Boundary Rules

No manual GUI clicking: AI coding agents make automated stdio JSON-RPC tool calls on demand.
Avoids context window explosion by returning compact summaries instead of full binary dumps.
Verified against Apple Silicon ARM64, Intel x86_64, and 16-bit real-mode architectures.