【问题标题】:C program that, after compiling and linking, results in an EXE file that contains an edata section?C 程序,在编译和链接后,会生成一个包含 edata 部分的 EXE 文件?
【发布时间】:2019-03-07 12:10:44
【问题描述】:

我正在审查关于可移植可执行文件(EXE 文件)的 Microsoft 规范。特别是,我正在审查 .edata(导出数据)部分。这里是what the specification says about the edata section

名为 .edata 的导出数据部分包含有关 其他图像可以通过动态链接访问的符号。出口 符号一般存在于 DLL 中,但 DLL 也可以导入符号。

非 DLL 文件可以有 edata 部分吗?具体来说,C 程序是否可以在编译和链接后生成包含 edata 节的 EXE 文件?如果是,请您展示一个简单的 C 程序,该程序在编译和链接后会生成一个包含 edata 部分的 EXE 文件?

【问题讨论】:

  • 在第一个部分名称根本没有任何作用。任何PE都可以有导出表,有什么问题?
  • 导出数据部分,名为 .edata - 这是错误的。 IMAGE_EXPORT_DIRECTORY数据目录不是一个section,可以属于任意一个section,任意名字

标签: c compilation executable portable-executable


【解决方案1】:

任何 PE 映像文件都可能包含导出表,无论它是 EXE 还是 DLL。但是,导出表不一定包含在.edata 部分中。例如,在.rdata 部分中看到导出表是很常见的。

要定位导出表,你应该使用导出表数据目录,而不是完全依赖Section Table。

以下是一个示例 C 程序,编译后将生成一个带有导出表的 EXE。但是,它可能不会放在 .edata 部分中(并且 EXE 可能根本没有 .edata 部分)。

#include <stdio.h>

__declspec(dllexport) void some_func(void)
{
    printf("Hello\n");
    return;
}

int main()
{
    return 0;
}

当我在我的系统上使用 Visual Studio 2017 编译此程序并在生成的 EXE 上运行 dumpbin /HEADERS /EXPORTS 时,我看到以下内容:

...

SECTION HEADER #3
  .rdata name
    2A94 virtual size
   19000 virtual address (0000000140019000 to 000000014001BA93)
    2C00 size of raw data
    7E00 file pointer to raw data (00007E00 to 0000A9FF)
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
40000040 flags
         Initialized Data
         Read Only

...


  Section contains the following exports for SampleApp.exe

    00000000 characteristics
    FFFFFFFF time date stamp
        0.00 version
           1 ordinal base
           1 number of functions
           1 number of names

    ordinal hint RVA      name

          1    0 0001108C some_func = @ILT+135(some_func)

在这种情况下,确认导出表已放入 .rdata 部分。

【讨论】:

  • 谢谢@Erlend Graff - 太棒了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多