Ghidra 使用及配置
Ghidra 使用及配置
本文主要是个人使用 Ghidra 的一些小 Tips 以及配置
常用快捷键
功能 | 快捷键 |
---|---|
Go To 对话框 | G |
搜索内存 | S |
修改名称 | L |
IDEA 脚本开发环境搭建
IDEA 插件地址: https://github.com/garyttierney/intellij-ghidra
按照插件 README 中的解释,编译一份安装即可。安装完成之后,创建一个空的 Java 项目,然后在项目设置中如图进行操作,即可获得代码提示脚本的代码提示功能
然后,添加一个 Run/Debug Configuration 就可以点击启动 Ghidra 了(注意,不光点击启动,而且还点击关闭🤣
启动后,在 Script Manager 里怕是找不到自己新建的脚本添加一下目录就好了(我测试好像从 IDEA 启动添加目录之后,不会保存我添加的目录,但是我正常打开添加一遍就保存了。
Debug 模式下启动还能调试脚本,这不比 IDA 舒服?(关键是免费
2023年12月更新: 最新版本 2023.3 的 IDEA 中需要升级一下项目的 Kotlin 版本,以及支持库的版本,才能编译成功。
鼠标 前进/后退 导航脚本
Ghidra 在导航方面有个大问题,就是鼠标的前进后退侧键不好使,只能按键盘的快捷键 Alt + Shift + 左/右
来实现 IDA Pro 的导航效果。这个问题早就有人在官方仓库下提过了,但是官方的意思是不会支持的 https://github.com/NationalSecurityAgency/ghidra/issues/208,可以用脚本实现,并提供了Alt + 左/右
脚本,下面是我改成函数级的导航后的脚本。
不同的鼠标,前进后退键的 button 值不同,可以打印一下自己的值,改一下脚本,我个人的就是 4
是后退,5
是前进。
//@category Experimental
import java.awt.AWTEvent;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.MouseEvent;
import java.util.Set;
import docking.DefaultActionContext;
import ghidra.app.script.GhidraScript;
import docking.action.DockingActionIf;
import ghidra.framework.plugintool.PluginTool;
import ghidra.util.Swing;
public class MouseNavigationScript extends GhidraScript {
private static final String ACTION_OWNER = "NextPrevAddressPlugin";
private static AWTEventListener LISTENER;
@Override
protected void run() throws Exception {
if (isRunningHeadless()) {
return;
}
createListener();
Toolkit tk = Toolkit.getDefaultToolkit();
// don't repeatedly add the listener
tk.removeAWTEventListener(LISTENER);
tk.addAWTEventListener(LISTENER, AWTEvent.MOUSE_EVENT_MASK);
}
private void createListener() {
if (LISTENER != null) {
return;
}
LISTENER = e -> {
MouseEvent mousey = (MouseEvent) e;
int id = mousey.getID();
int button = mousey.getButton();
if (id != MouseEvent.MOUSE_PRESSED) {
return;
}
// 可以在这里打印看看自己鼠标对应的按键
if (button == 4) {
mousey.consume();
DockingActionIf back = getNavigationAction("Previous Function in History");
if (back != null) {
Swing.runLater(() -> {
back.actionPerformed(new DefaultActionContext());
});
}
} else if (button == 5) {
mousey.consume();
DockingActionIf forward = getNavigationAction("Next Function in History");
if (forward != null) {
Swing.runLater(() -> {
forward.actionPerformed(new DefaultActionContext());
});
}
}
};
}
private DockingActionIf getNavigationAction(String name) {
PluginTool tool = state.getTool();
Set<DockingActionIf> actions = tool.getDockingActionsByOwnerName(ACTION_OWNER);
for (DockingActionIf action : actions) {
if (action.getName().equals(name)) {
return action;
}
}
return null;
}
}
想更方便点,可以给脚本设置个快捷键,像我就随便设置了个 Ctrl + 0
点击高亮同名变量名
这个功能其实是有的,只不过有点反人类,默认是点击鼠标中键高亮,改一下改成 LEFT
就好了。