【问题标题】:Finding a function in a disassembly在反汇编中查找函数
【发布时间】:2010-10-10 15:06:34
【问题描述】:

我正忙于学习一个教程,作者使用 DUMPBIN 列出导出,并使用 OllyDbg 获取导出函数的汇编代码。鉴于导出表 RVA 与反汇编中的实际地址不对应,我如何在完整的反汇编中找到函数代码。

【问题讨论】:

  • 只是出于好奇,哪个教程?
  • 这是逆向的一部分:逆向工程的秘密,Eldad Eilam。关于逆向工程 IA-32 Windows 应用程序的一些开创性的工作。他的首要目标是培养使用最少的工具阅读“死”列表的技能。

标签: debugging assembly reverse-engineering portable-executable


【解决方案1】:

RVA 是可重定位的虚拟地址。要在进程空间中找到真正的地址,您需要知道在进程中加载​​模块的基地址。将该基地址添加到 RVA,您就有了真实地址。我没有使用过 ollydbg,但如果它没有为在它所连接的进程中加载​​的模块提供基地址,我会感到震惊。如果由于某种原因它没有提供该信息,您可以使用 sysinternal 工具中的 procexp.exe 来获取它。

【讨论】:

    【解决方案2】:

    一个很好的函数指标,至少对于用高级语言编写的程序来说是设置堆栈帧的代码。

    如果您知道用于生成相关代码的编译器,您应该能够找出要查找的内容。

    例子

    $ cat main.c
    int main(int argc, char **argv) {
            return 1;
    }
    $ gcc -m32 -S main.c
    $ cat main.s 
            .file     "main.c"
            .text
    .globl main
            .type    main, @function
    main:
            leal     4(%esp), %ecx
            andl     $-16, %esp
            pushl    -4(%ecx)
            pushl    %ebp
            movl     %esp, %ebp
            pushl    %ecx
            movl     $1, %eax
            popl     %ecx
            popl     %ebp
            leal     -4(%ecx), %esp
            ret
            .size    main, .-main
            .ident   "GCC: (Debian 4.3.3-4) 4.3.3"
            .section    .note.GNU-stack,"",@progbits
    

    在我的示例中,movl %esp, %ebp 指令是该设置代码的最后一条指令。

    可以下载free-as-in-beer version 的商业反汇编程序IDA Pro 在自动查找函数方面做得很好。

    【讨论】:

    • 我有免费的 IDA Pro,它非常棒,但我在这方面坚持书作者的意见并“冷处理”。正如您的回答所暗示的,我不是在寻找任何功能,而是在寻找特定的导出。你在这里显示的这种奇怪的语言是什么,我只知道 Windows,:-)
    • “奇怪的语言”只是从 Unix shell 会话中复制和粘贴的文本,“$”是提示符。正在编译为 x86 程序集的最小 C 程序。
    • 奇怪的语言是 AT&T 符号 ;-)
    【解决方案3】:

    如果使用 radare2 ,您可以使用 -AA 标志以二进制形式(可能)分析函数,然后使用 afl 命令列出所有函数。例如:

    % r2 -AA hello
    [Cannot analyze at 0x00400420g with sym. and entry0 (aa)
    [x] Analyze all flags starting with sym. and entry0 (aa)
    [Cannot analyze at 0x00400420ac)
    [x] Analyze function calls (aac)
    [x] Analyze len bytes of instructions for references (aar)
    [x] Check for objc references
    [x] Check for vtables
    [x] Type matching analysis for all functions (aaft)
    [x] Propagate noreturn information
    [x] Use -AA or aaaa to perform additional experimental analysis.
    [x] Finding function preludes
    [x] Enable constraint types analysis for variables
    -- Greetings, human.
    [0x00400430]> afl
    0x00400430    1 41           entry0
    0x00400410    1 6            sym.imp.__libc_start_main
    0x00400460    4 50   -> 41   sym.deregister_tm_clones
    0x004004a0    4 58   -> 55   sym.register_tm_clones
    0x004004e0    3 28           entry.fini0
    0x00400500    4 38   -> 35   entry.init0
    0x004005b0    1 2            sym.__libc_csu_fini
    0x004005b4    1 9            sym._fini
    0x00400540    4 101          sym.__libc_csu_init
    0x00400526    1 21           main
    0x00400400    1 6            sym.imp.puts
    0x004003c8    3 26           sym._init
    [0x00400430]>
    

    radare2->Cutter 的 Windows 版本

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-23
      • 2021-03-04
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-30
      相关资源
      最近更新 更多