FidelityGPT : Correcting Decompilation Distortions with Retrieval Augmented Generation

Zhiping Zhou Xiaohong Li Ruitao Feng Yao ZhangTianjin University Tianjin University Southern Cross University Tianjin [email protected] [email protected] [email protected] [email protected][1em] Yuekang Li Wenbu Feng Yunqian Wang Yuqing LiUniversity of New South Wales Tianjin · 2025

Read FidelityGPT : Correcting Decompilation Distortions with Retrieval Augmented Generation by Zhiping Zhou Xiaohong Li Ruitao Feng Yao ZhangTianjin University Tianjin University Southern Cross University Tianjin [email protected] [email protected] [email protected] [email protected][1em] Yuekang Li Wenbu Feng Yunqian Wang Yuqing LiUniversity of New South Wales Tianjin (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2510-19615.txt.

Introduction

Zhiping Zhou and seven co-authors present FidelityGPT, a system that repairs meaning errors in decompiled code. Decompilers turn machine code back into readable source-like text, but the output often distorts the original logic, especially for closed-source programs. Simple fixes like renaming variables do not catch semantic mistakes.

FidelityGPT pairs language models with retrieval-augmented generation: it detects distorted lines, pulls similar correct code from a database, and uses a variable-dependency analysis to keep long functions manageable. On six hundred twenty function pairs it detected distortions with high accuracy and fixed far more of them correctly than the leading earlier system. The gains matter for reverse engineering and security analysis of binaries without source code.

Catalog record

CREATORZhiping Zhou Xiaohong Li Ruitao Feng Yao ZhangTianjin University Tianjin University Southern Cross University Tianjin [email protected] [email protected] [email protected] [email protected][1em] Yuekang Li Wenbu Feng Yunqian Wang Yuqing LiUniversity of New South Wales Tianjin
YEAR2025
COLLECTIONPAPERS
FORMATTXT
FILE SIZE88 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2510-19615

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

FidelityGPT : Correcting Decompilation Distortions with Retrieval Augmented Generation PubID: pubid: Network and Distributed System Security (NDSS) Symposium 2026 23 - 27 February 2026 , San Diego, CA, USA ISBN 979-8-9919276-8-0 https://dx.doi.org/10.14722/ndss.2026.230989 www.ndss-symposium.org Zhiping Zhou Xiaohong Li Ruitao Feng Yao ZhangTianjin University Tianjin University Southern Cross University Tianjin [email protected] [email protected] [email protected] [email protected][1em] Yuekang Li Wenbu Feng Yunqian Wang Yuqing LiUniversity of New South Wales Tianjin University Tianjin University Tianjin [email protected] [email protected] [email protected] [email protected] Abstract Decompilation is a crucial technique that converts machine code into a human-readable format, facilitating analysis and debugging in the absence of source code. However, this process is hindered by fidelity issues, which can significantly impair the readability and accuracy of the decompiled output. Existing approaches partially addressed these, such as variable renaming and structural simplification, but typically fail to provide adequate detection and correction, especially in complex but practical closed-source binary scenarios. To address this, we introduce FidelityGPT , a novel framework to improve the accuracy and readability of decompiled code by systematically detecting and correcting discrepancies between decompiled code and its original source. FidelityGPT defines distortion prompt templates tailored to closed-source environments and incorporates Retrieval-Augmented Generation (RAG) with a dynamic semantic intensity algorithm. The algorithm identifies distorted lines based on semantic intensity, retrieving similar code from a database. Additionally, a variable dependency algorithm is designed to overcome the limitations of long-context inputs by analyzing redundant variables through their dependencies and integrating redundant variable names into prompt context. These combined techniques establish FidelityGPT as the first framework capable of effectively addressing decompilation distortion issues in LLM-based decompilation optimization. We evaluated FidelityGPT on 620 function pairs from a binary similarity benchmark, achieving an average detection accuracy of 89% and a precision of 83%. Compared to the current state-of-the-art model, DeGPT , which achieved an average Fix Rate (FR) of 83% and an average Corrected Fix Rate (CFR) of 37%, FidelityGPT demonstrated superior performance. With an average FR of 94% and an average CFR of 64%, FidelityGPT significantly improves both accuracy and readability, underscoring its effectiveness in enhancing decompilation and its potential to drive advancements in reverse engineering. † † footnotetext: ∗ Corresponding authors. I Introduction Decompilation is a critical technique that translates machine code (e.g., binary files) into human-readable languages [ 1 , 2 ] . While decompiled code cannot be recompiled and executed, it significantly aids reverse engineers in comprehending, analyzing, and debugging programs when the source code is inaccessible. This makes decompilation indispensable in both software engineering [ 3 ] and cybersecurity [ 4 , 5 ] . Despite its importance, decompilation faces significant challenges due to factors such as the loss or absence of symbolic information, complex control flows, and other related issues, often leading to discrepancies between the decompiled code and the original source. These discrepancies, known as fidelity issues (or distortion issues ), can severely affect both the readability and the semantic integrity of the decompiled code [ 6 ] . As a result, decompiled code may suffer from issues such as meaningless variable names, type errors, redundant variables, incorrect return behavior, and the inclusion of compiler-specific functions. These problems not only hinder research but also pose a risk of misinterpreting the original code [ 7 , 8 ] . To this end, a few attempts have been made, aiming at improving the accuracy of source code inference from decompiled binaries, with a particular focus on predicting variable names and other code elements. For instance, Banerjee et al. [ 9 ] introduced a method that employs masked language models, byte-pair encoding, and neural architectures to infer variable names in decompiled code. Similarly, HexT5 [ 10 ] leveraged a unified pre-training model with pseudo-code objectives, including code summarization and variable name recovery, while VARBERT [ 11 ] applied Transformer-based architectures to enhance variable name prediction in decompiled outputs. However, these machine learning-based approaches still have lots of limitations, particularly in that they can only target specific datasets and have limited generative capabilities. For example, these models often struggle to generate new code constructs or accurately infer variable names and types when encountering unfamiliar patterns or contexts. This limitation is particularly pronounced when dealing with code that exhibits significant deviations from the patterns seen during training, reducing their effectiveness in real-world scenarios where code diversity is usually higher than expected. In recent years, large language models (LLMs) have demonstrated outstanding performance in decompilation optimization. For instance, DeGPT [ 12 ] was the first to use LLMs for optimizing the output of decompiled code. It introduced a three-role mechanism to enhance decompilation results, achieving significant improvements in restoring variable names and reconstructing code structures, thereby greatly enhancing the readability of decompiled code. However, this approach primarily addresses isolated aspects of decompilation fidelity, such as variable name recovery and code restructuring, leaving substantial gaps in fully detecting and correcting discrepancies between the source code and the decompiled outputs. Overall, current research has yet to develop extensive and automated methods for detecting and addressing distortion issues. Generally, three primary challenges persist in mitigating this issue: C1: Impractical Description of Discrepancies. Existing research has primarily focused on identifying discrepancies in specific code elements, such as variables and types. However, these studies address only a small subset of the differences encountered during decompilation. While previous work [ 6 ] has provided a comprehensive taxonomy of these discrepancies, some types, such as missing variables and missing code, require reference to the source code for detection. This becomes impractical in closed-source environments where the source code is not directly available. Therefore, further investigation is necessary for closed-source scenarios. C2: Handling Long Decompiled Code in LLMs. Decompiled functions often span hundreds of lines, posing a challenge for large language models (LLMs) due to token limitations and constrained attention mechanisms. Processing such long sequences in a single pass leads to performance degradation, increased computational costs, and loss of context for long-range variable dependencies. Efficiently managing long code sequences is critical for applying LLMs to large-scale decompilation tasks [ 13 , 14 ] . C3: Inconsistent and Inaccurate Outputs of LLMs. One of the key challenges in optimizing decompilation using LLMs is ensuring accuracy and precision. LLMs often encounter issues such as semantic drift and hallucination during code interpretation, leading to inconsistent and unreliable results. Retrieval-Augmented Generation (RAG) can mitigate these problems by grounding LLM predictions with relevant external knowledge, but this requires a comprehensive database of distortion patterns and precise querying to ensure contextually accurate results. In response to the challenges mentioned, we propose FidelityGPT , a novel framework designed to detect and correct distortions in decompiled code, especially in closed-source environments. This tool aims at optimizing decompiled output, providing reverse engineers with a more reliable foundation for analysis. Specifically, to address C1 , we developed an extensive prompt template that systematically categorizes distortion types, aiding in the detection of decompilation issues in closed-source contexts(see III-D ). To tackle C2 , we employ a chunking strategy to split long decompiled code into smaller, manageable blocks, reducing performance degradation in LLMs. To preserve context across chunks, we implement a Variable Dependency Algorithm(see III-B ) that extracts relationships between variables, ensuring accurate detection of distortions involving long-range dependencies.To solve C3 , we leverage Retrieval-Augmented Generation

Read the complete text