wire / wire-format / pe-coff-header

PE/COFF header (Windows executable)

A Windows PE (Portable Executable) file begins with a DOS stub (MZ header + 'This program cannot be run in DOS mode'), then at the PE header offset (e_lfanew) a 4-byte signature 'PE\x00\x00' followed by a 20-byte COFF file header and an optional header (PE32 or PE32+).

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: PE/COFF header (Windows executable)

wire format

spec: Microsoft PE/COFF specification

A Windows PE (Portable Executable) file begins with a DOS stub (MZ header + 'This program cannot be run in DOS mode'), then at the PE header offset (e_lfanew) a 4-byte signature 'PE\x00\x00' followed by a 20-byte COFF file header and an optional header (PE32 or PE32+).

fieldsizemeaning
DOS MZ signature2 bytes'MZ' (0x4D 0x5A) at file offset 0.
e_lfanew4 bytesFile offset (at DOS header offset 0x3C) to the PE signature.
PE signature4 bytes'PE\x00\x00' (0x50 0x45 0x00 0x00).
Machine2 bytesTarget CPU: 0x014C i386, 0x8664 x86-64, 0x01C0 ARM, 0xAA64 ARM64.
NumberOfSections2 bytesCount of section headers following the optional header.
TimeDateStamp4 bytesUnix timestamp of link time.
PointerToSymbolTable4 bytesOffset to COFF symbol table (0 if stripped).
NumberOfSymbols4 bytesNumber of symbols in the symbol table.
SizeOfOptionalHeader2 bytesSize of the optional header (224 for PE32, 240 for PE32+).
Characteristics2 bytesFlags: executable image, DLL, large address aware, ... (e.g. 0x0002 EXECUTABLE_IMAGE, 0x2000 DLL).
Magic (optional header)2 bytes0x10B PE32 (32-bit), 0x20B PE32+ (64-bit), 0x107 ROM.
AddressOfEntryPoint4 bytesRVA of the entry point (relative to image base).
ImageBase4/8 bytesPreferred load address (PE32 4 bytes, PE32+ 8 bytes).
SectionAlignment4 bytesAlignment of sections in memory (usually 0x1000).
FileAlignment4 bytesAlignment of sections in the file (usually 0x200).

example:

4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00 b8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00

MZ DOS stub prefix (first 64 bytes)


provenance

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/pe-coff-header or /wire-format/pe-coff-header.json