Abstract
Decompilation is a critical process in software reverse engineering, yet existing tools frequently produce code that is syntactically incorrect or functionally broken. This paper introduces DecGPT, a hybrid framework designed to bridge the "recompilability gap" by utilizing Large Language Models (LLMs). DecGPT employs a dual-stage approach: iterative static syntax correction driven by compiler feedback and dynamic logic repair guided by AddressSanitizer (ASAN). Our evaluation demonstrates that DecGPT can elevate the recompilation success rate of IDA-Pro output from 0% to over 75%, significantly outperforming traditional rule-based methods.
Introduction
Decompilation transforms binary executables back into human-readable source code, a vital task for security auditing and legacy system maintenance. However, the compilation process is inherently destructive, discarding metadata such as variable names, types, and high-level structures. Consequently, state-of-the-art decompilers like IDA-Pro and Ghidra often output "C-like" code that fails to recompile due to syntax errors, invalid API calls, or incorrect type inferences. Historically, bridging this gap required intensive manual effort by human experts. DecGPT automates this refinement process, enabling the generation of functional, recompilable source code from lossy binary representations.
Methodology: The DecGPT Framework
DecGPT utilizes a two-step pipeline powered by GPT-3.5 to transform raw decompiler output into valid source code.
1. Static Augmenting (Syntax Correction)
The first stage addresses the "specification errors" that prevent initial compilation. DecGPT enters an iterative loop where the decompiled code is passed to a standard compiler (e.g., GCC). If compilation fails, the resulting error messages are fed back to the LLM. The model then acts as an expert debugger, using the error context to fix syntax and type-inference mistakes. This process repeats until the code successfully compiles or a predefined iteration limit is reached.
2. Dynamic Repairing (Logic Correction)
Successful compilation does not guarantee functional correctness. Decompiled code often contains subtle memory errors, such as buffer overflows or incorrect array indexing. To address these, DecGPT compiles the code with AddressSanitizer (ASAN) enabled and executes it against test cases. If ASAN detects a memory corruption error, the specific diagnostic report is provided to the LLM to guide a surgical repair of the program logic.
To ensure high-quality output and prevent the LLM from taking "shortcuts" (such as deleting problematic code or using excessive type-casting), the authors developed specialized system prompts. These prompts explicitly forbid the use of goto statements and encourage the reduction of intermediate variables to improve code clarity and reliability.
Evaluation and Results
The researchers evaluated DecGPT using 300 test cases from the Code Contest dataset, specifically selecting submissions made after September 2021 to avoid data leakage in the LLM's training set.
Key Performance Metrics
- Recompilation Success: While raw IDA-Pro output had a 0% success rate, DecGPT achieved over 75%.
- Comparison with Rule-Based Systems: DecGPT significantly outperformed DecRule, a state-of-the-art rule-based recompiler, which only achieved an 8% success rate.
- Efficiency: The majority of specification errors—which account for 80% of failures—were resolved within just two rounds of LLM interaction.
Insights
The study revealed that LLMs are far more effective than rigid, rule-based systems at inferring the original intent of broken code. However, the iterative design is critical; an ablation study showed that without the feedback loop (DecGPT Zero), the success rate for complex, long-context code plummeted from 27% to a mere 2%.
Discussion and Limitations
Despite its success, DecGPT faces several challenges. LLMs occasionally exhibit "lazy" behavior, satisfying the compiler through heavy-handed type casting that masks underlying bugs. Furthermore, the performance of the model degrades as code length increases due to the context window limitations of GPT-3.5 (4096 tokens). Future work will focus on fine-tuning specialized models for low-level code and improving the handling of complex C++ Standard Template Library (STL) structures, which remain difficult to decompile cleanly.
Summary updated