DEV Community

Sandeep Kumar
Sandeep Kumar

Posted on

Stopping LLM Hallucinations in Reverse Engineering: Meet Reverify

Large Language Models (LLMs) are changing how we write, debug, and understand code. But when you throw an LLM at compiled binaries, things get messy quickly.

If you’ve ever tried to use an AI agent to analyze malware, reverse-engineer a proprietary protocol, or solve a CTF challenge, you have likely run into the hallucination barrier. An agent will confidently assert that a specific function starts at 0x401120, uses an RC4 decryption routine, and reads a struct with a 16-byte offset. You open the binary in Ghidra or IDA Pro, check the address, and realize... none of that exists. The LLM simply hallucinated a plausible-looking structure because it fit the probabilistic pattern of its training data.

Binary analysis is an unforgiving domain. A single incorrect byte, mismatched register, or offset shift of 4 bytes breaks everything. In reverse engineering, close enough is not good enough.

This is where Reverify comes in.

Reverify is an advanced, deterministic verification loop designed to ground AI reverse-engineering agents in actual binary bytes. It acts as an automated judge that forces LLMs to prove their hypotheses using binary parsing, disassembly, pattern matching, and CPU emulation.


The Problem: Why LLMs Fail at Binary Analysis

LLMs are probabilistic engines designed to predict the next token. They are excellent at understanding semantic patterns but struggle with exact physical structures and arithmetic calculations. When analyzing a binary, an AI agent faces several distinct challenges:

  1. Spatial and Structural Hallucinations: AI agents routinely guess struct offsets, assembly layouts, and function boundaries based on naming conventions or contextual clues rather than physical reality.
  2. Execution Blindness: Static analysis alone is rarely enough. An LLM cannot execute a code path in its head to verify if a decryption loop actually produces a specific key.
  3. Lack of Ground-Truth Feedback: When an agent acts autonomously, it lacks a tight feedback loop. If it makes an incorrect assumption early in its chain of thought, every subsequent conclusion is compromised.

To make autonomous reverse-engineering agents viable, we must transition them from a "guess-and-check" methodology to a formal hypothesis-and-verification loop.


What is Reverify?

Reverify bridges the gap between probabilistic LLMs and deterministic execution engines. It provides a structured verification layer that tests LLM assertions against reality.

Instead of allowing an AI agent to simply state:

"The function at 0x1000 is a custom XOR decryption routine."

Reverify forces the agent to interact with a verification framework that asks:

"Prove it. Provide the disassembly, trace the register states, emulate the execution using Unicorn, and show that the output bytes at target memory locations match your claim."

The Tech Stack

Reverify leverages a powerhouse stack of binary analysis and dynamic instrumentation tools:

  • LIEF: For structural parsing of executable formats (ELF, PE, Mach-O).
  • Capstone Engine: For multi-architecture instruction disassembly.
  • Unicorn Engine: For lightweight CPU emulation, allowing register and memory tracing without running the full binary on the host system.
  • Frida: For dynamic instrumentation and hooking during live process execution.
  • Model Context Protocol (MCP): To expose these validation tools natively to LLM agents (like Claude or GPT-based agents) as structured tools.

Under the Hood: Key Components

Let's dive into some of the core components of the Reverify codebase to see how it enforces this deterministic verification loop.

1. Orchestration and Tool Exposure: reverify/cli.py

The command-line interface (reverify/cli.py) serves as the entry point for both human analysts and automated agents. It exposes commands that allow agents to query, parse, disassemble, and run emulation checks.

Rather than just outputting raw text, the CLI outputs structured JSON that agents can parse directly to adjust their internal state. This structured feedback loop is critical for correcting the agent's path before it goes off the rails.

2. Validating Assumptions: benchmarks/prologue_prior.py

A classic hallucination point for LLM agents is identifying function entry points. When analyzing stripped binaries, agents often guess where functions start based on compiler-specific patterns (like push rbp; mov rbp, rsp).

The benchmark and analysis script benchmarks/prologue_prior.py validates whether function prologues actually exist at the addresses proposed by the model.

