wire / wire-format / pe-coff-header
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+).
aka: PE/COFF header (Windows executable)
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+).
| field | size | meaning |
|---|---|---|
| DOS MZ signature | 2 bytes | 'MZ' (0x4D 0x5A) at file offset 0. |
| e_lfanew | 4 bytes | File offset (at DOS header offset 0x3C) to the PE signature. |
| PE signature | 4 bytes | 'PE\x00\x00' (0x50 0x45 0x00 0x00). |
| Machine | 2 bytes | Target CPU: 0x014C i386, 0x8664 x86-64, 0x01C0 ARM, 0xAA64 ARM64. |
| NumberOfSections | 2 bytes | Count of section headers following the optional header. |
| TimeDateStamp | 4 bytes | Unix timestamp of link time. |
| PointerToSymbolTable | 4 bytes | Offset to COFF symbol table (0 if stripped). |
| NumberOfSymbols | 4 bytes | Number of symbols in the symbol table. |
| SizeOfOptionalHeader | 2 bytes | Size of the optional header (224 for PE32, 240 for PE32+). |
| Characteristics | 2 bytes | Flags: executable image, DLL, large address aware, ... (e.g. 0x0002 EXECUTABLE_IMAGE, 0x2000 DLL). |
| Magic (optional header) | 2 bytes | 0x10B PE32 (32-bit), 0x20B PE32+ (64-bit), 0x107 ROM. |
| AddressOfEntryPoint | 4 bytes | RVA of the entry point (relative to image base). |
| ImageBase | 4/8 bytes | Preferred load address (PE32 4 bytes, PE32+ 8 bytes). |
| SectionAlignment | 4 bytes | Alignment of sections in memory (usually 0x1000). |
| FileAlignment | 4 bytes | Alignment 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)
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/pe-coff-header
or /wire-format/pe-coff-header.json