IDAPython:获取在地址处定义的结构 ID

逆向工程 蟒蛇
2021-06-14 06:48:31

在尝试确定在 DB 中的给定地址处定义了哪种类型的结构(因为isStruct(getFlags(ea))Returns True时发现了一个有趣的问题通读idc.py并没有多大帮助。

  • struct在“结构”窗口中定义一个
  • 它被分配了一个structID,因此,它可以从 IDC/Python 脚本访问。
  • 现在,struct在例如.data部分中的某处定义一个变量

一个可靠的例子:

# Some Python code
strid = idaapi.get_struc_id('_s__RTTIClassHierarchyDescriptor')
size = idaapi.get_struc_size(strid)
idaapi.doStruct(ea, size, strid)

知道ea,我如何获得strid价值?

2个回答

这对我有用:

ea=here()
ti = idaapi.opinfo_t()
f = idc.GetFlags(ea)
if idaapi.get_opinfo(ea, 0, f, ti):
   print ("tid=%08x - %s" % (ti.tid, idaapi.get_struc_name(ti.tid)))

所以ti.tid然后包含步幅。

在 IDC 中,以下工作有效,所以我不确定您是否可以使用 Python 中的相同功能

auto type;
auto ea;

ea = 0x8F84C37C;
Message("isStruct: %d\n", isStruct(GetFlags(ea)));
type = GetTinfo(ea);
Message("firstattr: %s\n", firstattr(type));
Message("getattr: %d\n", getattr(type,"typid"));

输出:

isStruct: 1
firstattr: typid
getattr: 52541