跳到正文
Skillpedia
通用编程13k · #11376

idapython

它能做什么

它为 AI 智能体提供 IDA Pro Python 接口的指南,用于逆向工程。适用于分析已编译程序的安全研究人员和开发者。

适用场景

  • ✓当你需要一个脚本,列出 IDA Pro 数据库中的函数或交叉引用时。
  • ✓当你要在 IDA 中分析的二进制文件里修补字节、重命名名称或设置类型时。
  • ✓当你要在 Python 中使用 Hex-Rays 反编译器时。

技能链接

https://github.com/mrexodia/ida-pro-mcp/blob/main/skills/idapython/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/mrexodia/ida-pro-mcp/blob/main/skills/idapython/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我写一个 IDA Python 脚本,列出这个二进制文件中所有调用 strcpy 的函数。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会使用正确的 ida_* 模块,以及遍历函数、指令和引用的常用模式。然后它会编写一个可在 IDA 内运行的脚本。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

IDAPython

Use modern ida_* modules. Avoid legacy idc module.

Module Router

Task Module Key Items
Bytes/memory ida_bytes get_bytes, patch_bytes, get_flags, create_*
Functions ida_funcs func_t, get_func, add_func, get_func_name
Names ida_name set_name, get_name, demangle_name
Types ida_typeinf tinfo_t, apply_tinfo, parse_decl
Decompiler ida_hexrays decompile, cfunc_t, lvar_t, ctree visitor
Segments ida_segment segment_t, getseg, add_segm
Xrefs ida_xref xrefblk_t, add_cref, add_dref
Instructions ida_ua insn_t, op_t, decode_insn
Stack frames ida_frame get_frame, define_stkvar
Iteration idautils Functions(), Heads(), XrefsTo(), Strings()
UI/dialogs ida_kernwin msg, ask_*, jumpto, Choose
Database info ida_ida inf_get_*, inf_is_64bit()
Analysis ida_auto auto_wait, plan_and_wait
Flow graphs ida_gdl FlowChart, BasicBlock
Register tracking ida_regfinder find_reg_value, reg_value_info_t

Core Patterns

Iterate functions

for ea in idautils.Functions():
    name = ida_funcs.get_func_name(ea)
    func = ida_funcs.get_func(ea)

Iterate instructions in function

for head in idautils.FuncItems(func_ea):
    insn = ida_ua.insn_t()
    if ida_ua.decode_insn(insn, head):
        print(f"{head:#x}: {insn.itype}")

Cross-references

for xref in idautils.XrefsTo(ea):
    print(f"{xref.frm:#x} -> {xref.to:#x} type={xref.type}")

Read/write bytes

data = ida_bytes.get_bytes(ea, size)
ida_bytes.patch_bytes(ea, b"\x90\x90")

Names

name = ida_name.get_name(ea)
ida_name.set_name(ea, "new_name", ida_name.SN_NOCHECK)

Decompile function

cfunc = ida_hexrays.decompile(ea)
if cfunc:
    print(cfunc)  # pseudocode
    for lvar in cfunc.lvars:
        print(f"{lvar.name}: {lvar.type()}")

Walk ctree (decompiled AST)

class MyVisitor(ida_hexrays.ctree_visitor_t):
    def visit_expr(self, e):
        if e.op == ida_hexrays.cot_call:
            print(f"Call at {e.ea:#x}")
        return 0

cfunc = ida_hexrays.decompile(ea)
MyVisitor().apply_to(cfunc.body, None)

Apply type

tif = ida_typeinf.tinfo_t()
if ida_typeinf.parse_decl(tif, None, "int (*)(char *, int)", 0):
    ida_typeinf.apply_tinfo(ea, tif, ida_typeinf.TINFO_DEFINITE)

Create structure

udt = ida_typeinf.udt_type_data_t()
m = ida_typeinf.udm_t()
m.name = "field1"
m.type = ida_typeinf.tinfo_t(ida_typeinf.BTF_INT32)
m.offset = 0
m.size = 4
udt.push_back(m)
tif = ida_typeinf.tinfo_t()
tif.create_udt(udt, ida_typeinf.BTF_STRUCT)
tif.set_named_type(ida_typeinf.get_idati(), "MyStruct")

Strings list

for s in idautils.Strings():
    print(f"{s.ea:#x}: {str(s)}")

Wait for analysis

ida_auto.auto_wait()  # Block until autoanalysis completes

Key Constants

Constant Value/Use
BADADDR Invalid address sentinel
ida_name.SN_NOCHECK Skip name validation
ida_typeinf.TINFO_DEFINITE Force type application
o_reg, o_mem, o_imm, o_displ, o_near Operand types
dt_byte, dt_word, dt_dword, dt_qword Data types
fl_CF, fl_CN, fl_JF, fl_JN, fl_F Code xref types
dr_R, dr_W, dr_O Data xref types

Critical Rules

  1. NEVER convert hex/decimal manually — use int_convert MCP tool
  2. Wait for analysis: Call ida_auto.auto_wait() before reading results
  3. Thread safety: IDA SDK calls must run on main thread (use @idasync)
  4. 64-bit addresses: Always assume ea_t can be 64-bit

Anti-Patterns

Avoid Do Instead
idc.* functions Use ida_* modules
Hardcoded addresses Use names, patterns, or xrefs
Manual hex conversion Use int_convert tool
Blocking main thread Use execute_sync() for long ops
Guessing at types Derive from disassembly/decompilation

Detailed API Reference

For comprehensive documentation on any module, read docs/<module>.md:

  • High-use: ida_bytes, ida_funcs, ida_hexrays, ida_typeinf, ida_name, idautils
  • Medium-use: ida_segment, ida_xref, ida_ua, ida_frame, ida_kernwin
  • Specialized: ida_dbg (debugger
常见问题

使用它需要 IDA Pro 吗?

需要。脚本在 IDA Pro 内运行,所以你需要先安装该工具。

它会使用较旧的 idc 模块吗?

不会。该技能要求智能体优先使用较新的 ida_* 模块,避免使用旧的 idc 模块。

它能帮忙处理反编译器吗?

可以。它涵盖 Hex-Rays 反编译,包括 ctree 访问器和局部变量。

详情

作者的原始描述

IDA Pro Python scripting for reverse engineering. Use when writing IDAPython scripts, analyzing binaries, working with IDA's API for disassembly, decompilation (Hex-Rays), type systems, cross-references, functions, segments, or any IDA database manipulation. Covers ida_* modules (50+), idautils iterators, and common patterns.

repo: mrexodia/ida-pro-mcp

热度

GitHub 星标
13k
排名
#11376
许可证
MIT
更新时间
2026/9/26

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

相似技能