Table of Contents
Fetching ...

FidelityGPT: Correcting Decompilation Distortions with Retrieval Augmented Generation

Zhiping Zhou, Xiaohong Li, Ruitao Feng, Yao Zhang, Yuekang Li, Wenbu Feng, Yunqian Wang, Yuqing Li

TL;DR

Decompilation fidelity is limited by loss of symbolic information and long-range dependencies, which hampers interpretation of binary analysis outputs. FidelityGPT introduces a distortion-aware, Retrieval-Augmented Generation framework with a Dynamic Semantic Intensity Retrieval Algorithm and a Variable Dependency Algorithm to detect and correct six distortion types in closed-source binaries. By partitioning long code, grounding predictions with a curated distortion database, and using distortion-aware prompts, FidelityGPT achieves high detection accuracy (≈0.89) and precision (≈0.83), along with strong distortion correction metrics (FR ≈0.94, CFR ≈0.64), outperforming state-of-the-art baselines. The approach offers practical improvements in readability and semantic fidelity for reverse engineering workflows, with demonstrated robustness across compilers, decompilers, and LLM backends, and an accessible artifact for reproducibility.

Abstract

Decompilation converts machine code into human-readable form, enabling analysis and debugging without source code. However, fidelity issues often degrade the readability and semantic accuracy of decompiled output. Existing methods, such as variable renaming or structural simplification, provide partial improvements but lack robust detection and correction, particularly for complex closed-source binaries. We present FidelityGPT, a framework that enhances decompiled code accuracy and readability by systematically detecting and correcting semantic distortions. FidelityGPT introduces distortion-aware prompt templates tailored to closed-source settings and integrates Retrieval-Augmented Generation (RAG) with a dynamic semantic intensity algorithm to locate distorted lines and retrieve semantically similar code from a database. A variable dependency algorithm further mitigates long-context limitations by analyzing redundant variables and integrating their dependencies into the prompt context. Evaluated on 620 function pairs from a binary similarity benchmark, FidelityGPT achieved an average detection accuracy of 89% and a precision of 83%. Compared to the state-of-the-art DeGPT (Fix Rate 83%, Corrected Fix Rate 37%), FidelityGPT attained 94% FR and 64% CFR, demonstrating significant gains in accuracy and readability. These results highlight its potential to advance LLM-based decompilation and reverse engineering.

FidelityGPT: Correcting Decompilation Distortions with Retrieval Augmented Generation

TL;DR

Decompilation fidelity is limited by loss of symbolic information and long-range dependencies, which hampers interpretation of binary analysis outputs. FidelityGPT introduces a distortion-aware, Retrieval-Augmented Generation framework with a Dynamic Semantic Intensity Retrieval Algorithm and a Variable Dependency Algorithm to detect and correct six distortion types in closed-source binaries. By partitioning long code, grounding predictions with a curated distortion database, and using distortion-aware prompts, FidelityGPT achieves high detection accuracy (≈0.89) and precision (≈0.83), along with strong distortion correction metrics (FR ≈0.94, CFR ≈0.64), outperforming state-of-the-art baselines. The approach offers practical improvements in readability and semantic fidelity for reverse engineering workflows, with demonstrated robustness across compilers, decompilers, and LLM backends, and an accessible artifact for reproducibility.

Abstract

Decompilation converts machine code into human-readable form, enabling analysis and debugging without source code. However, fidelity issues often degrade the readability and semantic accuracy of decompiled output. Existing methods, such as variable renaming or structural simplification, provide partial improvements but lack robust detection and correction, particularly for complex closed-source binaries. We present FidelityGPT, a framework that enhances decompiled code accuracy and readability by systematically detecting and correcting semantic distortions. FidelityGPT introduces distortion-aware prompt templates tailored to closed-source settings and integrates Retrieval-Augmented Generation (RAG) with a dynamic semantic intensity algorithm to locate distorted lines and retrieve semantically similar code from a database. A variable dependency algorithm further mitigates long-context limitations by analyzing redundant variables and integrating their dependencies into the prompt context. Evaluated on 620 function pairs from a binary similarity benchmark, FidelityGPT achieved an average detection accuracy of 89% and a precision of 83%. Compared to the state-of-the-art DeGPT (Fix Rate 83%, Corrected Fix Rate 37%), FidelityGPT attained 94% FR and 64% CFR, demonstrating significant gains in accuracy and readability. These results highlight its potential to advance LLM-based decompilation and reverse engineering.
Paper Structure (64 sections, 2 equations, 9 figures, 11 tables, 2 algorithms)

This paper contains 64 sections, 2 equations, 9 figures, 11 tables, 2 algorithms.

Figures (9)

  • Figure 1: Case Study of Decompilation Fidelity Issues and Comparison of FidelityGPT with DeGPT
  • Figure 2: Long-Range Variable Dependencies in Decompiled Code
  • Figure 3: Workflow of FidelityGPT
  • Figure 4: Prompt Templates
  • Figure 5: The value of f across different decompiled function line ranges
  • ...and 4 more figures