【发布时间】:2012-12-04 22:44:22
【问题描述】:
在使用具有 4 个字节的文件对齐和节对齐的压缩 PE(Windows 控制台 EXE)时,我注意到如果节的虚拟大小和原始大小匹配,则程序加载,但如果虚拟大小为数据部分(最后一部分)不匹配,然后 Windows 拒绝加载它,即使按照规范,您应该能够拥有大于原始大小的虚拟大小。
这是对压缩 PE 的某种隐藏约束吗?
我已经在下面粘贴了一个 exe 的 dumpbin /headers:
Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file ba42x.exe
PE signature found
File Type: EXECUTABLE IMAGE
FILE HEADER VALUES
14C machine (x86)
2 number of sections
50AABC14 time date stamp Mon Nov 19 18:09:08 2012
0 file pointer to symbol table
0 number of symbols
60 size of optional header
10F characteristics
Relocations stripped
Executable
Line numbers stripped
Symbols stripped
32 bit word machine
OPTIONAL HEADER VALUES
10B magic # (PE32)
2.03 linker version
BD0 size of code
5000 size of initialized data
0 size of uninitialized data
CC entry point (004000CC)
CC base of code
C9C base of data
400000 image base (00400000 to 00403FFF)
4 section alignment
4 file alignment
4.00 operating system version
0.00 image version
4.00 subsystem version
0 Win32 version
4000 size of image
CC size of headers
0 checksum
3 subsystem (Windows CUI)
0 DLL characteristics
10000 size of stack reserve
1000 size of stack commit
0 size of heap reserve
0 size of heap commit
0 loader flags
0 number of directories
SECTION HEADER #1
.text name
BD0 virtual size
CC virtual address (004000CC to 00400C9B)
BD0 size of raw data
CC file pointer to raw data (000000CC to 00000C9B)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
E0000020 flags
Code
Execute Read Write
SECTION HEADER #2
.data name
3102 virtual size
C9C virtual address (00400C9C to 00403D9D)
3102 size of raw data
C9C file pointer to raw data (00000C9C to 00003D9D)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
C0000040 flags
Initialized Data
Read Write
Summary
3104 .data
BD0 .text
例如,如果您将上述 .data 部分的虚拟大小更改为 3106,则程序将不会加载,即使初始化数据 (0x5000) 的大小足以容纳额外的内存。
【问题讨论】:
-
Pericin 和 Vuksan 指出,对于平面内存模型(又名低对齐模式),所有物理地址都需要与其对应的物理地址匹配。也许这就是 virtualsize 和 rawsize 也需要匹配的原因? sebug.net/paper/Meeting-Documents/hitbsecconf2012ams/…(见幻灯片 25)
-
我的处境相似:尝试手工制作有效的 PE 图像文件。你解决问题了吗?
标签: c windows linker executable portable-executable