PE Assembler
A comprehensive library for constructing and analyzing Windows Portable Executable (PE) files, covering everything from simple executables to complex dynamic libraries and debug symbols.
🏛️ Architecture
graph TB
subgraph "PE File Construction"
A[PE Program Model] --> B[DOS/NT Header Builder]
B --> C[Section Allocator]
C --> D[Data Directory Resolver]
D --> E[PE Binary (.exe / .dll)]
subgraph "Data Directories"
F[Import Table .idata]
G[Export Table .edata]
H[Resource Table .rsrc]
I[Base Relocations .reloc]
end
D --> F
D --> G
D --> H
D --> I
end
🚀 Features
Core Capabilities
- Format Versatility: Supports generation of Executables (EXE), Dynamic Link Libraries (DLL), Static Libraries (LIB), and Object files (OBJ/COFF).
- Header Management: Precise construction of DOS stubs, PE headers (32/64 bit), and Optional headers with full data directory support.
- Import/Export Resolution: Automatically builds Import Address Tables (IAT) and Export Name/Ordinal tables for seamless dynamic linking.
Advanced Features
- Relocation Handling: Generates base relocation blocks required for Address Space Layout Randomization (ASLR) compatibility.
- Resource Management: (🚧) Support for embedding icons, version information, and other manifest resources.
- PDB Support: (🚧) Initial framework for generating Program Database (PDB) debug information.
- COFF Support: Low-level access to COFF symbol tables and section relocations for static linking scenarios.
💻 Usage
Generating a Windows Executable
The following example shows how to use the high-level API to write a PE program to an EXE file.
use ;
use Path;
🛠️ Support Status
| Feature | Support Level | Architecture |
|---|---|---|
| EXE / DLL | ✅ Full | x86, x64, ARM64 |
| LIB / OBJ | ✅ Full | COFF Standard |
| Imports (IAT) | ✅ Full | Static & Delay-load |
| Exports | ✅ Full | Name & Ordinal |
| Relocations | ✅ Full | Base Reloc (Type 3/10) |
| Resources | 🚧 Partial | .rsrc section |
Legend: ✅ Supported, 🚧 In Progress, ❌ Not Supported
🔗 Relations
- gaia-types: Extensively uses the
BinaryWriterfor structured I/O of complex PE structures and alignment padding. - gaia-assembler: Acts as the primary Windows-native backend for generating runnable PE binaries from Gaia IR.
- clr-assembler: Relies on the PE foundation to wrap MSIL bytecode and .NET metadata into valid CLI-compatible PE files.