windows - PE : Relation between SizeOfRawData and VirtualSize fields of the section header

标签 windows assembly windows-10 portable-executable

我看到对于图像文件中的部分,VirtualSize 字段是加载到内存中时部分的总大小,而 SizeOfRawData 字段是部分的大小磁盘上的初始化数据。

在检查 .idata 部分时,VirtualSize 字段设置为 0x14,而 SizeOfRawData 字段设置为 0x400。

为什么链接器 - 在本例中为 MinGW ld - 使文件部分如此之大,而加载到内存中的部分只是其大小的一小部分?

此外,VirtualSize 字段的用途是什么?为什么不总是加载整个部分,即加载 SizeOfRawData 字节?

我在官方 PE 文档中没有看到描述或它们之间的关系。

最佳答案

SizeOfRawData(图像文件中原始数据部分的大小)总是多个 IMAGE_OPTIONAL_HEADER.FileAlignment

文件对齐

The alignment of the raw data of sections in the image file, in bytes. The value should be a power of 2 between 512 and 64K (inclusive). The default is 512. If the SectionAlignment member is less than the system page size, this member must be the same as SectionAlignment.

VirtualSize 字段的目的是为段分配和复制多少内存。没有这个字段,加载器怎么知道这个?

VirtualSize 可以大于或小于 SizeOfRawData

例如,我们可以在部分中只有几个字节的初始化实际数据并且没有未初始化的数据 - 所以 VirtualSize 将只有几个字节大小,而 SizeOfRawData 512 字节

在另一种情况下,在 .data.bss 部分 - 可能根本没有初始化数据(因此 SizeOfRawData == 0)但是虚拟大小 != 0.

所以加载器分配 (VirtualSize + SectionAlignment - 1) & ~(SectionAlignment-1) 字节给 section 并复制 min(VirtualSize, SizeOfRawData) 字节给它文件

关于windows - PE : Relation between SizeOfRawData and VirtualSize fields of the section header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38975070/

相关文章:

windows - 触摸屏模拟器 : Are there any windows simulator to test application in touch screen environment

ruby - 用 Ruby 做原生 GUI

assembly - 为什么我在 GDB 上出现断点问题? GDB 停止

python - pip - 即使成功安装后也没有名为 'pip' 的模块

Powershell在运行命令时变黑

c# - 当用户尝试打开一个新实例时返回到一个已经打开的应用程序

linux - 该内核需要 x86-64 CPU,但仅检测到 i686 CPU

assembly - 是否有已弃用的 x86 指令列表?

assembly - 我的标志标志值显示错误?我对标志旗的工作原理有误解吗?

visual-studio-2015 - Windows 10和Visual Studio 2015