【问题标题】:How to determine RVA of AddressOfEntryPoint from PE Headers Using Dumpbin如何使用 Dumpbin 从 PE 标头中确定 AddressOfEntryPoint 的 RVA
【发布时间】:2013-01-08 00:26:50
【问题描述】:

我一直在网上搜索试图找到这个问题的答案,但它似乎在逃避我。在问这个问题之前,我已经咨询了以下来源。

我了解 PE 格式(或者至少我认为我了解)。使用命令行调试器 (cdb),我希望能够反汇编 RVA 所在的地址,以查看第一个调用是什么。对于本机应用程序(如记事本),我希望看到 notepad!WinMainCRTStartup,对于 .NET 应用程序,我希望看到 CLR 的 jmp 命令。

以记事本为例,我在上面执行了dumpbin /headers,得到的入口点值为3570。当我执行 cdb notepad 并执行此命令 - u [内存中的基地址]+0x3570 - 我没有收到 WinMainCRTStartup 调用。

我是否误解了 dumpbin 的 PE 输出?我如何才能确切地知道在内存中的何处查找应用程序的启动功能?

编辑(1/7/13):我忘了提到我在 64 位 Windows 7 上运行它。如果我尝试在 Windows XP 模式下使用 cdb(从一个 32 位操作系统),反汇编我从 PE 文件分析中获得的 AddressOfEntryPoint 让我得到了对 WinMainCRTStartup 的调用,正如我所期望的那样。换句话说,我被告知要查看的确切地址包含我认为在 32 位操作系统中应该看到的地址。在 64 位机器上运行应用程序真的会有这么大的不同吗?

只是为了增加复杂性,如果我在 cdb 的 64 位操作系统中对 ImageBaseAddress 执行 !dh,我会得到我需要使用的 EXACT AddressOfEntryPoint。

【问题讨论】:

    标签: debugging windbg portable-executable


    【解决方案1】:

    使用 Microsoft 符号服务器获取符号调试信息。 http://support.microsoft.com/kb/311503/en-us

    0:001> !dh -a notepad
        ....
        3689 address of entry point
        ...
        00ac0000 image base
        ...
    0:001> u ac3689 
    notepad!WinMainCRTStartup:
    

    编辑:添加dumpbin输出(入口点相同的偏移量,图像库可能不同,因为ASLR在图像加载到内存时起作用):

    Microsoft (R) COFF/PE Dumper Version 11.00.50727.1
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    
    Dump of file c:\windows\notepad.exe
    
    PE signature found
    
    File Type: EXECUTABLE IMAGE
    
    FILE HEADER VALUES
                 14C machine (x86)
                   4 number of sections
            4A5BC60F time date stamp Tue Jul 14 03:41:03 2009
                   0 file pointer to symbol table
                   0 number of symbols
                  E0 size of optional header
                 102 characteristics
                       Executable
                       32 bit word machine
    
    OPTIONAL HEADER VALUES
                 10B magic # (PE32)
                9.00 linker version
                A800 size of code
               22400 size of initialized data
                   0 size of uninitialized data
                3689 entry point (01003689) _WinMainCRTStartup
    

    Edit 2为 x64 添加输出

    垃圾箱:

    Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    
    Dump of file c:\windows\notepad.exe
    
    PE signature found
    
    File Type: EXECUTABLE IMAGE
    
    FILE HEADER VALUES
                8664 machine (x64)
                   6 number of sections
            4A5BC9B3 time date stamp Tue Jul 14 03:56:35 2009
                   0 file pointer to symbol table
                   0 number of symbols
                  F0 size of optional header
                  22 characteristics
                       Executable
                       Application can handle large (>2GB) addresses
    
    OPTIONAL HEADER VALUES
                 20B magic # (PE32+)
                9.00 linker version
                A800 size of code
               25800 size of initialized data
                   0 size of uninitialized data
                3570 entry point (0000000100003570) WinMainCRTStartup
    

    windbg:

        0:000> !dh -a notepad
    
        File Type: EXECUTABLE IMAGE
        FILE HEADER VALUES
            8664 machine (X64)
            ...
            1000 base of code
                 ----- new -----
        00000000ff0c0000 image base
        ...
    0:000> u ff0c0000+3570
    notepad!WinMainCRTStartup:
    

    【讨论】:

    • 感谢您回复 sergmat。当我启动调试器时,我一直在做 .symfix 和 .reload 。调试器中基地址上的 !dh 显示正确的 AddressOfEntryPoint 是完全正确的。您从技术上回答了我的问题,即我如何确切地知道在内存中查找真正的起始函数的位置。非常感谢你!作为后续,为什么这与 dumpbin(或其他 PE 分析器)显示的地址不同?
    • 在答案中添加了 dumpbin 输出。
    • 您在哪个版本的 Windows 上执行此操作?什么架构?
    • \Windows 和 \Windows\System32 中的 Notepad.exe 版本似乎存在差异。当我指定可执行文件的路径时,我得到了 PE 输出和调试器中的信息之间的匹配。留下一条路对你有什么好处!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-06
    相关资源
    最近更新 更多