# 2.2.2 IDA Pro

* [快捷键](#快捷键)
* [IDA Python](#ida-python)
* [常用插件](#常用插件)
* [常用脚本](#常用脚本)
* [技巧](#技巧)
* [参考资料](#参考资料)

## 快捷键

* `;`：为当前指令添加全文交叉引用的注释
* `n`：定义或修改名称，通常用来标注函数名
* `g`：跳转到任意地址
* `Esc`：返回到跳转前的位置
* `D`：分别按字节、字、双字显示数据
* `A`：按 ASCII 显示数据

## IDA Python

## 常用插件

* [IDA FLIRT Signature Database](https://github.com/push0ebp/sig-database) -- 用于识别静态编译的可执行文件中的库函数
* [Find Crypt](https://github.com/polymorf/findcrypt-yara) -- 寻找常用加密算法中的常数（需要安装 [yara-python](https://github.com/VirusTotal/yara-python)）
* [IDA signsrch](https://github.com/nihilus/IDA_Signsrch) -- 寻找二进制文件所使用的加密、压缩算法
* [Ponce](https://github.com/illera88/Ponce) -- 污点分析和符号化执行工具
* [snowman decompiler](https://github.com/yegord/snowman/tree/v0.1.0) -- C/C++反汇编插件（F3 进行反汇编）
* [CodeXplorer](https://github.com/REhints/HexRaysCodeXplorer) -- 自动类型重建以及对象浏览（C++）（jump to disasm)
* [IDA Ref](https://github.com/nologic/idaref) -- 汇编指令注释（支持arm，x86，mips）
* [auto re](https://github.com/a1ext/auto_re) -- 函数自动重命名
* [nao](https://github.com/tkmru/nao) -- dead code 清除
* [HexRaysPyTools](https://github.com/igogo-x86/HexRaysPyTools) -- 类/结构体创建和虚函数表检测
* [DIE](https://github.com/ynvb/DIE) -- 动态调试增强工具，保存函数调用上下文信息
* [sk3wldbg](https://github.com/cseagle/sk3wldbg) -- IDA 动态调试器，支持多平台
* [idaemu](https://github.com/36hours/idaemu) -- 模拟代码执行（支持X86、ARM平台）
* [Diaphora](https://github.com/joxeankoret/diaphora) -- 程序差异比较
* [Keypatch](https://github.com/keystone-engine/keypatch) -- 基于 Keystone 的 Patch 二进制文件插件​
* [FRIEND](https://github.com/alexhude/FRIEND) -- 哪里不会点哪里，提升汇编格式的可读性、提供指令、寄存器的文档等
* [SimplifyGraph](https://github.com/fireeye/SimplifyGraph) -- 简化复杂的函数流程图
* [bincat](https://github.com/airbus-seclab/bincat) -- 静态二进制代码分析工具包，2017 Hex-Rays 插件第一名
* [golang\_loader\_assist](https://github.com/strazzere/golang_loader_assist) -- Golang编译的二进制文件分析助手
* [BinDiff](https://www.zynamics.com/bindiff.html)

## 常用脚本

### 内存 dump 脚本

调试程序时偶尔会需要 dump 内存，但 IDA Pro 没有直接提供此功能，可以通过脚本来实现。

```python
import idaapi

data = idaapi.dbg_read_memory(start_address, data_length)
fp = open('path/to/dump', 'wb')
fp.write(data)
fp.close()
```

## 技巧

### 堆栈不平衡

某些函数在使用 f5 进行反编译时，会提示错误 "sp-analysis failed"，导致无法正确反编译。原因可能是在代码执行中的 pop、push 操作不匹配，导致解析的时候 esp 发生错误。

解决办法步骤如下：

1. 用 Option->General->Disassembly, 将选项 Stack pointer 打钩
2. 仔细观察每条 call sub\_xxxxxx 前后的堆栈指针是否平衡
3. 有时还要看被调用的 sub\_xxxxxx 内部的堆栈情况，主要是看入栈的参数与 ret xx 是否匹配
4. 注意观察 jmp 指令前后的堆栈是否有变化
5. 有时用 Edit->Functions->Edit function...,然后点击 OK 刷一下函数定义

## 参考资料

* 《IDA Pro权威指南（第2版）》
* <https://www.hex-rays.com/products/ida/>
