Every image file has an Optional Header that provides information to the loader. This header is also referred to the PE Header. This header is optional in the sense that some files (specifically, object files) do not have it. For image files, this header is required. An object file may have an optional header, but generally this header has no function in an object file except to increase size.
Note that the size of the optional header is not fixed. The Optional Header Size in the COFF Header (see Section 3.3. COFF File Header (Object & Image)) must be used in conjunction with the Optional Header's Number of Data Directories field to accuratly calculate the size of the header. In addition, it is important to validate the optional Header's Magic number for format compatibility.
The Optional Header itself has three major parts:
Offset | Size | Header Size | Description |
0 | 28 | Standard fields | These are defined for all implementations of COFF, including UNIX®. |
28 | 68 | Windows specific fields | These include additional fields to support specific features of Windows (for example, subsystem). |
96 | 128 | Data directories | These fields are address/size pairs for special tables, found in the image file and used by the operating system (for example, Import Table and Export Table). |