PE结构各字段偏移参考

The Dos Header

OFFSET

SIZE

NAME

EXPLANATION

00

Word

e_magic

Magic DOS signature MZ (4Dh 5Ah)

02

WORD

e_cblp

Bytes on last page of file

04

WORD

e_cp

Pages in file

06

WORD

e_crlc

Relocations

08

WORD

e_cparhdr

Size of header in paragraphs

0A

WORD

e_minalloc

Minimum extra paragraphs needed

0C

WORD

e_maxalloc

Maximum extra paragraphs needed

0E

WORD

e_ss

Initial (relative) SS value

10

WORD

e_sp

Initial SP value

12

WORD

e_csum

Checksum

14

WORD

e_ip

Initial IP value

16

WORD

e_cs

Initial (relative) CS value

18

WORD

e_lfarlc

File address of relocation table

1A

WORD

e_ovno

Overlay number

1C

WORD

e_res[4]

Reserved words

24

WORD

e_oemid

OEM identifIEr (for e_oeminfo)

26

WORD

e_oeminfo

OEM information; e_oemid specific

28

WORD

e_res2[10]

Reserved words

3C

DWORD

e_lfanew

Offset to start of PE header

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 (relative) 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;

The PE Header

Offsets shown are from the beginning of this section.

0DWORDSignaturePE Signature PE.. (50h 45h 00h 00h)
4WORDMachine014Ch = Intel 386, 014Dh = Intel 486, 014Eh = Intel 586, 0200h = Intel 64-bit, 0162h=MIPS
6WORDNumberOfSectionsNumber Of Sections
8DWORDTimeDateStampDate & time image was created by the linker
0CDWORDPointerToSymbolTableZero or offset of COFF symbol table in older files
10DWORDNumberOfSymbolsNumber of symbols in COFF symbol table
14WORDSizeOfOptionalHeaderSize of optional header in bytes (224 in 32bit exe)
16WORDCharacteristicssee below
18**********START OF OPTIONAL HEADER**************************************
180WORDMagic010Bh=32-bit executable image
020Bh=64-bit executable image
0107h=ROM image
1A2BYTEMajorLinkerVersionMajor version number of the linker
1B3BYTEMinorLinkerVersionMinor version number of the linker
1C4DWORDSizeOfCodesize of code section or sum if multiple code sections
208DWORDSizeOfInitializedDataas above
24CDWORDSizeOfUninitializedDataas above
2810DWORDAddressOfEntryPointStart of code execution, optional for DLLs, zero when none present
2C14DWORDBaseOfCodeRVA of first byte of code when loaded into RAM
3018DWORDBaseOfDataRVA of first byte of data when loaded into RAM
341CDWORDImageBasePreferred load address
3820DWORDSectionAlignmentAlignment of sections when loaded in RAM
3C24DWORDFileAlignmentAlignment of sections in file on disk
4028WORDMajorOperatingSystemVersionMajor version no. of required operating system
422AWORDMinorOperatingSystemVersionMinor version no. of required operating system
442CWORDMajorImageVersionMajor version number of the image
462EWORDMinorImageVersionMinor version number of the image
4830WORDMajorSubsystemVersionMajor version number of the subsystem
4A32WORDMinorSubsystemVersionMinor version number of the subsystem
4C34DWORD-Reserved1
5038DWORDSizeOfImageAmount of memory allocated by loader for image. Must be a multiple of SectionAlignment
543CDWORDSizeOfHeadersOffset of first section, multiple of FileAlignment
5840DWORDCheckSumImage checksum (only required for kernel-mode drivers and some system DLLs).
5C44WORDSubsystem0002h=Windows GUI, 0003h=console
5E46WORDDllCharacteristics0001h=per-process library initialization
0002h=per-process library termination
0003h=per-thread library initialization
0004h=per-thread library termination
6048DWORDSizeOfStackReserveNumber of bytes reserved for the stack
644CDWORDSizeOfStackCommitNumber of bytes actually used for the stack
6850DWORDSizeOfHeapReserveNumber of bytes to reserve for the local heap
6C54DWORDSizeOfHeapCommitNumber of bytes actually used for local heap
7058DWORDLoaderFlagsThis member is obsolete.
745CDWORDNumberOfRvaAndSizesNumber of Directory entries.
78**********START OF DATADIRECTORY**************************************
780DWORDIMAGE_DATA_DIRECTORY0RVA of Export Directory
7C4DWORD-size of Export Directory
808DWORDIMAGE_DATA_DIRECTORY1RVA of Import Directory (array of IIDs)
84CDWORD-size of Import Directory (array of IIDs)
8810DWORDIMAGE_DATA_DIRECTORY2RVA of Resource Directory
8C14DWORD-size of Resource Directory
9018DWORDIMAGE_DATA_DIRECTORY3RVA of Exception Directory
941CDWORD-size of Exception Directory
9820DWORDIMAGE_DATA_DIRECTORY4Raw Offset of Security Directory
9C24DWORD-size of Security Directory
A028DWORDIMAGE_DATA_DIRECTORY5RVA of Base Relocation Directory
A42CDWORD-size of Base Relocation Directory
A830DWORDIMAGE_DATA_DIRECTORY6RVA of Debug Directory
AC34DWORD-size of Debug Directory
B038DWORDIMAGE_DATA_DIRECTORY7RVA of Copyright Note
B43CDWORD-size of Copyright Note
B840DWORDIMAGE_DATA_DIRECTORY8RVA to be used as Global Pointer (IA-64 only)
BC44DWORD-Not used
C048DWORDIMAGE_DATA_DIRECTORY9RVA of Thread Local Storage Directory
C44CDWORD-size of Thread Local Storage Directory
C850DWORDIMAGE_DATA_DIRECTORY10RVA of Load Configuration Directory
CC54DWORD-size of Load Configuration Directory
D058DWORDIMAGE_DATA_DIRECTORY11RVA of Bound Import Directory
D45CDWORD-size of Bound Import Directory
D860DWORDIMAGE_DATA_DIRECTORY12RVA of first Import Address Table
DC64DWORD-total size of all Import Address Tables
E068DWORDIMAGE_DATA_DIRECTORY13RVA of Delay Import Directory
E46CDWORD-size of Delay Import Directory
E870DWORDIMAGE_DATA_DIRECTORY14RVA of COM Header (top level info & metadata...
EC74DWORD-size of COM Header     ...in .NET executables)
F078DWORDZERO (Reserved)Reserved
F47CDWORDZERO (Reserved)Reserved
F8**********START OF SECTION TABLE*******Offsets shown from here********
08 BytesName1Name of first section header
8DWORDmisc (VirtualSize)Actual size of data in section
0CDWORDvirtual addressRVA where section begins in memory
10DWORDSizeOfRawDataSize of data on disk (multiple of FileAlignment)
14DWORDpointerToRawDataRaw offset of section on disk
18DWORDpointerToRelocationsStart of relocation entries for section, zero if none
1CDWORDPointerToLinenumbersStart of line-no. entries for section, zero if none
20WORDNumberOfRelocationsThis value is zero for executable images.
22WORDNumberOfLineNumbersNumber of line-number entries for section.
24DWORDCharacteristicssee end of page below
08 BytesName1Name of second section header
**********Repeats for rest of sections**************************************

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[16];
} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
typedef struct _IMAGE_DATA_DIRECTORY {
  DWORD VirtualAddress;
  DWORD Size;
} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;


