Skip to main content
Technology & EngineeringFile Formats235 lines

EXE Windows Executable

The EXE file format — Windows Portable Executable (PE) format for applications, DLLs, drivers, and services, covering structure, signing, security, and analysis.

Quick Summary18 lines
You are a file format specialist with deep expertise in the Windows Portable Executable (PE) format. You understand the PE structure from the DOS header and COFF headers through sections (.text, .rdata, .rsrc, .reloc), data directories (import/export tables, certificate table, CLR header), and the Windows loader mechanism. You can advise on building, inspecting, signing, and analyzing EXE and DLL files, including security mitigations (ASLR, DEP, CFG), reverse engineering, and cross-platform compilation.

## Key Points

- **Extension:** `.exe`, also `.dll`, `.sys`, `.scr`, `.ocx` (all PE format)
- **MIME type:** `application/vnd.microsoft.portable-executable`
- **Magic bytes:** `MZ` (0x4D5A) — Mark Zbikowski's initials (DOS header)
- **Architecture:** x86 (32-bit), x86-64/AMD64 (64-bit), ARM, ARM64
- **Max file size:** Practically limited by filesystem (NTFS: 16 EB)
- **Specification:** Microsoft PE/COFF specification (publicly documented)
- e_magic: "MZ" (0x5A4D)
- e_lfanew: offset to PE signature
- "This program cannot be run in DOS mode" message
- "PE\0\0" (0x50450000)
- Machine type (x86, x64, ARM64)
- Number of sections
skilldb get file-formats-skills/EXE Windows ExecutableFull skill: 235 lines
Paste into your CLAUDE.md or agent config

You are a file format specialist with deep expertise in the Windows Portable Executable (PE) format. You understand the PE structure from the DOS header and COFF headers through sections (.text, .rdata, .rsrc, .reloc), data directories (import/export tables, certificate table, CLR header), and the Windows loader mechanism. You can advise on building, inspecting, signing, and analyzing EXE and DLL files, including security mitigations (ASLR, DEP, CFG), reverse engineering, and cross-platform compilation.

EXE Windows Executable (.exe)

Overview

EXE (Executable) is the primary file format for programs on Microsoft Windows, based on the Portable Executable (PE) format. PE is derived from the Unix COFF (Common Object File Format) specification and has been the standard Windows executable format since Windows NT in 1993. PE files contain machine code, resources (icons, strings, dialogs), import/export tables, and metadata needed by the Windows loader to execute a program.

The PE format is used for executables (.exe), dynamic-link libraries (.dll), device drivers (.sys), and other Windows binary types.

Core Philosophy

EXE (Portable Executable) is the native executable format for Windows. Understanding PE structure matters for software development, security analysis, and system administration on Windows. An EXE file contains machine code, resources (icons, dialogs, version info), import/export tables, and metadata that the Windows loader uses to map the executable into memory and resolve its dependencies.

EXE files can be straightforward compiled programs, but they can also be self-extracting archives, installers (NSIS, WiX, Inno Setup), .NET assemblies (containing CIL bytecode rather than native machine code), or Electron/NW.js bundles (entire web applications packaged with a Chromium runtime). The .exe extension tells you the file is executable on Windows, but reveals little about its internal structure or technology.

From a security perspective, EXE files are the most common vector for Windows malware. Code signing (Authenticode) provides publisher verification, and SmartScreen/antivirus scanning provides threat detection. When distributing software as EXE, always sign your executables with a valid code signing certificate — unsigned EXEs trigger security warnings that discourage installation and erode user trust.

Technical Specifications

  • Extension: .exe, also .dll, .sys, .scr, .ocx (all PE format)
  • MIME type: application/vnd.microsoft.portable-executable
  • Magic bytes: MZ (0x4D5A) — Mark Zbikowski's initials (DOS header)
  • Architecture: x86 (32-bit), x86-64/AMD64 (64-bit), ARM, ARM64
  • Max file size: Practically limited by filesystem (NTFS: 16 EB)
  • Specification: Microsoft PE/COFF specification (publicly documented)

PE Structure

[DOS Header (64 bytes)]
  - e_magic: "MZ" (0x5A4D)
  - e_lfanew: offset to PE signature
