Logo
Articles Compilers Libraries Books MiniBooklets Assembly C++ Rust Go Linux CPU Others Videos
Advertisement

Article by Ayman Alheraki on January 11 2026 10:37 AM

Understanding Executable File Headers Across Platforms (Windows, Linux, macOS) — With Hex Analysis

Understanding Executable File Headers Across Platforms (Windows, Linux, macOS) — With Hex Analysis

When a program is compiled into an executable, it carries a binary header at the beginning. This header is crucial — it tells the operating system how to load and run the program. These headers differ across platforms and architectures (32-bit vs 64-bit). This article presents a comprehensive overview of executable headers on Windows, Linux, and macOS, including real hexadecimal headers extracted from binaries.

Windows PE Format (Portable Executable)

Windows executables follow the PE format, built on top of an older DOS format for compatibility.

PE Header Structure

  1. DOS Header (IMAGE_DOS_HEADER) Starts with MZ (0x4D 0x5A) and contains a pointer to the PE header at offset 0x3C.

  2. PE Signature: "PE\0\0" = 0x50 0x45 0x00 0x00

  3. COFF File Header (IMAGE_FILE_HEADER) Contains machine type, section count, and flags.

  4. Optional Header (IMAGE_OPTIONAL_HEADER) Contains entry point, memory layout, and more. It differs between 32-bit (PE32) and 64-bit (PE32+).

PE Header Structure (Simplified Overview):

PE32 vs PE32+ Differences:

  • PE32 is used for 32-bit executables.

  • PE32+ is used for 64-bit executables.

  • In PE32+, ImageBase and other fields are 64-bit wide.

Use dumpbin /headers yourfile.exe or objdump -f yourfile.exe to inspect.

Hexadecimal PE Header (Simplified 32-bit Example)

  • 4D 5A = "MZ"

  • 50 45 00 00 = "PE\0\0"

  • 0B 01 = PE32 (for PE32+ use 0B 02)

Linux ELF Format (Executable and Linkable Format)

The ELF format is used on Linux and many Unix-like systems.

ELF Header Structure

  1. Magic Bytes: 0x7F 45 4C 46 = "\x7FELF"

  2. Class: 0x01 = 32-bit, 0x02 = 64-bit

  3. Data Encoding: 0x01 = Little Endian, 0x02 = Big Endian

  4. File Type: 0x02 = Executable

  5. Machine Type: e.g., 0x03 = x86, 0x3E = x86_64

ELF Header Structure (for 32-bit and 64-bit):

Use readelf -h yourfile or objdump -f yourfile to inspect.

Hexadecimal ELF Header (64-bit Example)

  • 7F 45 4C 46 = ELF

  • 02 = 64-bit

  • 3E 00 = x86-64 architecture

For 32-bit ELF, use 01 in the class byte, and the rest of the layout is adjusted accordingly.

macOS Mach-O Format

Mach-O (Mach Object) is the native binary format for macOS and iOS.

Mach-O Header Structure (64-bit)

  1. Magic: 0xCFFAEDFE = little-endian 64-bit Mach-O

  2. CPU Type: e.g., 0x01000007 = x86_64

  3. File Type: 0x02 = Executable

  4. Load Commands: Follow immediately after the header

macOS Executable Header – Mach-O Format

macOS (and iOS) uses the Mach-O (Mach Object) format, which can also be packaged in Fat/Universal binaries (for Intel and ARM).

Mach-O Header Structure:

Use otool -hv yourfile or mach-o-analyzer to view header info.

Hexadecimal Mach-O Header (64-bit Intel)

  • CF FA ED FE = Mach-O 64-bit (little endian)

  • 07 00 00 01 = x86_64

  • 02 00 00 00 = Executable

Mach-O Fat Binary Header

Used when a binary includes multiple architectures (e.g., Intel + ARM).

Summary Table: Headers and Magic Bytes

PlatformFormatMagic Bytes (Hex)Description
WindowsPE4D 5A50 45 00 00DOS header, then PE signature
LinuxELF7F 45 4C 46\x7FELF
macOSMach-OCF FA ED FE64-bit Mach-O (little endian)
macOSFATCA FE BA BEFat binary (multi-arch)

 

Bonus: How to View These Headers

  • Linux/macOS:

    • xxd your_binary | head

    • readelf -h your_binary

    • otool -hv your_macho_file

  • Windows:

    • Use CFF Explorer, PE-bear, or dumpbin /headers yourfile.exe

Final Thoughts

Understanding executable headers is essential for:

  • Writing loaders, debuggers, or virtual machines

  • Malware analysis and reverse engineering

  • Building cross-platform compilers and linkers

  • Developing custom packers or OS loaders

These headers reveal the true structure and intent of the binary before the code even runs.

Advertisements

Responsive Counter
General Counter
1190514
Daily Counter
1251