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框架,通过系统化检测与校正语义失真来提升反编译代码的准确性与可读性。FidelityGPT针对闭源场景设计了失真感知提示模板,并集成检索增强生成(RAG)与动态语义强度算法,以定位失真代码行并从数据库中检索语义相似的代码。变量依赖算法通过分析冗余变量并将其依赖关系整合至提示上下文中,进一步缓解长上下文限制。在二进制相似性基准测试的620个函数对上进行评估,FidelityGPT实现了平均89%的检测准确率与83%的精确率。相较于当前最优的DeGPT(修复率83%,校正修复率37%),FidelityGPT达到94%的修复率与64%的校正修复率,在准确性与可读性方面取得显著提升。这些结果凸显了其在推进基于大语言模型的反编译与逆向工程方面的潜力。