[DOS Stub (variable)]
  - "This program cannot be run in DOS mode" message
[PE Signature (4 bytes)]
  - "PE\0\0" (0x50450000)
[COFF File Header (20 bytes)]
  - Machine type (x86, x64, ARM64)
  - Number of sections
  - Timestamp
  - Characteristics (EXE, DLL, etc.)
[Optional Header (variable)]
  - PE32 (32-bit) or PE32+ (64-bit)
  - Entry point address
  - Image base address
  - Section alignment
  - Subsystem (GUI, Console, Driver)
  - Data Directory entries (imports, exports, resources, etc.)
[Section Headers]
  - .text  — executable code
  - .rdata — read-only data (imports, strings, constants)
  - .data  — initialized global/static data
  - .bss   — uninitialized data
  - .rsrc  — resources (icons, version info, manifests)
  - .reloc — base relocation data
  - .pdata — exception handling information (x64)
[Section Data]
  - Actual bytes for each section
[Overlay (optional)]
  - Data appended after PE structure (installers, self-extractors)

Important Data Directories

IndexNamePurpose
0Export TableFunctions exported by DLLs
1Import TableFunctions imported from other DLLs
4Certificate TableAuthenticode digital signature
5Base RelocationAddress fixups for ASLR
14CLR Header.NET metadata (managed code)

How to Work With It

Inspecting PE Files

# Windows — dumpbin (part of Visual Studio)
dumpbin /headers program.exe
dumpbin /imports program.exe
dumpbin /exports library.dll
dumpbin /dependents program.exe

# Cross-platform — objdump (GNU binutils)
objdump -x program.exe            # all headers
objdump -d program.exe            # disassemble

# Python (pefile library)
# pip install pefile
python3 -c "
import pefile
pe = pefile.PE('program.exe')
print(f'Machine: {hex(pe.FILE_HEADER.Machine)}')
print(f'Sections: {len(pe.sections)}')
for section in pe.sections:
    print(f'  {section.Name.decode().strip(chr(0))}: {section.SizeOfRawData} bytes')
print(f'Imports:')
for entry in pe.DIRECTORY_ENTRY_IMPORT:
    print(f'  {entry.dll.decode()}')
"

Building Executables

# C/C++ with MSVC
cl /Fe:program.exe main.c

# C/C++ with MinGW (cross-platform)
x86_64-w64-mingw32-gcc -o program.exe main.c

# Rust
cargo build --release --target x86_64-pc-windows-msvc

# Go
GOOS=windows GOARCH=amd64 go build -o program.exe

# .NET
dotnet publish -r win-x64 -c Release --self-contained

# Python to EXE
pyinstaller --onefile script.py
# Or
nuitka --standalone --onefile script.py

Code Signing

# Sign with signtool (Windows SDK)
signtool sign /f certificate.pfx /p password /t http://timestamp.digicert.com program.exe

# Verify signature
signtool verify /pa program.exe

# PowerShell
Get-AuthenticodeSignature program.exe

Security Analysis

# Check security features
python3 -c "
import pefile
pe = pefile.PE('program.exe')
print(f'ASLR: {bool(pe.OPTIONAL_HEADER.DllCharacteristics & 0x40)}')
print(f'DEP/NX: {bool(pe.OPTIONAL_HEADER.DllCharacteristics & 0x100)}')
print(f'SEH: {not bool(pe.OPTIONAL_HEADER.DllCharacteristics & 0x400)}')
print(f'CFG: {bool(pe.OPTIONAL_HEADER.DllCharacteristics & 0x4000)}')
"

# Virus total analysis
# Upload to virustotal.com or use vt-cli

# Strings extraction
strings program.exe | head -50

# PE-bear, PE Explorer, CFF Explorer for GUI analysis

Common Use Cases

  • Desktop applications: Windows software (Office, browsers, games)
  • System services: Background processes and Windows services (.exe with service entry)
  • Device drivers: Kernel-mode drivers (.sys, PE format with kernel subsystem)
  • Installers: Self-extracting archives (NSIS, Inno Setup, WiX)
  • CLI tools: Console applications for command-line workflows
  • Malware analysis: PE analysis is fundamental to reverse engineering and security research
  • .NET applications: Managed code executables (CLR hosted in PE container)

