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查看

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章