上次我们学习了IMAGE_OPTIONAL_HEADER的前十个参数,下面我们继续学习。
第十一个值SectionAlignment,表示节对齐粒度。这个值一定要大于或等于文件对齐粒度。
The alignment of sections loaded in memory, in bytes. This value must be greater than or equal to the FileAlignment member.
The default value is the page size for the system.
原来是4096B,也就是4kb了。
第十二个值是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.
这个值应该是512B的倍数。
第十三个值是MajorOperatingSystemVersion,所需操作系统的主版本号。
The major version number of the required operating system.
第十四个值是MinorOperatingSystemVersion,所需操作系统的副版本号。
The minor version number of the required operating system.
第十五个值是MajorImageVersion
The major version number of the image.
第十六个值是MinorImageVersion
The minor version number of the image.
第十七个值是MajorSubsystemVersion
The major version number of the subsystem.
第十八个值为MinorSubsystemVersion
The minor version number of the subsystem.
第十九个值为Win32VersionValue,保留值,且必须为零。
This member is reserved and must be 0.
第二十个值为SizeOfImage,4个字节,表示程序调入后占用内存大小(字节),等于所有段的长度之和。
The size of the image, in bytes, including all headers. Must be a multiple of SectionAlignment.
0x2B000=?
好吧,两三天了,终于弄明白这个值了,由于在实验过程中,为了防止意外,所以复制了一个副本在当前文件夹下,通过二进制的对比,发现这两个文件的SizeOfImage值是不一样的,所以走了弯路。
既然错了文件,那么我还是以这个文件为例吧,因为其他的部分都一样,所以就不修改其他的部分了。
0x25000+0x5188=0x2A188,再考虑内存对齐,我们试着用这个值除以对齐粒度0x1000,看是否能除尽。
结果是不能除尽,所以要求大一点,结果这个SizeOfImage就变成了0x2B000。
第二十一个值为SizeOfHeaders,占用4个字节,表示所有头加节表的大小。
The combined size of the following items, rounded to a multiple of the value specified in the FileAlignment member.
- 4 byte signature
- size of IMAGE_FILE_HEADER
- size of optional header
- size of all section headers
也就是0x1000了。
第二十二个值为CheckSum,占用四个字节。
The image file checksum. The following files are validated(验证) at load time: all drivers, any DLL loaded at boot time, and any DLL loaded into a critical (关键)system process.
第二十三个值为Subsystem,占用两个字节。表示文件运行所需的子系统。
The subsystem required to run this image. The following values are defined.
Value | Meaning |
---|---|
|
Unknown subsystem. |
|
No subsystem required (device drivers and native system processes). |
|
Windows graphical user interface (GUI) subsystem. |
|
Windows character-mode user interface (CUI) subsystem. |
|
OS/2 CUI subsystem. |
|
POSIX CUI subsystem. |
|
Windows CE system. |
|
Extensible Firmware Interface (EFI) application. |
|
EFI driver with boot services. |
|
EFI driver with run-time services. |
|
EFI ROM image. |
|
Xbox system. |
|
Boot application. |
第二十四个值为DllCharacteristics,占用两个字节。表示dll文件的属性值。
The DLL characteristics of the image. The following values are defined.
Value | Meaning |
---|---|
|
Reserved.(保留) |
|
Reserved. |
|
Reserved. |
|
Reserved. |
|
The DLL can be relocated at load time.(允许在载入的时候进行重定位) |
|
Code integrity checks are forced. If you set this flag and a section contains only uninitialized data, set the PointerToRawData member of IMAGE_SECTION_HEADER for that section to zero; otherwise, the image will fail to load because the digital signature cannot be verified. |
|
The image is compatible(兼容) with data execution prevention (DEP). |
|
The image is isolation(隔离) aware, but should not be isolated. |
|
The image does not use structured exception handling (SEH). No handlers can be called in this image. |
|
Do not bind the image. |
|
Reserved. |
|
A WDM driver. |
|
Reserved. |
|
The image is terminal server aware. |
第二十五个值为SizeOfStackReserve,占用4个字节。表示初始化是的堆栈大小。
The number of bytes to reserve for the stack. Only the memory specified by the SizeOfStackCommit member is committed at load time; the rest is made available one page at a time until this reserve size is reached.
0x00100000=1MB
第二十六个值为SizeOfStackCommit,占用四个字节。表示初始化时实际提交的堆栈大小。
The number of bytes to commit for the stack.
0x1000字节=4kb
第二十七个值为SizeOfHeapReserve,占用四个字节。初始化时保留堆的大小。
The number of bytes to reserve for the local heap. Only the memory specified by the SizeOfHeapCommit member is committed at load time; the rest is made available one page at a time until this reserve size is reached.
第二十八个值为SizeOfHeapCommit,占用四个字节。初始化时实际提交的堆得大小。
The number of bytes to commit for the local heap.
第二十九个值为LoaderFlags,占用4个字节。未使用。
This member is obsolete.
第三十个值为NumberOfRvaAndSizes,占用四个字节。表示下面个成员数据目录结构的数量。
这个值一般就直接是16.
下面是最后一个成员DataDirectory,占用128个字节,为一个IMAGE_DATA_DIRECTORY structure结构体数组(16个)。
A pointer to the first IMAGE_DATA_DIRECTORY structure in the data directory.
typedef struct _IMAGE_DATA_DIRECTORY { DWORD VirtualAddress; DWORD Size; } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
这个结构体有两个成员,一个成员占用4个字节,也就是8个字节。这个数组有16个数据,也就是16*8=128字节。
我们来看第一个。
IMAGE_DIRECTORY_ENTRY_EXPORT 导出表
这个程序没有导出函数,所以没有导出表。
第二个IMAGE_DIRECTORY_ENTRY_IMPORT 导入表
这个程序需要用到dll中的函数
我们用PEiD来查看下
结果是一样的。这个是RVA,表示偏移地址哦。
第三个IMAGE_DIRECTORY_ENTRY_RESOURCE 资源目录
从上面这张图也可以看出。RVA为00025000,大小为5188byte
第四个IMAGE_DIRECTORY_ENTRY_EXCEPTION 异常目录
未使用。
第五个 IMAGE_DIRECTORY_ENTRY_SECURITY 安全目录
第六个 IMAGE_DIRECTORY_ENTRY_BASERELOC 重定位表
第七个 IMAGE_DIRECTORY_ENTRY_DEBUG 调试信息
第八个 IMAGE_DIRECTORY_ENTRY_COPYRIGHT 版权信息
第九个 IMAGE_DIRECTORY_ENTRY_GLOBALPTR
第十个 IMAGE_DIRECTORY_ENTRY_TLS 线程的本地存储器
第十一个 IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 载入配置目录
Load configuration table address and size
第十二个 IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 绑定导入表地址和大小
Bound import table address and size
第十三个 IMAGE_DIRECTORY_ENTRY_IAT 导入函数地址表Import Address Table
Import address table address and size
用Exeinfo PE 查看
第十四个 IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT
Delay import descriptor address and size
第十五个 IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR
The CLR header address and size
第十六个 IMAGE_NUMBEROF_DIRECTORY_ENTRIES 保留值
到此,整个PE文件头结束了。