0%

PE结构-DOS头

PE结构-DOS头,本部分为参照吾爱破解论坛lyl610abc师傅PE文件笔记所整理的学习笔记。

DOS部首

DOS部首结构

其结构分为两部分:

  1. DOS ‘MZ’ HEADER 其在c中定义的结构体为_IMAGE_DOS_HEADER
  2. DOS sub

image-20211119195942676

DOS MZ头

DOS MZ头在C语言中所定义的结构体为:

定义于winnt.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
WORD e_magic; // Magic number
WORD e_cblp; // Bytes on last page of file
WORD e_cp; // Pages in file
WORD e_crlc; // Relocations
WORD e_cparhdr; // Size of header in paragraphs
WORD e_minalloc; // Minimum extra paragraphs needed
WORD e_maxalloc; // Maximum extra paragraphs needed
WORD e_ss; // Initial (relative) SS value
WORD e_sp; // Initial SP value
WORD e_csum; // Checksum
WORD e_ip; // Initial IP value
WORD e_cs; // Initial (r elative) CS value
WORD e_lfarlc; // File address of relocation table
WORD e_ovno; // Overlay number
WORD e_res[4]; // Reserved words
WORD e_oemid; // OEM identifier (for e_oeminfo)
WORD e_oeminfo; // OEM information; e_oemid specific
WORD e_res2[10]; // Reserved words
LONG e_lfanew; // File address of new exe header
} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;

分析_IMAGE_DOS_HEADER成员

DOS头的存在,是为了往下兼容在低版本DOS系统上运行,所以该部分主要用于DOS系统

目前在32/64位Windows操作系统中还有效的成员只有两个

  • 第一个成员:e_magic (WORD 2字节) 用于识别文件是否为PE格式文件 值固定为4d 5a (MZ)
  • 最后一个成员: e_lfanew (LONG 4字节) 存储PE头首地址 位于0x3c位置

DOS部首中的其他值已经在现阶段Windows系统中弃用,下面通过将对应值置换为0,验证其无效性:

利用16进制编辑器打开Everedit.exe程序,将DOS部首除e_magice_lfanew之外的DOS部首成员选中清零

image-20211119201606255

image-20211119201720010

另存为新文件后仍能正常使用,确认DOS部首其他值已在Windows平台弃用。