DDisasm:可逆(双向)反汇编器
DDisasm: Reversible (bi-directional) Disassembler

原始链接: https://github.com/GrammaTech/ddisasm

DDisasm 是一款高精度、快速的反汇编工具,旨在生成可重汇编的汇编代码。它利用 Soufflé Datalog 引擎,通过逻辑规则和启发式方法对二进制文件进行分析。通过解析 ELF/PE 文件并解码潜在指令的超集,DDisasm 能够识别函数边界、符号和代码位置。 其输出格式为 GTIRB 中间表示,便于进行二进制分析和逆向工程。借助随附的 GTIRB 代码美化工具(pretty printer),用户既可以生成新的重编译二进制文件,也可以生成用于手动修改的汇编列表。DDisasm 支持多种架构,包括 x86(32/64 位)、ARM(32/64 位)和 MIPS32。 该工具通过 Docker 提供,部署简便,能够无缝集成到二进制重写工作流中。作为高级分析任务的基础组件,它在关于基于 Datalog 的反汇编和加权区间调度的研究论文中均有详细介绍。丰富的文档和社区贡献进一步支持了其在安全和逆向工程研究中的应用。

近期的一场 Hacker News 讨论聚焦于由 GrammaTech 开发的可逆(双向)反汇编器 **DDisasm**。 该项目因其能将二进制文件反汇编为可重新组装成功能性可执行文件的格式而引发了广泛关注。评论者探讨了这一过程的技术可行性,指出虽然修改指令数量或大小通常会破坏二进制文件,但 DDisasm 利用了 ELF 和 PE 文件中现有的重定位信息来保持功能完整性。 参与者还讨论了其底层技术,特别提到了对 Soufflé 逻辑编程语言的使用。尽管一些用户对这类工具的复杂性以及底层逻辑分析中可能出现的“饱和爆炸”表示怀疑,但原作者称赞 DDisasm 效果惊人,将其描述为二进制分析领域的一项重大进步。总的来说,社区对 DDisasm 如何在无需“魔法”的情况下架起反汇编与重组之间桥梁这一特性仍深感好奇。
相关文章

原文

DDisasm is a fast disassembler which is accurate enough for the resulting assembly code to be reassembled. DDisasm is implemented using the datalog (souffle) declarative logic programming language to compile disassembly rules and heuristics. The disassembler first parses ELF/PE file information and decodes a superset of possible instructions to create an initial set of datalog facts. These facts are analyzed to identify code location, symbolization, and function boundaries. The results of this analysis, a refined set of datalog facts, are then translated to the GTIRB intermediate representation for binary analysis and reverse engineering. The GTIRB pretty printer may then be used to pretty print the GTIRB to reassemblable assembly code.

Binary formats:

Instruction Set Architectures (ISAs):

  • x86_32
  • x86_64
  • ARM32
  • ARM64
  • MIPS32

You can run a prebuilt version of Ddisasm using Docker:

docker pull grammatech/ddisasm:latest

Ddisasm can be used to disassemble a binary into the GTIRB representation. We can try it with one of the examples included in the repository.

First, start the Ddisasm docker container:

docker run -v $PWD/examples:/examples -it grammatech/ddisasm:latest

Within the Docker container, let us build one of the examples:

apt update && apt install gcc -y
cd /examples/ex1
gcc ex.c -o ex

Now we can proceed to disassemble the binary:

Once you have the GTIRB representation, you can make programmatic changes to the binary using GTIRB or gtirb-rewriting.

Then, you can use gtirb-pprinter (included in the Docker image) to produce a new version of the binary:

gtirb-pprinter ex.gtirb -b ex_rewritten

Internally, gtirb-pprinter will generate an assembly file and invoke the compiler/assembler (e.g. gcc) to produce a new binary. gtirb-pprinter will take care or generating all the necessary command line options to generate a new binary, including compilation options, library dependencies, or version linker scripts.

You can also use gtirb-pprinter to generate an assembly listing for manual modification:

gtirb-pprinter ex.gtirb --asm ex.s

This assembly listing can then be manually recompiled:

gcc -nostartfiles ex.s -o ex_rewritten

Please take a look at our documentation for additional information.

See CONTRIBUTING.md

  • Programming Language Group, The University of Sydney: Initial support for ARM64.
  • Github user gogo2464: Documentation refactoring.
  1. Datalog Disassembly
@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,
}
  1. GTIRB
@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}
}
  1. Ddisasm WIS
@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}}
联系我们 contact @ memedata.com