5.14 数据

当分析反汇编文件时,绕过反汇编器直接在二进制文件中,访问其中的字节,非常有用。要做到这些,IDA 提供如下函数(下面附带的)。所有下面这些函数都定义在 bytes.hpp。这些函数对字节进行操作,而且也有一些函数对 word,long,qword 进行操作(get_word(),patch_word() 等等),也定义在 bytes.hpp 中。在二进制文件自身中,可以使用这些函数读取数据,也可以在调试器下执行进程的时候,读取进程的内存。详情请参考 Debugger 函数章节。

5.14.1 get_byte

定义

idaman uchar ida_export

get_byte(ea_t ea)

含义

在 IDA 中打开的当前反汇编文件中,返回地址 ea 处的字节。如果 ea 并不存在,则返回 BADADDR。要操作更大的数据块,可以使用 get_word(),get_long() 还有 get_qword()。操作多字节数据块,使用 get_many_bytes()。

示例

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

#include <bytes.hpp>

// Display the byte value for the current cursor

// position. The values returned should correspond

// to those in your IDA Hex view.

msg("%x\n", get_byte(get_screen_ea()));

5.14.2 get_many_bytes

定义

idaman bool ida_export

get_many_bytes(ea_t ea, void *buf, ssize_t size)

含义

在 ea 地址的开始处,获取 size 个字节的数据,并保存到*buf。

示例

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

#include <bytes.hpp>

char string[MAXSTR];

flags_t flags = getFlags(get_screen_ea());

// Only get a string if we're at actual data.

if (isData(flags)) {

// Get a string from the binary

get_many_bytes(get_screen_ea(),

string,

sizeof(string)-2);

// NULL terminate the string, if not already

// terminated in the binary (so strlen doesn't barf)

string[MAXSTR-1] = '\0';

msg("String length: %d\n", strlen(string));

}

5.14.3 patch_byte

定义

idaman void ida_export

patch_byte(ea_t ea, ulong x)

含义

用 x 替换地址 ea 处的字节。原始字节保存在 IDA 数据库,也可以使用 get_original_byte()(参阅 bytes.hpp)获取原始字节。不保存原始字节,使用 put_byte(ea_t ea, ulong x) 代替。要操作更大的数据块,可以使用 put_word(),put_long() 还有 put_qword()。操作多字节数据块,使用 put_many_bytes()。

示例

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

#include <bytes.hpp>

// Get the flags for the byte at the cursor position.

flags_t flags = getFlags(get_screen_ea());

// Replace the instruction at the cursor position with

// a NOP instruction (0x90).

// Unless used carefully, your executable will probably

// not work correctly after this :-)

if (isCode(flags))

patch_byte(get_screen_ea(), 0x90);

5.14.4 patch_many_bytes

定义

idaman void ida_export

patch_many_bytes(ea_t ea, const void *buf, size_t size)

含义

用*buf 的内容替换地址 ea 处的 size 个字节内容。

示例

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

#include <bytes.hpp>

// Prompt the user for an address, then a string

ea_t addr = get_screen_ea();

askaddr(&addr, "Address to put string:");

char *string = askstr(0, "", "Please enter a string");

// Write the user supplied string to the address

// the user specified.

patch_many_bytes(addr, string, strlen(string));

发布评论

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

词条统计

浏览:0 次

字数:3651

最后编辑:1 个月前

最近更新:JSmiles

编辑次数:0 次

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