如何在 IDA Pro 中使用 IDAPython 加载 C 头文件?
我正在尝试使用 IDAPython 自动加载 C 头文件,例如Load("filename.h").
如何在 IDA Pro 中使用 IDAPython 加载 C 头文件?
我正在尝试使用 IDAPython 自动加载 C 头文件,例如Load("filename.h").
好吧,ws的回答实际上指出了你应该做什么。这里我给出更详细的回答:
简而言之,1.h在您的 E: 驱动器下创建文件,填写一些结构定义并在您的 IDA 的输出窗口中尝试此操作:
idaapi.idc_parse_types("E:\\1.h", idc.PT_FILE)
此函数将返回解析.h文件时遇到的错误数。如果得到 0,则表示头文件中没有任何问题。
NOTE1:IDA Python 不断变化。上面的代码适用于我(我使用 IDA Pro 6.8)。如果您使用不同的版本,则可能需要进行一些更改。试试IDA Python 参考。
注意 2:您应该会在本地类型窗口中找到新类型(按 Shift+F1 打开它),该窗口以 TIL 显示类型。如果你确实需要结构(属于IDB),尝试idaapi.til2idb或idaapi.import_type将其导入。
请参阅下面来自idc.py的报价
def parse_decls(inputtype, flags = 0):
"""
Parse type declarations
@param inputtype: file name or C declarations (depending on the flags)
@param flags: combination of PT_... constants or 0
@return: number of parsing errors (0 no errors)
"""
return ida_typeinf.idc_parse_types(inputtype, flags)
PT_FILE = 0x0001 # input if a file name (otherwise contains type declarations)
PT_SILENT = 0x0002 # silent mode
PT_PAKDEF = 0x0000 # default pack value
PT_PAK1 = 0x0010 # #pragma pack(1)
PT_PAK2 = 0x0020 # #pragma pack(2)
PT_PAK4 = 0x0030 # #pragma pack(4)
PT_PAK8 = 0x0040 # #pragma pack(8)
PT_PAK16 = 0x0050 # #pragma pack(16)
PT_HIGH = 0x0080 # assume high level prototypes
# (with hidden args, etc)
PT_LOWER = 0x0100 # lower the function prototypes