PE File Format
PE File Format
Window’s executable file format is called the Portable Executable (PE). The PE file
format not only applies to executable files .exe, but also to DLLs and kernel-mode
drivers.
A PE files is also called a module, whereas a module implies that a single executable file
that is a part of a program.
MS-Dos Header
MS-Dos Stub
PE Header
DATA Directory
Section Table
MS-Dos Header:
Every PE file starts with the MS-Dos header section which contains a pointer to the PE
header section.
MS-Dos Stub section provided for legacy reason. This section informs the user that this
file cannot be run in DOS mode when the user attempts to run it with DOS command.
PE Header contains important needed to run the executable such as: the base address of
the PE file, the address of the Entry point, and the number of sections in the section table.
Import Table:
When the system loads the executable file, it uses the information in import table
to load all DLL files that are by current executable and to resolve.
Locates the address of the exported function using IAT.
It contains a list of all functions the current executable imports grouped under
each module name.
Every PE file has a list of functions that aren’t originally part of that PE. These functions
are called Import which is located in OS DLL’s (Dynamic Link Library) while PE
doesn’t know where they are located so every win32 executable has IAT inside PE.
Export table:
Export Table contains names & RVA of every exported function
Run time linking: It loads the DLL files and then imports to required function manually
at run time
No import table is provided
Executable imports the right function by loading DLL file first
Using win32 API LoadLibrary() / LoadLibraryEx() followed by win32API
GetProcAddress()
In the PE file, the magic part of the DOS header contains the value 4Dh, 5Ah (the letters
“MZ”) which signifies a valid DOS header.
A PE header begins with its signature 50h, 45h, 00h, 00h (the letters “PE” followed by
two terminating zeroes) i.e. the PE signature at start of PE Header
Terminology:
Size of Raw Data Amount of section data within the executable file.
Relative Virtual Address. Memory offset from the beginning of
RVA
the executable
Virtual Address Absolute memories address (RVA + Base). The PE Header fields
(VA) named Virtual Address actually contain RVA
Virtual Size Amount of section data in memory