# Simplified concept of prologue verification in Reverify
def verify_function_prologue(binary_bytes, offset, architecture="x64"):
    # Read the bytes at the claimed offset
    prologue_bytes = binary_bytes[offset:offset+4]

    # Define known valid prologues for validation
    valid_prologues = {
        "x64": [
            b"\x55\x48\x89\xe5",  # push rbp; mov rbp, rsp
            b"\x48\x83\xec",      # sub rsp, imm
        ],
        "x86": [
            b"\x55\x89\xe5",      # push ebp; mov ebp, esp
        ]
    }

    # Force the agent to ground its claim in actual byte sequences
    if any(prologue_bytes.startswith(p) for p in valid_prologues.get(architecture, [])):
        return True, "Valid prologue found."
    return False, f"Invalid prologue at offset {hex(offset)}. Found bytes: {prologue_bytes.hex()}"
Enter fullscreen mode Exit fullscreen mode

If an agent proposes a function boundary, Reverify executes a check like this. If the check fails, the agent receives an immediate, actionable error message: “Failed: Bytes at 0x401050 do not match standard function prologues. Found 0x00000000 instead.” The agent is then forced to revise its hypothesis.


The Verification Loop in Action

How does this look in practice? Imagine an autonomous agent analyzing a piece of malware containing an obfuscated string.

       +---------------------------------------------+
       |             AI RE Agent (LLM)               |
       |  "I think 0x4012A0 decrypts the payload"    |
       +----------------------+----------------------+
                              |
                     Hypothesis & Proof Request
                              v
       +---------------------------------------------+
       |             Reverify Engine                 |
       |  1. Disassemble 0x4012A0 (Capstone)        |
       |  2. Set up emulation state (Unicorn)        |
       |  3. Run to return instruction               |
       +----------------------+----------------------+
                              |
                     Deterministic Feedback
                              v
       +---------------------------------------------+
       |             AI RE Agent (LLM)               |
       |  "Ah, the register EDX held the key.        |
       |   The decrypted string is 'flag{u_got_me}'"  |
       +---------------------------------------------+
Enter fullscreen mode Exit fullscreen mode
  1. The Hypothesis: The agent theorizes that calling the function at 0x4012A0 with register rdi pointing to a ciphertext buffer will decrypt a payload.
  2. The Verification Setup: The agent invokes Reverify’s emulation tool via MCP. It configures a virtual CPU state:
    • Maps memory at 0x400000 (binary base).
    • Writes the ciphertext to a virtual stack/heap.
    • Sets rdi to the ciphertext address.
    • Sets rip to 0x4012A0.
  3. Execution: Reverify uses Unicorn Engine to emulate execution. It steps through instructions, tracking changes to memory and registers.
  4. Validation: The emulation runs until a ret instruction is hit, or a timeout occurs. Reverify inspects the memory address where the agent expected the decrypted string to appear.
  5. The Verdict: Reverify returns the precise memory state and registers back to the agent. If the memory contains plaintext, the hypothesis is confirmed. If the memory is unchanged or faulted, the agent is given the exact CPU state at the point of failure so it can debug its assumptions.

Key Use Cases

1. Automated Malware Analysis

Malware authors use packer, crypters, and custom obfuscation to defeat static analysis tools. Reverify allows security analysts to build autonomous triage pipelines where AI agents can systematically strip obfuscation layers, run unpacking loops in safe emulated sandboxes, and verify decrypted payloads with absolute confidence.

2. Autonomous CTF Solving

In Capture The Flag (CTF) competitions, speed is key. An AI agent powered by Reverify can quickly parse binary targets, verify function logic, validate vulnerability hypotheses (like buffer overflow offsets), and test exploit payloads locally using emulated environments before throwing them at the remote flag server.

3. Copilot for Human Reverse Engineers

Even when a human is in the loop, Reverify serves as an excellent assistant. You can ask an LLM to analyze a complex function, but have Reverify run behind the scenes to verify every assertion made by the model. This significantly reduces the time analysts spend manually double-checking hallucinated details in Ghidra.


Conclusion

The future of reverse engineering is undeniably collaborative. AI agents have the potential to speed up vulnerability research, malware triage, and binary analysis by orders of magnitude. However, they cannot do it alone. Without strict guardrails, they are prone to confident mistakes that waste analyst time.

By introducing a deterministic validation loop, Reverify turns LLMs from unreliable guess-engines into precise, verified analysis partners.

Are you building AI-powered security agents, or looking to supercharge your binary analysis workflows? Check out Reverify, explore the source code, and start building deterministic validation loops into your security stack today.

Top comments (0)