5.15 I/O

如 5.1 节提到的,许多 I/O 的标准 C 库函数,都有 IDA SDK 版本,而且也推荐您使用这些 IDA SDK 版本。它们定义在 diskio.hpp。

5.15.1 fopenWT

定义

idaman FILE *ida_export

fopenWT(const char *file)

含义

以写模式,打开*file 文件,返回 FILE 指针,如果打开文件失败则返回 NULL。要以读模式打开文件,使用 fopenRT(),而且对于二进制文件,用 W 替换 R。要同时读写,使用 fopenM()。

示例

#include <diskio.hpp>

FILE *fp = fopenWT("c:\\temp\\txtfile.txt");

if (fp == NULL)

warning("Failed to open output file.");

5.15.2 openR

定义

idaman FILE *ida_export

openR(const char *file)

含义

以只读模式,打开二进制文件*file,并返回 FILE 指针,如果打开文件失败,则直接退出(显示一个错误框,然后关闭 IDA)。以只读模式打开 text 文件,失败就推出,使用 openRT(),要同时读写,使用 openM()。

示例

#include <diskio.hpp>

FILE *fp = openR("c:\\temp\\binfile.exe");

5.15.3 ecreate

定义

idaman FILE *ida_export

ecreate(const char *file)

含义

建立二进制文件*file,以只写模式,返回文件的 FILE 指针。如果无法建立文件,则显示一个错误框,并直接退出。要建立 text 文件,使用 ecreateT()。

示例

#include <diskio.hpp>

FILE *fp = ecreate("c:\\temp\\newbinfile.exe");

5.15.4 eclose

定义

idaman void ida_export

eclose(FILE *fp)

含义

关闭 FILE 指针*fp 表示的文件。如果无法关闭文件,则显示一个错误框,并直接退出。

示例

#include <diskio.hpp>

// Open the file first.

FILE *fp = openR("c:\\temp\\binfile.exe");

// Close it

eclose(fp);

5.15.5 eread

定义

idaman void ida_export

eread(FILE *fp, void *buf, sszie_t size)

含义

读取 FILE 指针*fp 所表示文件的 size 个字节数据,保存到缓冲区*buf。如果读取不成功,将显示一个错误框,然后退出 IDA。

示例

#include <diskio.hpp>

char buf[MAXSTR];

// Open the text file

FILE *fp = openRT("c:\\temp\\txtfile.txt");

// Read MAXSTR bytes from the start of the file.

eread(fp, buf, MAXSTR-1);

eclose(fp);

5.15.6 ewrite

定义

idaman void ida_export

ewrite(FILE *fp, const void *buf, ssize_t size)

含义

写入*buf 的 size 个字节到 FILE 指针*fp 所表示文件中。如果写入不成功,将显示一个错误框,然后退出 IDA。

示例

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

#include <bytes.hpp> // For get_many_bytes()

#include <diskio.hpp>

char buf[MAXSTR];

ea_t saddr, eaddr;

// Create the binary dump file

FILE *fp = ecreate("c:\\bindump");

// Get the address range selected, or return false if

// there was no selection

if (read_selection(&saddr, &eaddr)) {

int size = eaddr - saddr;

// Dump the selected address range to a binary file

get_many_bytes(saddr, buf, size);

ewrite(fp, buf, size);

}

eclose(fp);

发布评论

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

词条统计

浏览:0 次

字数:3615

最后编辑:1 个月前

最近更新:JSmiles

编辑次数:0 次

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