Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
LLM4Decompile — 逆向工程:使用大型语言模型反编译二进制代码 | Kitploit
工具/GitHubGitHub/albertan017/llm4decompile
逆向工程二进制分析机器学习AI 辅助逆向
GitHubalbertan017/llm4decompile

LLM4Decompile

逆向工程:使用大型语言模型反编译二进制代码

查看仓库网站
7.0k54586个月前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

LLM4Decompile

📊 结果 | 🤗 模型 | 🚀 快速开始 | 📚 HumanEval-Decompile | 📎 引用 | 📝 论文 | 🖥️ Colab | ▶️ YouTube

逆向工程:利用大型语言模型反编译二进制代码

GitHub Tread

更新

  • [2025-10-04]:发布 SK²Decompile:基于 LLM 的从骨架(Skeleton)到皮肤(Skin)的两阶段二进制反编译。第一阶段:结构恢复(骨架)——将二进制/伪代码转换为混淆的中间表示 🤗 HF 链接。第二阶段:标识符命名(皮肤)——生成具有有意义标识符的人类可读源代码 🤗 HF 链接。
  • [2025-05-20]:发布 decompile-bench,包含两百万对用于训练的二进制-源码函数对,以及 70K 对用于评估的函数对。详情请参阅 decompile-bench 文件夹。
  • [2024-10-17]:发布 decompile-ghidra-100k,内含 10 万个训练样本的子集(每个优化级别 2.5 万个)。我们提供了训练脚本,在单块 A100 40G GPU 上约 3.5 小时即可运行完成。其可重执行率达到 0.26,总成本低于 20 美元,可快速复现 LLM4Decompile。
  • [2024-09-26]:更新了 Colab 笔记本 以演示 LLM4Decompile 模型的使用方法,包括 LLM4Decompile-End 和 LLM4Decompile-Ref 模型的示例。
  • [2024-09-23]:发布 LLM4Decompile-9B-v2,基于 Yi-Coder-9B 微调,在 Decompile 基准测试上取得了 0.6494 的可重执行率。
  • [2024-06-19]:发布 V2 系列(LLM4Decompile-Ref)。V2(1.3B-22B)基于 Ghidra 构建,在 20 亿个 token 上训练,用于优化 Ghidra 反编译出的伪代码。22B-V2 版本比 6.7B-V1.5 额外提升了 40.1%。详情请查看 ghidra 文件夹。
  • [2024-05-13]:发布 V1.5 系列(LLM4Decompile-End,直接使用 LLM 反编译二进制代码)。V1.5 使用更大的数据集(15B token)和最大 token 长度为 4,096 进行训练,与之前的模型相比性能显著提升(提升超过 100%)。
  • [2024-03-16]:新增 llm4decompile-6.7b-uo 模型,该模型在训练时不了解优化级别(O0~O3)的先验知识,平均可重执行率约为 0.219,在我们的模型中表现最佳。

关于

  • LLM4Decompile 是首个专用于反编译的开源大型语言模型。当前版本支持将 Linux x86_64 二进制文件(涵盖 GCC 的 O0 至 O3 优化级别)反编译为人类可读的 C 源代码。我们的团队致力于扩展该工具的能力,持续努力纳入更广泛的架构和配置。
  • LLM4Decompile-End 专注于直接反编译二进制代码。LLM4Decompile-Ref 则优化 Ghidra 反编译出的伪代码。

评估

框架

image

