generate_disasm_line 以及 generate_disassembly

但从字面上也很容易理解这两个函数的意思,但是事实在实际使用的时候效果却并不是想要的那样。 sad

idaman int ida_export generate_disassembly(
                                // Generate disassembly (many lines)
                                // and put them into a buffer
                                // Returns number of generated lines
        ea_t ea,                // address to generate disassembly for
        char *lines[],          // buffer to hold pointer to generated lines
        int bufsize,            // size of buffer
        int *lnnum,             // number of "the most interesting" line
                                // may be NULL
        bool as_stack);         // Display undefined items as 2/4/8 bytes

idaman bool ida_export generate_disasm_line(
                                // Generate one line of disassembly
                                // This function discards all "non-interesting" lines
                                // It is designed to generate one-line desriptions
                                // of addresses for lists, etc.
        ea_t ea,                // address to generate disassembly for
        char *buf,              // pointer to the output buffer
        size_t bufsize,         // size of the output buffer
        int flags=0);
#define GENDSM_FORCE_CODE 1     // generate a disassembly line as if
                                // there is an instruction at 'ea'
#define GENDSM_MULTI_LINE 2     // if the instruction consists of several lines,
                                // produce all of them (useful for parallel instructions)


上面是两个函数的定义,按照我的理解, generate_disassembly应该是生成从ea开始的bufsize大小的反汇编代码,但是实际在使用的时候却发现这个函数只能生成光标所在行的代码,和generate_disasm_line并没有太多的区别。
唯一的区别在于如果是从函数起始地址开始生成代码的话generate_disasm_line不会包含变量的定义,例如下面的代码

得到的代码将会是下面的样子:

00403A40 mov     eax, [esp+arg_0]

而如果使用 generate_disassembly得到的代码将会是下面的样子:

.text:00403A40 sub_403A40 proc near
.text:00403A40
.text:00403A40 arg_0= dword ptr  4
.text:00403A40
.text:00403A40 mov     eax, [esp+arg_0

测试代码如下:

		char clean_buf[MAXSTR];
		int nlines = generate_disassembly( get_screen_ea(),myLines,max_lines,&lnnum,MAKELINE_STACK);
		for ( int j=0; j

所以有的东西并不是看起来那样子,使用以下发现完全不是自己想要的效果。嘎嘎。
 

  😉 smile

☆版权☆

* 网站名称:obaby@mars
* 网址:https://h4ck.org.cn/
* 个性:https://oba.by/
* 本文标题: 《generate_disasm_line 以及 generate_disassembly》
* 本文链接:https://h4ck.org.cn/2012/06/4221
* 短链接:https://oba.by/?p=4221
* 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。


猜你喜欢:

3 comments

  1. Level 1
    Internet Explorer 6 Internet Explorer 6 Windows XP Windows XP cn河南省商丘市 电信

    请教一个问题, ida提供的sdk中有汇编功能的函数吗? 类似assemble(), 不是反汇编. 因为我翻遍sdk的头文件没有类似assemble的函数. 我只是用了关键字查找, 不知道是否有这类函数. 那么Patch Program功能汇编输入的指令是如何实现呢, 还有idapython中的idaapi.assemble似乎是这样的函数, 但是它又调用的哪个sdk函数呢? 感谢.

    1. 公主 Queen 
      Opera 12 Opera 12 Windows 7 Windows 7 cn福建省厦门市 电信

      python 最终调用的是idc的接口,你可以看下那个接口对应的idc函数,这个和sdk里面的比较相似。

  2. Level 1
    Internet Explorer 6 Internet Explorer 6 Windows XP Windows XP cn河南省商丘市 电信

    谢谢你回答, 我查看了idaapi.py. 找了好像相关的定义
    def assemble(*args):
    “””assemble(ea_t ea, ea_t cs, ea_t ip, bool use32, char line) -> bool”””
    return _idaapi.assemble(*args)
    又找到此处
    _mod = imp.load_module(‘_idaapi’, fp, pathname, description)
    找不出此assemble究竟是调用了哪个idc函数. 不知道解决思路可对
    另外我用chrome无法留言提示”Unreadable CAPTCHA Token File”

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注