IDAPython:idaapi.get_highlight 用于解构名称

逆向工程 艾达 蟒蛇 idapro-sdk ida插件
2021-07-06 03:44:29

我正在使用以下代码来获取所选函数/变量的地址:

hightlight = idaapi.get_highlight(idaapi.get_current_viewer())
screen_ea = idaapi.get_screen_ea()
ea = idaapi.get_name_ea(screen_ea, name)

它就像一个魅力,除非你在 IDA 视图中遇到 demangled name :(

例如,对于这一行

.text:00406744                 call    KBTickCount(void)

idaapi.get_name_ea 调用永远不会返回正确的地址,因为真正的名字是?KBTickCount@@YIJXZ。

我知道我可以在 IDA Pro 中更改解散名称表示,但我正在开发一个公共插件并且我正在考虑最终用户。

而且我还想让它在 Pseudocode 视图中工作,其中所有名称都被取消了。

关于如何获取特定行的所选函数/变量的地址的任何想法?

1个回答

所有动作回调都会收到一个上下文指针,其中预填充了各种信息:

  ea_t cur_ea;           ///< the current EA of the position in the view
  uval_t cur_value;      ///< the possible address, or value the cursor is positioned on

  func_t *cur_func;      ///< the current function
  func_t *cur_fchunk;    ///< the current function chunk

  struc_t *cur_struc;    ///< the current structure
  member_t *cur_strmem;  ///< the current structure member

  enum_t cur_enum;       ///< the current enum

  segment_t *cur_seg;    ///< the current segment

(来自kernwin.hpp)

因此,您可以直接使用ctx.cur_value(或其 Python 同义词cur_extracted_ea)直接获取光标下的地址/值/标识符,而无需自己解析。