DeGPT: Optimizing Decompiler Output with LLM

Peiwei Hu, Ruigang Liang, Kai Chen2024

Abstract

Reverse engineering is a cornerstone of cybersecurity, yet the output of modern decompilers often lacks the readability necessary for efficient analysis. Decompiled code frequently suffers from meaningless variable names, redundant logic, and a total absence of developer comments. While previous machine learning approaches required massive, domain-specific datasets, they often failed to generalize across different software types. We introduce DeGPT, an end-to-end framework that utilizes Large Language Models (LLMs) to refine decompiler output. By implementing a novel "three-role" mechanism—comprising a Referee, an Advisor, and an Operator—DeGPT optimizes code readability while ensuring semantic correctness through Micro Snippet Semantic Calculation (MSSC). Our evaluation demonstrates that DeGPT reduces the cognitive burden of understanding decompiled code by 24.4% and significantly outperforms existing state-of-the-art tools in variable renaming and semantic clarity.

Introduction

In the realms of malware analysis and vulnerability discovery, reverse engineers rely heavily on decompilers like Ghidra or Hex-Rays to translate binary assembly into high-level C code. However, the resulting "lifted" code is often difficult to parse. Stripped binaries lose all original variable names and comments, and the decompiler's logic can be unnecessarily convoluted. Previous attempts to automate the cleanup of this code relied on supervised learning with large datasets, which struggle with "binary migration"—the performance drop seen when a model encounters software types it wasn't trained on.

The DeGPT Framework

DeGPT addresses these challenges by leveraging the general-purpose reasoning of LLMs. To prevent the common pitfalls of LLMs, such as "hallucinations" or logical errors, DeGPT employs a structured three-role pipeline that breaks the optimization task into manageable, verifiable steps.

The high-level workflow of DeGPT, illustrating the transition from raw binary to optimized, human-readable output via the three-role LLM process.

The Three-Role Mechanism

  1. Referee (R_ref): This component acts as the initial filter. It queries the LLM to determine which specific optimizations (renaming, commenting, or structural simplification) are actually required for a given code snippet. This targeted approach reduces API costs and minimizes unnecessary alterations.
  2. Advisor (R_adv): Once the optimization plan is set, the Advisor generates the actual edits. It uses specialized prompts to provide descriptive comments and meaningful variable names based on the code's inferred logic.
  3. Operator (R_ope): To ensure the optimized code remains functionally identical to the original, the Operator performs semantic verification.
A detailed view of the three-role mechanism: the Referee plans, the Advisor executes, and the Operator verifies semantic integrity using MSSC.

A critical innovation in the Operator role is Micro Snippet Semantic Calculation (MSSC). MSSC uses a lightweight symbolic execution method to verify that the optimized code produces the same outputs as the original for the same inputs. If a change alters the program's behavior, the Operator rejects it, providing a vital safety net against LLM errors.

Evaluation and Results

DeGPT was tested against a diverse set of 620 functions, including real-world malware (Mirai), Linux utilities (Coreutils), and modern audio libraries (AudioFlux). The results were significant:

  • Cognitive Burden: Using Halstead’s Effort metric, DeGPT achieved a 24.4% reduction in the effort required to understand the code.
  • Naming Accuracy: DeGPT correctly recovered 30.3% of original variable names, nearly tripling the 11.1% accuracy of the previous state-of-the-art tool, DIRTY.
  • Human Performance: In user studies, participants using DeGPT-optimized code were 126% more accurate and 47% faster at identifying a function's purpose compared to those using raw Ghidra output.
  • Semantic Utility: 62.9% of the comments generated by DeGPT provided practical, accurate semantic information that directly aided reverse engineers.

Conclusion

DeGPT demonstrates that LLMs, when constrained by a multi-role verification framework, can dramatically improve the utility of decompiled code. By moving beyond one-shot prompting and incorporating semantic guardrails like MSSC, DeGPT provides a robust tool for the reverse engineering community. Future work will focus on expanding the context window to include inter-procedural analysis, allowing the model to understand how functions interact across an entire binary codebase.

Summary updated

BibTeX
@misc{hu2024degpt,
  author = {Peiwei Hu and Ruigang Liang and Kai Chen},
  title = {{DeGPT: Optimizing Decompiler Output with LLM}},
  year = {2024},
  doi = {10.14722/ndss.2024.24401},
}
Figure