DDisasm 是一款快速的反汇编器,其精度足以让生成的汇编代码能够被重新汇编。DDisasm 使用 datalog(souffle)声明式逻辑编程语言实现,以编译反汇编规则和启发式方法。该反汇编器首先解析 ELF/PE 文件信息,并解码一组超集的潜在指令,以创建初始的 datalog 事实集。这些事实经过分析,用于识别代码位置、符号化以及函数边界。分析结果(即精炼后的 datalog 事实集)随后被转换为 GTIRB 中间表示,用于二进制分析和逆向工程。之后可使用 GTIRB pretty printer 将 GTIRB 格式化为可重新汇编的汇编代码。
二进制格式:
指令集架构 (ISA):
你可以使用 Docker 运行预构建版本的 Ddisasm:
docker pull grammatech/ddisasm:latest
Ddisasm 可用于将二进制反汇编为 GTIRB 表示形式。我们可以使用仓库中包含的其中一个示例来尝试。
首先,启动 Ddisasm Docker 容器:
docker run -v $PWD/examples:/examples -it grammatech/ddisasm:latest
在 Docker 容器内,让我们构建其中一个示例:
apt update && apt install gcc -y
cd /examples/ex1
gcc ex.c -o ex
现在我们可以继续反汇编该二进制文件:
ddisasm ex --ir ex.gtirb
一旦你拥有了 GTIRB 表示形式,就可以使用 GTIRB 或 gtirb-rewriting 对二进制文件进行程序化修改。
然后,你可以使用 gtirb-pprinter(包含在 Docker 镜像中)生成一个新版本的二进制文件:
gtirb-pprinter ex.gtirb -b ex_rewritten
在内部,gtirb-pprinter 会生成一个汇编文件并调用编译器/汇编器(例如 gcc)来生成新的二进制文件。gtirb-pprinter 将负责生成所有必要的命令行选项,包括编译选项、库依赖或版本链接脚本。
你也可以使用 gtirb-pprinter 生成汇编列表以供手动修改:
gtirb-pprinter ex.gtirb --asm ex.s
然后可以手动重新编译这个汇编列表:
gcc -nostartfiles ex.s -o ex_rewritten
请查看我们的文档以获取更多信息。
请参阅 CONTRIBUTING.md
@inproceedings {flores-montoya2020,
author = {Antonio Flores-Montoya and Eric Schulte},
title = {Datalog Disassembly},
booktitle = {29th USENIX Security Symposium (USENIX Security 20)},
year = {2020},
isbn = {978-1-939133-17-5},
pages = {1075--1092},
url = {https://www.usenix.org/conference/usenixsecurity20/presentation/flores-montoya},
publisher = {USENIX Association},
month = aug,
}
@misc{schulte2020gtirb,
title={GTIRB: Intermediate Representation for Binaries},
author={Eric Schulte and Jonathan Dorn and Antonio Flores-Montoya and Aaron Ballman and Tom Johnson},
year={2020},
eprint={1907.02859},
archivePrefix={arXiv},
primaryClass={cs.PL}
}
@INPROCEEDINGS{11023516,
author={Flores-Montoya, Antonio and Lim, Junghee and Seitz, Adam and Sood, Akshay and Raff, Edward and Holt, James},
booktitle={2025 IEEE Symposium on Security and Privacy (SP)},
title={Disassembly as Weighted Interval Scheduling with Learned Weights},
year={2025},
volume={},
number={},
pages={3033-3050},
keywords={Measurement;Privacy;Accuracy;Heuristic algorithms;Reverse engineering;Binary codes;Benchmark testing;Scheduling;Inference algorithms;Security;disassembly;reverse engineering;learning;binary analysis},
doi={10.1109/SP61157.2025.00192}}