GrammaTech/ddisasm

GitHub: GrammaTech/ddisasm

DDisasm 是一个基于 Datalog 逻辑编程语言实现的快速、高精度反汇编器,能够将二进制文件转换为可重新汇编的中间表示。

Stars: 744 | Forks: 66

# Datalog Disassembly DDisasm 是一个*快速*的反汇编器,其精度足以使 生成的汇编代码能够被重新汇编。DDisasm 使用 datalog ([souffle](https://github.com/souffle-lang/souffle)) 声明式逻辑编程语言实现,用于编译反汇编规则 和启发式方法。该反汇编器首先解析 ELF/PE 文件信息 并解码可能的指令超集,以创建初始的 datalog 事实集合。 这些事实经过分析以识别*代码位置*、*符号化* 和*函数边界*。该分析的结果,即经过精炼的 datalog 事实集合, 随后被转换为用于二进制分析和逆向工程的 [GTIRB](https://github.com/grammatech/gtirb) 中间表示。 然后可以使用 [GTIRB pretty printer](https://github.com/grammatech/gtirb-pprinter) 将 GTIRB 美化打印为可重新汇编的汇编代码。 ## 二进制支持 二进制格式: - ELF (Linux) - PE (Windows) 指令集架构 (ISA): - x86_32 - x86_64 - ARM32 - ARM64 - MIPS32 ## 入门指南 您可以使用 Docker 运行 Ddisasm 的预构建版本: ``` docker pull grammatech/ddisasm:latest ``` Ddisasm 可用于将二进制文件反汇编为 [GTIRB](https://github.com/grammatech/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](https://github.com/grammatech/gtirb) 或 [gtirb-rewriting](https://github.com/grammatech/gtirb-rewriting) 对二进制文件进行程序化修改。 然后,您可以使用 [gtirb-pprinter](https://github.com/grammatech/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 ``` 请查看我们的 [文档](https://grammatech.github.io/ddisasm/) 以获取更多信息。 ## [文档](https://grammatech.github.io/ddisasm/) ## 引用 1. [Datalog Disassembly](https://www.usenix.org/conference/usenixsecurity20/presentation/flores-montoya) ``` @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, } ``` 2. [GTIRB](https://arxiv.org/abs/1907.02859) ``` @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} } ``` 3. [Ddisasm WIS](https://ieeexplore.ieee.org/document/11023516) ``` @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}} ```
标签:Datalog, ELF, GTIRB, Hakrawler, MIPS, PE, Souffle, URL提取, x86, 中间表示, 二进制分析, 云安全运维, 云资产清单, 代码还原, 反汇编器, 反编译, 可配置连接, 汇编代码, 程序分析, 符号化, 请求拦截, 逆向工程, 逻辑编程