Practical Source Code Recovery from Binary Functions Using Anchor-Based Retrieval and LLM Reasoning

Charles Edward Gagnon, Steven H. H. Ding, Philippe Charland, Benjamin C. M. FungarXiv 2026

TL;DR

Instead of trying to guess what source code looked like via traditional decompilation, this paper introduces a pipeline that retrieves the actual original source code from a database. By combining anchor-based search (strings, constants) with LLM-powered semantic re-ranking, the approach maps stripped binary functions back to their exact source code, achieving up to 95.2% instruction coverage in a curated environment.

What Problem Does This Paper Address?

Reverse engineering stripped, optimized binaries is a massive bottleneck in cybersecurity. When analyzing malware, firmware, or proprietary software, analysts rely on decompilers to turn assembly language back into human-readable pseudocode. However, compilers are fundamentally irreversible; they strip away variable names, comments, structure definitions, and code organization.

Since modern software relies heavily on open-source components, the authors ask a clever question: Why try to synthesize approximate code when the exact original source code might already exist on the internet? The challenge lies in accurately matching a stripped, optimized binary function to its corresponding source code snippet within a massive, noisy database without relying on debug symbols.

Methods

The authors propose a multi-stage binary-to-source retrieval pipeline:

  1. Feature Extraction: Using Ghidra, the system extracts two types of features from the binary function:
  2. Anchors: Highly specific, lightweight identifiers used for initial database queries (e.g., string literals, numeric constants, external function calls like memcpy).
  3. Dense Features: Richer, more verbose descriptions reserved for final verification (disassembled instructions, decompiled pseudocode, and metadata).
  4. Source Code Retrieval: The extracted anchors are used to query an inverted-index database (or a public API like GitHub) to pull a set of candidate source files.
  5. Candidate Localization: To handle compiler optimizations like function inlining and preprocessor macros, a custom preprocessor analyzes the candidate files to isolate specific function snippets rather than returning entire files.
  6. Function Similarity Reasoning: A Large Language Model (such as GPT-5.5 or GPT-5 mini) acts as the ultimate judge. It reviews the dense binary features alongside the candidate source snippets, re-ranks them, and outputs a match report complete with an explicit textual rationale for its decision.
  7. Iterative Propagation: Once a function is identified with high confidence, its recovered name is fed back into the binary's call graph, acting as a new anchor to help identify neighboring functions in subsequent passes.
Fig. 1. Overview of our method. An unknown function is first disassembled and its features are extracted. The anchors are used to perform the initial database query. The disassembled code, along with information-dense features, is used to re-order the top-k candidates. In our experiments, k is set to 12.

Datasets

The approach was evaluated using two distinct database setups:

  • Curated Database: A high-fidelity, private database containing source files from 8,061 open-source projects. This was used to evaluate a stripped, O2-optimized tcpdump binary.
  • Public GitHub API: A large, noisy, real-world search index used to evaluate four ubiquitous open-source utilities: BusyBox, curl, sqlite3, and dropbear (all compiled for Linux x86_64 with O2 optimization).

Key Insights and Ideas

  • Retrieval over Generation: Traditional LLM-based decompilers try to generate code from scratch, which is non-deterministic and difficult to verify. Turning this into a retrieval and verification problem leverages the LLM's strengths in semantic comparison rather than code generation.
  • The Call-Graph Force Multiplier: Functions that perform purely mathematical operations often contain zero anchors (no strings or external calls). However, by iteratively propagating names from successfully matched neighbor functions, the pipeline can crack these "anchor-sparse" functions purely through context.
  • The Retrieval Bottleneck: The LLM is exceptionally good at matching code if the correct file is in the candidate pool. In real-world scenarios, the primary failure mode isn't bad LLM reasoning; it's the initial search engine failing to find the file due to code duplication (like repository forks) and noise.

Key Results

  • Curated Environment: When tested against the curated database on tcpdump, the pipeline achieved an impressive 95.2% assembly instruction coverage and a Hit@1 rate of 85.64%. For queries that contained at least one anchor, the correct match was found in the top 3 candidates 100% of the time.
  • Real-World Environment: Testing against the public GitHub API yielded a lower average Hit@1 of 28.3% and 35.5% instruction coverage, heavily impacted by a 53.1% database miss rate.
  • LLM Impact: However, when the correct file was successfully retrieved by the search engine, the LLM re-ranker boosted the Hit@1 rate from 18.2% (baseline) to 59.0%, proving that LLM reasoning significantly improves matching accuracy in noisy environments.
Table 1. Evaluation metrics of our experiment on the tcpdump binary with a curated database.

Limitations and Future Work

The system's biggest limitation is its dependency on the backing database; it cannot recover entirely novel code (such as custom malware), though it can still identify reused open-source libraries within them.

Additionally, the pipeline struggles with structural ambiguity. For example, simple accessor functions (like a get_name() function vs. a get_email() function) produce nearly identical decompiled code, differing only by a structure offset, which can occasionally trick the LLM.

Future work will focus on expanding and deduplicating source code databases, improving initial retrieval queries, and incorporating deeper program analysis signals to reduce false positives.

Summary updated

BibTeX
@misc{gagnon2026practical,
  author = {Charles Edward Gagnon and Steven H. H. Ding and Philippe Charland and Benjamin C. M. Fung},
  title = {{Practical Source Code Recovery from Binary Functions Using Anchor-Based Retrieval and LLM Reasoning}},
  year = {2026},
  eprint = {2607.09452},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2607.09452},
}
Figure