PE文件结构及其加载机制(二)

在学习之前,我们来看看上次的进度

以及对应的结构体

typedef struct _IMAGE_OPTIONAL_HEADER {
  WORD                 Magic;
  BYTE                 MajorLinkerVersion;
  BYTE                 MinorLinkerVersion;
  DWORD                SizeOfCode;
  DWORD                SizeOfInitializedData;
  DWORD                SizeOfUninitializedData;
  DWORD                AddressOfEntryPoint;
  DWORD                BaseOfCode;
  DWORD                BaseOfData;
  DWORD                ImageBase;
  DWORD                SectionAlignment;
  DWORD                FileAlignment;
  WORD                 MajorOperatingSystemVersion;
  WORD                 MinorOperatingSystemVersion;
  WORD                 MajorImageVersion;
  WORD                 MinorImageVersion;
  WORD                 MajorSubsystemVersion;
  WORD                 MinorSubsystemVersion;
  DWORD                Win32VersionValue;
  DWORD                SizeOfImage;
  DWORD                SizeOfHeaders;
  DWORD                CheckSum;
  WORD                 Subsystem;
  WORD                 DllCharacteristics;
  DWORD                SizeOfStackReserve;
  DWORD                SizeOfStackCommit;
  DWORD                SizeOfHeapReserve;
  DWORD                SizeOfHeapCommit;
  DWORD                LoaderFlags;
  DWORD                NumberOfRvaAndSizes;
  IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;

同样的,我们先在msdn中查看下这个结构体

第一个值,表示文件的格式,它可能的值有

IMAGE_NT_OPTIONAL_HDR_MAGIC,这个值包括两个值,分别为IMAGE_NT_OPTIONAL_HDR32_MAGICIMAGE_NT_OPTIONAL_HDR64_MAGIC,分别表示是32位的应用程序和64位的应用程序,具体的十六进制值为0x10b和0x20b。

还有一个值是IMAGE_ROM_OPTIONAL_HDR_MAGIC,表示这是一个ROM文件,其值为0x107。

总结为一张图

对于这个文件,它的值是

表示32位的应用程序。

第二个值是MajorLinkerVersion,表示主版本号的链接器,这个值一般来说是不重要的。

对于这个文件,它的值为

第三个值是MinorLinkerVersion,表示次版本号的连接器,这个值一般来说是不重要的。

它的值

第四个值是SizeOfCode,表示The size of the code section, in bytes, or the sum of all such sections if there are multiple code sections.

代码段的总大小,单位为字节,如果是多个部分,则表示它们的总和。

94208字节,即92kb。

第五个值是SizeOfInitializedData,表示所有含已初始化数据的节的大小。

The size of the initialized data section, in bytes, or the sum of all such sections if there are multiple initialized data sections.

77824字节,76kb。

第六个值是SizeOfUninitializedData,表示未初始化数据的节的大小。

The size of the uninitialized data section, in bytes, or the sum of all such sections if there are multiple uninitialized data sections.

第七个值是AddressOfEntryPoint,表示程序的入口点。

A pointer to the entry point function, relative to the image base address. For executable files, this is the starting address. For device drivers, this is the address of the initialization function. The entry point function is optional for DLLs. When no entry point is present, this member is zero.

我们用PEiD来看看这个值

如果看过《C++反汇编与逆向分析技术揭秘》的童鞋就会知道,PEiD是如何工作的。

第八个值是BaseOfCode,表示代码段的起始RVA。

即RVA为00001000,如果加上ImageBase的话,就可以知道这个位置在内存中的位置为00401000,我们用OD打开这个程序看看

第九个值是BaseOfData,表示数据段的起始RVA。

同样,我们用OD来查看下,00018000+00400000=00418000

第十个值是ImageBase,表示程序的建议装载地址。

用PEiD查看

posted @ 2012-09-03 18:38  r3call  阅读(4664)  评论(0编辑  收藏  举报