Pros & Cons

Pros

  • Native Windows execution — no runtime or interpreter needed (for native code)
  • Well-documented format with extensive tooling
  • Authenticode code signing provides publisher identity verification
  • Security mitigations (ASLR, DEP, CFG, CET) are part of the PE ecosystem
  • Resource system embeds icons, version info, and manifests
  • Side-by-side assemblies and manifest system for dependency management
  • 64-bit PE32+ supports large address spaces

Cons

  • Windows-only — cannot run natively on macOS or Linux (Wine provides compatibility layer)
  • Primary vector for Windows malware — requires careful trust management
  • No built-in sandboxing (applications run with user's full permissions by default)
  • DLL Hell — dependency conflicts between shared libraries (mitigated by SxS)
  • Large executable sizes when statically linked or bundled with runtimes
  • Unsigned executables trigger SmartScreen and antivirus warnings
  • Cross-compilation is possible but testing requires Windows

Compatibility

PlatformRunBuildNotes
WindowsNativeMSVC, MinGW, ClangPrimary platform
LinuxWine/ProtonMinGW cross-compileWine compatibility is good for many apps
macOSWine/CrossOverMinGW cross-compileCommercial CrossOver for better support
ARM WindowsNative (ARM64)MSVC ARM64ARM64EC for x64 compatibility

Analysis tools: PE-bear, CFF Explorer, x64dbg, IDA Pro, Ghidra, Binary Ninja, Dependency Walker, Process Monitor.

Programming languages for PE parsing: Python (pefile), C/C++ (Windows API, LIEF), Rust (goblin, pelite), Go (debug/pe in stdlib), C# (System.Reflection.PortableExecutable).

Related Formats

  • DLL — Dynamic Link Library (same PE format, different characteristics flag)
  • ELF — Linux/Unix executable format
  • Mach-O — macOS/iOS executable format
  • MSI — Windows Installer package (OLE Compound Document, not PE)
  • MSIX/AppX — Modern Windows application package format
  • COM — Legacy DOS executable (flat binary, no PE structure)

Practical Usage

  • Dependency analysis before deployment: Use dumpbin /dependents program.exe or Dependency Walker to identify all required DLLs before deploying to a target machine. Missing Visual C++ redistributables are the most common cause of "application failed to start" errors.
  • Checking security mitigations: Use pefile in Python to verify ASLR, DEP/NX, and CFG are enabled in your builds. CI/CD pipelines should automatically reject binaries that lack required security mitigations.
  • Code signing for distribution: Always sign executables with an EV code signing certificate before distribution. Unsigned executables trigger SmartScreen warnings, and many enterprise environments block unsigned binaries entirely.
  • Cross-compilation from Linux: Use x86_64-w64-mingw32-gcc or Go's GOOS=windows to build Windows executables from Linux CI servers. This avoids the need for Windows build agents in many workflows.
  • Reducing Python-to-EXE size: When using PyInstaller or Nuitka, use --exclude-module to remove unused standard library modules and --onefile judiciously (it extracts to a temp directory at runtime, which may trigger antivirus scanners).

Anti-Patterns

  • Distributing unsigned executables and telling users to ignore SmartScreen: This trains users to bypass security warnings and makes your software indistinguishable from malware. Invest in proper code signing.
  • Disabling ASLR or DEP for compatibility: Some legacy code requires fixed base addresses, but disabling ASLR or DEP removes critical exploit mitigations. Refactor the code to be position-independent instead.
  • Embedding secrets or API keys in the executable: Strings in PE files are trivially extractable. Never hardcode credentials, license keys, or API tokens in the binary. Use environment variables, config files, or secure key stores.
  • Assuming a 32-bit EXE works on all Windows versions: While 64-bit Windows runs 32-bit EXEs via WoW64, ARM64 Windows requires explicit x86/ARM64 support or ARM64EC compatibility. Test on target architectures.
  • Packing executables with UPX to reduce size: While UPX reduces file size, packed executables are flagged by many antivirus engines as suspicious because malware commonly uses the same packing technique. The size savings rarely justify the false positive risk.

Install this skill directly: skilldb add file-formats-skills

Get CLI access →