如何使用其标头确定准确的 PE 图像文件大小?
我需要字节大小,IMAGE_OPTIONAL_HEADER.SizeOfImage 似乎四舍五入到(不确定)边界并且大于实际文件大小。
I need byte size, IMAGE_OPTIONAL_HEADER.SizeOfImage appears to be rounded up to (unsure) boundary and is greater than real file size.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
IMAGE_OPTIONAL_HEADER.SizeOfImage
是虚拟内存中加载的可执行文件/dll 的大小。它与磁盘上的大小不同。
您可以使用上一节的
VirtualAddress + VirtualSize
来计算它。IMAGE_OPTIONAL_HEADER.SizeOfImage
是向上舍入到IMAGE_OPTIONAL_HEADER.SectionAlignment
的值(通常与页面大小相同)的值。IMAGE_OPTIONAL_HEADER.SizeOfImage
is the size of the loaded executable/dll in virtual memory.It is not the same as the size on disk.
You can calculate it with
VirtualAddress + VirtualSize
of the last section.IMAGE_OPTIONAL_HEADER.SizeOfImage
is that value rounded up to the value ofIMAGE_OPTIONAL_HEADER.SectionAlignment
(usually the same as the page size).事实上,接受的答案是不正确的。要获取可执行文件在磁盘上的大小,您应该计算最后一部分的 PointerToRawData + SizeOfRawData,而不是虚拟对应部分。有关示例,请参阅 http://www.strchr.com/creating_self-extracting_executables
另请注意,某些编译器喜欢在最后一节之后附加调试信息。请务必删除任何符号表或设置发布模式,具体取决于您使用的编译器,才能使其正常工作。
Actually, the accepted answer is incorrect. To get the executable's size on disk, you should calculate
PointerToRawData
+SizeOfRawData
of the last section, not the virtual counterparts. For an example see http://www.strchr.com/creating_self-extracting_executablesAlso note that some compilers like to append debug information after the last section. Be sure to strip any symbol tables or set release mode, depending on what compiler you use, for this to work.