5.9 交叉引用

下面四个函数是 xrefblk_t 结构的一部分,定义在 xref.hpp。它们用来填充和枚举一个地址的交叉引用。所有这些函数以标志作为一个参数,标志可以是如下的一个,同样取自在 xref.hpp:

#define XREF_ALL 0x00 // 返回所有引用
#define XREF_FAR 0x01 // 不返回普通流程引用
#define XREF_DATA 0x02 // 只返回数据引用

普通流程(ordinary flow) 指从一条指令直接执行下一条指令,并不通过 CALL 或 JMP(或等效跳转指令)。如果您只对代码交叉引用(忽略普通流程)感兴趣,那么您应该使用 XREF_ALL,并在任何情况下都检查 xrefblk_t 的 isCode 成员是否为 true。如果您只对数据引用感兴趣,就使用 XREF_DATA。

5.9.1 first_from

定义

bool

first_from(ea_t from, int flags)

含义

用来自 from 地址的首个交叉引用,来填充 xrefblk_t 结构。flags 参数表示您感兴趣的交叉引用。

示例

#include <kernwin.hpp>

#include <xref.hpp>

ea_t addr = get_screen_ea();

xrefblk_t xb;

if (xb.first_from(addr, XREF_ALL)) {

// xb 开始被填充

msg(“First reference FROM %a is %a\n”, xb.from,

xb.to);

}

5.9.2 first_to

定义

bool

first_to(ea_t to,int flags)

含义

用引用到 to 地址的首个交叉引用,来填充 xrefblk_t 结构。flags 表示您感兴趣的交叉引用。如果没有 to 没有引用,则返回 NULL。

示例

#include <kernwin.hpp> // For get_screen_ea() definition

#include <xref.hpp>

ea_t addr = get_screen_ea();

xrefblk_t xb;

if (xb.first_to(addr, XREF_ALL)) {

// xb is now populated

msg("First reference TO %a is %a\n", xb.to,

xb.from);

}

5.9.3 next_from

定义

bool

next_from(void)

含义

用 from 地址的下一个参考引用,填充 xrefblk_t 结构。如果没有其它的参考引用,则返回 false

示例

#include <kernwin.hpp> // For get_screen_ea() definition

#include <lines.hpp> // For tag_remove() and

// generate_disasm_line()

#include <xref.hpp>

xrefblk_t xb;

ea_t addr = get_screen_ea();

// Replicate IDA 'x' keyword functionality

for (bool res = xb.first_to(addr, XREF_FAR); res;

res = xb.next_to()) {

char buf[MAXSTR];

char clean_buf[MAXSTR];

// Get the disassembly text for the referencing addr

generate_disasm_line(xb.from, buf, sizeof(buf)-1);

// Clean out any format or colour codes

tag_remove(buf, clean_buf, sizeof(clean_buf)-1);

msg("%a: %s\n", xb.from, clean_buf);

}

5.9.4 next_to

定义

bool

next_to(void)

含义

用引用到 to 地址的交叉引用信息,填充 xrefblk_t 结构。如果没有其它的交叉引用,则返回 false

示例

#include <kernwin.hpp> // For get_screen_ea() definition

#include <xref.hpp>

xrefblk_t xb;

ea_t addr = get_screen_ea();

// Get the first cross reference to addr

if (xb.first_to(addr, XREF_FAR)) {

if (xb.next_to())

msg("There are multiple references to %a\n",

addr);

else

msg("The only reference to %a is at %a\n",

addr, xb.from);

}

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:0 次

字数:3409

最后编辑:1 个月前

最近更新:JSmiles

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。