在编译过程中,预处理器(Preprocessor)处理源代码(SRC)以去除注释并展开宏或包含的头文件。清理后的代码随后被传递给编译器(Compiler),编译器将其转换为汇编代码(ASM)。汇编器(Assembler)再将该 ASM 转换为二进制代码(0 和 1)。链接器(Linker)通过链接函数调用来完成最后一步,生成可执行文件。反编译则是将二进制代码转换回源文件的过程。由于 LLM 是在文本上训练的,它们不具备直接处理二进制数据的能力。因此,二进制文件必须先由 Objdump 反汇编为汇编语言(ASM)。需要注意的是,二进制与反汇编后的 ASM 是等价的,它们可以相互转换,因此我们会互换使用这两个术语。最后,在反编译代码与源代码之间计算损失以指导训练。为了评估反编译代码(SRC')的质量,需要通过测试断言(可重执行性)来检验其功能。

评估指标

  • 可重执行性:评估反编译代码能否正确执行并通过所有预定义的测试用例。

基准测试

  • HumanEval-Decompile:一个包含 164 个 C 函数的集合,这些函数仅依赖标准 C 库。
  • ExeBench:一个包含 2,621 个函数的集合,这些函数取自真实项目,每个函数都使用了用户自定义的函数、结构体与宏。

结果

results

image

模型

我们的 LLM4Decompile 系列包含参数规模从 13 亿到 330 亿不等的模型,并已将这些模型发布在 Hugging Face 上。

注释 3:V1.5 系列使用更大的数据集(15B token)和最大 4,096 的 token 长度进行训练,与之前的模型相比性能显著提升(提升超过 100%)。

注释 4:V2 系列基于 Ghidra 构建,在 20 亿个 token 上训练,用于优化 Ghidra 反编译出的伪代码。详情请查看 ghidra 文件夹。

快速开始

Open In Colab

环境搭建: 请使用以下脚本安装所需环境。

root@kitploit:~
git clone https://github.com/albertan017/LLM4Decompile.git
cd LLM4Decompile
conda create -n 'llm4decompile' python=3.9 -y
conda activate llm4decompile
pip install -r requirements.txt

以下示例演示了如何使用我们的模型(针对 V1.5 修订。对于之前的模型,请查看 HF 上对应的模型页面)。 注意:请将 "func0" 替换为您想要反编译的函数名。

预处理: 将 C 代码编译为二进制,并将二进制反汇编为汇编指令。

root@kitploit:~
import subprocess
import os
func_name = 'func0'
OPT = ["O0", "O1", "O2", "O3"]
fileName = 'samples/sample' #'path/to/file'
for opt_state in OPT:
    output_file = fileName +'_' + opt_state
    input_file = fileName+'.c'
    compile_command = f'gcc -o {output_file}.o {input_file} -{opt_state} -lm'#compile the code with GCC on Linux
    subprocess.run(compile_command, shell=True, check=True)
    compile_command = f'objdump -d {output_file}.o > {output_file}.s'#disassemble the binary file into assembly instructions
    subprocess.run(compile_command, shell=True, check=True)
    
    input_asm = ''
    with open(output_file+'.s') as f:#asm file
        asm= f.read()
        if '<'+func_name+'>:' not in asm: #IMPORTANT replace func0 with the function name
            raise ValueError("compile fails")
        asm = '<'+func_name+'>:' + asm.split('<'+func_name+'>:')[-1].split('\n\n')[0] #IMPORTANT replace func0 with the function name
        asm_clean = ""
        asm_sp = asm.split("\n")
        for tmp in asm_sp:
            if len(tmp.split("\t"))<3 and '00' in tmp:
                continue
            idx = min(
                len(tmp.split("\t")) - 1, 2
            )
            tmp_asm = "\t".join(tmp.split("\t")[idx:])  # remove the binary code
            tmp_asm = tmp_asm.split("#")[0].strip()  # remove the comments
            asm_clean += tmp_asm + "\n"
    input_asm = asm_clean.strip()
    before = f"# This is the assembly code:\n"#prompt
    after = "\n# What is the source code?\n"#prompt
    input_asm_prompt = before+input_asm.strip()+after
    with open(fileName +'_' + opt_state +'.asm','w',encoding='utf-8') as f:
        f.write(input_asm_prompt)

汇编指令应符合以下格式:

<FUNCTION_NAME>:\nOPERATIONS\nOPERATIONS\n

典型的汇编指令如下所示:

root@kitploit:~
<func0>:
endbr64
lea    (%rdi,%rsi,1),%eax
retq

反编译: 使用 LLM4Decompile 将汇编指令转换为 C 代码:

root@kitploit:~
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_path = 'LLM4Binary/llm4decompile-6.7b-v1.5' # V1.5 Model
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path,torch_dtype=torch.bfloat16).cuda()

with open(fileName +'_' + OPT[0] +'.asm','r') as f:#optimization level O0
    asm_func = f.read()
inputs = tokenizer(asm_func, return_tensors="pt").to(model.device)
with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=2048)### max length to 4096, max new tokens should be below the range
c_func_decompile = tokenizer.decode(outputs[0][len(inputs[0]):-1])

with open(fileName +'.c','r') as f:#original file
    func = f.read()

print(f'original function:\n{func}')# Note we only decompile one function, where the original file may contain multiple functions
print(f'decompiled function:\n{c_func_decompile}')

Docker 环境配置

root@kitploit:~
# build docker
docker build -t llm4decompile .

# run docker with GPU
docker run --gpus all -it --name llm4decompile llm4decompile /bin/bash

# run demo.py (choose a model suitable for your resources before running)
cd ghidra
python demo.py

HumanEval-Decompile

数据以 JSON 列表格式存储在 llm4decompile/decompile-eval/decompile-eval-executable-gcc-obj.json 中。共有 164*4(O0、O1、O2、O3)个样本,每个样本包含五个键:

  • task_id:表示问题 ID。
  • type:优化阶段,取值为 [O0, O1, O2, O3] 之一。
  • c_func:HumanEval 问题的 C 语言解决方案。
  • c_test:C 语言测试断言。
  • input_asm_prompt:带有提示词的汇编指令,可按照我们的预处理示例生成。

请查看评估脚本。

进行中

  • 更大的训练数据集及相应的清洗流程。(已完成:2024.05.13)
  • 支持流行的语言/平台及设置。
  • 支持可执行二进制文件。(已完成:2024.05.13)
  • 与反编译工具(如 Ghidra、Rizin)集成。

许可证

本代码仓库采用 MIT 和 DeepSeek 许可证。

引用

root@kitploit:~
@misc{tan2024llm4decompile,
      title={LLM4Decompile: Decompiling Binary Code with Large Language Models}, 
      author={Hanzhuo Tan and Qi Luo and Jing Li and Yuqun Zhang},
      year={2024},
      eprint={2403.05286},
      archivePrefix={arXiv},
      primaryClass={cs.PL}
}

Star 历史

Star History Chart

下载工具
模型检查点参数规模可重执行率备注
llm4decompile-1.3b-v1.5🤗 HF 链接1.3B27.3%注释 3
llm4decompile-6.7b-v1.5🤗 HF 链接6.7B45.4%注释 3
llm4decompile-1.3b-v2🤗 HF 链接1.3B46.0%注释 4
llm4decompile-6.7b-v2🤗 HF 链接6.7B52.7%注释 4
llm4decompile-9b-v2🤗 HF 链接9B64.9%注释 4
llm4decompile-22b-v2🤗 HF 链接22B63.6%注释 4