The Export Table

  Offsets shown from beginning of table (given at offset 78 from start of PE header). The following 40 Bytes repeat for each export library (DLL whose functions are imported by the executable) and ends with one full of zeroes.

OFFSETSIZENAMEEXPLANATION 
0DWORDCharacteristicsSet to zero (currently none defined)
4DWORDTimeDateStampoften set to zero 
8WORDMajorVersionuser-defined version number, otherwise zero
0AWORDMinorVersionas above
0CDWORDNameRVA of DLL name in null-terminated ASCII
10DWORDBaseFirst valid exported ordinal, normally=1 
14DWORDNumberOfFunctionsNumber of entries in EAT
18DWORDNumberOfNamesNumber of entries in ENT
1CDWORDAddressOfFunctionsRVA of EAT (export address table)
20DWORDAddressOfNamesRVA of ENT (export name table)
24DWORDAddressOfNameOrdinalsRVA of EOT (export ordinal table) 

typedef struct _IMAGE_EXPORT_DIRECTORY {
    DWORD   Characteristics;
    DWORD   TimeDateStamp;
    WORD    MajorVersion;
    WORD    MinorVersion;
    DWORD   Name;
    DWORD   Base;
    DWORD   NumberOfFunctions;
    DWORD   NumberOfNames;
    DWORD   AddressOfFunctions;     // RVA from base of image
    DWORD   AddressOfNames;         // RVA from base of image
    DWORD   AddressOfNameOrdinals;  // RVA from base of image
} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;


