项目简介
Ghidra 是美国国家安全局开发的软件逆向工程框架,具备反汇编、反编译、图形分析和脚本功能,支持多种处理器架构与可执行文件格式,并可通过 Java 或 Python 进行扩展。
README 预览
\n\n# Ghidra Software Reverse Engineering Framework\nGhidra is a software reverse engineering (SRE) framework created and maintained by the \n[National Security Agency][nsa] Research Directorate. This framework includes a suite of \nfull-featured, high-end software analysis tools that enable users to analyze compiled code on a \nvariety of platforms including Windows, macOS, and Linux. Capabilities include disassembly, \nassembly, decompilation, graphing, and scripting, along with hundreds of other features. Ghidra \nsupports a wide variety of processor instruction sets and executable formats and can be run in both \nuser-interactive and automated modes. Users may also develop their own Ghidra extension components \nand/or scripts using Java or Python.\n\nIn support of NSA's Cybersecurity mission, Ghidra was built to solve scaling and teaming problems \non complex SRE efforts, and to provide a customizable and extensible SRE research platform. NSA has \napplied Ghidra SRE capabilities to a variety of problems that involve analyzing malicious code and \ngenerating deep insights for SRE analysts who seek a better understanding of potential \nvulnerabilities in networks and systems.\n\nIf you are a U.S. citizen interested in projects like this, to develop Ghidra and other \ncybersecurity tools for NSA to help protect our nation and its allies, consider applying for a \n[career with us][career].\n\n## Security Warning\n**WARNING:** There are known security vulnerabilities within certain versions of Ghidra. Before \nproceeding, please read through Ghidra's [Security Advisories][security] for a better understanding \nof how you might be impacted.\n\n## Install\nTo install an official pre-built multi-platform Ghidra release: \n* Install [JDK 21 64-bit][jdk]\n* Download a Ghidra [release file][releases]\n - **NOTE:** The official multi-platform release file is named \n `ghidra___.zip` which can be found under the "Assets" drop-down.\n Downloading either of the file
常见问题 (5)
故障排除如何修复 Ghidra 将操作码 `8E D8` 显示为 `MOV AX, DS` 而不是 `MOV DS, AX` 的问题?
这是 Ghidra 12.1.3 和 12.1.4 中的一个回归问题,由提交 GP-7018 引起。对于 MOV 指令的操作码 0x8e,x86 SLEIGH 规范将段寄存器和通用寄存器的显示顺序颠倒了。
要在本地修复此问题,请编辑 Ghidra/Processors/x86/data/languages/ia.sinc,将受影响的构造函数名称从:
:MOV Rmr16,Sreg ... { Sreg = Rmr16; }
:MOV Rmr32,Sreg ... { Sreg = Rmr32(0); }
:MOV Rmr64,Sreg ... { Sreg = Rmr64(0); }
改为:
:MOV Sreg,Rmr16 ... { Sreg = Rmr16; }
:MOV Sreg,Rmr32 ... { Sreg = Rmr32(0); }
:MOV Sreg,Rmr64 ... { Sreg = Rmr64(0); }
只有显示的操作数顺序发生变化;语义动作必须保持为 Sreg = ...。
然后从 Ghidra 安装根目录重新构建 x86 SLEIGH 二进制文件:
support/sleigh -a Ghidra/Processors/x86
重启 Ghidra 并重新打开程序。此时,字节 8e d8 对应的指令应能正确反汇编为 MOV DS,AX。该修复已在 PR #9637 中提交,因此升级到包含该修复的版本才是永久性的解决方案。
故障排除当指令的操作数超过 8 个时,如何修复 Sleigh 反编译器错误 "Index 8 out of bounds for length 8"?
升级到 Ghidra 11.0 或更高版本。此版本包含提交 0e9c36b513c4d744fe6c6f7559c049ce1d65266f,该提交将 Sleigh/Pcode 操作数的最大数量提升到了此前 8 个的限制之上。如果必须使用旧版本的 Ghidra,作为变通方案,请将伪操作码定义中的操作数减少至最多 8 个。
故障排除如何修复 Ghidra 反编译器在处理 16 字节 RDX:RAX 返回值时出现的 "Low-level Error: Forced merge caused intersection" 错误?
这种情况发生在 Ghidra 12.1.2 中:当被调用函数使用默认的 void 签名,但实际通过 RDX:RAX 返回一个 16 字节的值,而调用方仅在一条条件路径上将该值存储到一个地址绑定的栈槽中时。反编译器会将该栈槽复用为调用输出,从而与现有的 INDIRECT varnode 发生冲突。
永久修复方法:升级到包含 GP-7136 的构建版本(提交 bb33bad196,已在 master 分支上修复)。在该问题被报告时,12.1.2–12.1.4 以及 12.2 分支中均未包含此修复。
受影响版本中的临时解决方法:
1. 打开被调用函数,例如 ret_pair。
2. 编辑其函数签名/返回类型。
3. 定义并指定一个锁定的 16 字节结构体返回类型,例如:
struct Pair16 {
undefined8 a;
undefined8 b;
};4. 将调用约定设置为
__stdcall 并应用该签名。5. 在 Decompiler 中重新打开调用方函数。
如果不需要该返回值,将被调用函数的返回类型改为 void 也可以避免崩溃。仅在调用点处使用 "Override Signature" 覆盖为 void(void) 是不够的。
故障排除如何修复 Ghidra 反编译器在 6809 或 H8/300H 等大端目标上错误地移除可达代码并提示 'Removing unreachable block' 的问题?
这是 Ghidra 12.1.2 的大端(big-endian)splitflow bug。当一个寄存器被拆分为独立使用的两半时,例如 6809 的 D(A/B),反编译器可能会交换各部分的 consume mask。随后,活跃的部分会被视为未使用、被替换为零,其分支被折叠,可达代码也被删除。
临时解决方法:禁用反编译器的 splitflow 简化规则并重新反编译。警告应当消失,活跃的寄存器半部/条件代码应当恢复。
永久修复:应用 PR "Preserve consume masks for big-endian register splits."。在 TransformVar::createReplacement() 中,仅在构造替换 varnode 地址时继续使用转换后的大端存储偏移量,而将原始的逻辑/有效位(significance)偏移量传递给 transferVarnodeProperties()。然后重新构建原生反编译器,或升级到包含该修复的 Ghidra 版本。
通过确认以下几点来验证结果:活跃的半部仍保持为变量,依赖数据的分支被保留,且循环后的 STA 存储等代码不再被报告为不可达。
故障排除为什么 Ghidra 错误对话框会隐藏 '<' 字符,并显示与堆栈跟踪不同的文本?
在 Ghidra 9.1 中,可扩展错误对话框在未先进行转义的情况下将纯文本消息渲染为 HTML。ErrLogExpandableDialog.getHTML() 通过 addHTMLContent() 插入对话框消息和每个 Throwable.getMessage(),而 addBR() 仅将换行符转换为 <br>。因此,诸如 <= 64 之类的文本可能会被解释为 HTML 标签,并从渲染后的对话框中消失。底层消息在堆栈跟踪或日志中仍然是正确的:Bit length must be >= 1 and <= 64。
解决方法:复制或查看完整的堆栈跟踪/日志,而不是依赖渲染后的对话框消息。
永久修复:在将每条纯文本消息插入对话框之前先对其进行 HTML 转义,然后再将换行符转换为 <br>:
private static String escapePlainText(String s) {
return s.replace("&", "&")
.replace("<", "<")
.replace(">", ">");
}
将此方法同时应用于 ErrLogExpandableDialog.getHTML() 中的主消息和 Throwable.getMessage(),然后重新构建 Ghidra,或者使用包含标题为 "Escape plain-text messages in the expandable error dialog" 的修复的构建版本。