The Import Table

  Offsets shown from beginning of table (given at offset 80 from start of PE header). The following 5 DWORDS repeat for each import library (DLL whose functions are imported by the executable) and ends with one full of zeroes.
OFFSET SIZE NAMEEXPLANATION
0DWORD Characteristics\OriginalFirstThunk RVA to Image_Thunk_Data 
4DWORD TimeDateStampzero unless bound against imported DLL 
8DWORD ForwarderChainpointer to 1st redirected function (or 0) 
0C DWORD Name1RVA to name in null-terminated ASCII
10DWORD FirstThunkRVA to Image_Thunk_Data


TLS目录结构IMAGE_TLS_DIRECTORY32

OFFSETSIZENAMEEXPLANATION 
0DWORDStartAddressOfRawDataTLS模板的起始地址
4DWORDEndAddressOfRawDataTLS模板的结束地址
8DWORDAddressOfIndexTLS索引的位置
0CDWORDAddressOfCallBacksTLS回调函数数组指针
10DWORDSizeOfZeroFill填充0的个数
14DWORDCharacteristics保留


节表项IMAGE_SECTION_HEADER

OFFSETSIZENAMEEXPLANATION 
08字节Name18个字节节名
8DWORDPhysicalAddress/VirtualSize节区的尺寸
0CDWORDVirtualAddress节区的RVA地址
10DWORDSizeOfRawData在文件中对齐后的尺寸
14DWORDPointerToRawData在文件中的偏移
18DWORDPointerToRelocations在OBJ文件中使用
1CDWORDPointerToLinenumbers行号表的位置(供调试用)
20DWORDNumberOfRelocations在OBJ文件中使用
22WORDNumberOfLinenumbers行号表中行号的数量
24DWORDCharacteristics节的属性

typedef struct _SECTION_IMAGE_INFORMATION
{
     PVOID TransferAddress;
     ULONG ZeroBits;
     ULONG MaximumStackSize;
     ULONG CommittedStackSize;
     ULONG SubSystemType;
     union
     {
          struct
          {
               WORD SubSystemMinorVersion;
               WORD SubSystemMajorVersion;
          };
          ULONG SubSystemVersion;
     };
     ULONG GpValue;
     WORD ImageCharacteristics;
     WORD DllCharacteristics;
     WORD Machine;
     UCHAR ImageContainsCode;
     UCHAR ImageFlags;
     ULONG ComPlusNativeReady: 1;
     ULONG ComPlusILOnly: 1;
     ULONG ImageDynamicallyRelocated: 1;
     ULONG Reserved: 5;
     ULONG LoaderFlags;
     ULONG ImageFileSize;
     ULONG CheckSum;
} SECTION_IMAGE_INFORMATION, *PSECTION_IMAGE_INFORMATION;


Image Characteristics Flags

FLAG  EXPLANATION                                                 
1Relocation info stripped from file                          
2File is executable (no unresolved external references)      
4Line numbers stripped from file                             
8Local symbols stripped from file                            
10Lets OS aggressively trim working set                       
20App can handle >2Gb addresses                               
80Low bytes of machine word are reversed                      
100requires 32-bit WORD machine                                
200Debugging info stripped from file into .DBG file            
400If image is on removable media, copy and run from swap file 
800If image is on a network, copy and run from swap file       
1000System file                                                 
2000File is a DLL                                               
4000File should only be run on a single-processor machine       
8000High bytes of machine word are reversed                     


Section Characteristics Flags

FLAGEXPLANATION                                                                                                   
8Section should not be padded to next boundary                                                                 
20Section contains code                                                                                         
40Section contains initialised data (which will become initialised with real values before the file is launched)
80Section contains uninitialised data (which will be initialised as 00 byte values before launch)               
200Section contains comments for the linker                                                                      
800Section contents will not become part of image                                                                
1000Section contents comdat (Common Block Data)                                                                   
8000Section contents cannot be accessed relative to GP                                                            
00100000 to 00800000    Boundary alignment settings                                                                                   
1000000Section contains extended relocations                                                                         
2000000Section can be discarded (e.g. .reloc)                                                                        
4000000Section is not cacheable                                                                                      
8000000Section is pageable                                                                                           
10000000Section is shareable                                                                                          
20000000Section is executable                                                                                         
40000000Section is readable                                                                                           
80000000Section is writable                                                                                           


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值