This is a complete PE32+ writer and machine code emitter implemented in pure x64 MASM assembly with zero dependencies and no CRT usage. It generates runnable Windows executables from scratch.
The PE writer follows a backend designer approach, providing a clean API for:
Implementation Details:
Implementation Details:
Implementation Details:
Implementation Details:
The implementation uses Windows heap APIs:
All memory allocation includes proper error handling and cleanup.
DOS Header (64 bytes)
DOS Stub (variable size, padded to 0x80)
NT Headers (248 bytes for PE32+)
Section Headers (40 bytes × 3 sections)
Padding to file alignment (0x400)
.text Section (code)
- Machine code
- Padded to file alignment
.rdata Section (read-only data)
- String constants, resources
- Padded to file alignment
.idata Section (import data)
- Import descriptors
- Import lookup table
- Import address table
- Import by name structures
- Padded to file alignment
0x1000: .text section (SECTION_ALIGNMENT)
0x2000: .rdata section
0x3000: .idata section
0x4000: Next available virtual address
; Create PE context
mov rcx, 0 ; Default image base
mov rdx, 1000h ; Entry point RVA
call PEWriter_CreateExecutable
mov rbx, rax ; Save context
; Add kernel32.dll imports
mov rcx, rbx
mov rdx, offset dll_kernel32
mov r8, offset func_GetStdHandle
call PEWriter_AddImport
; Add machine code
mov rcx, rbx
mov rdx, offset code_buffer
mov r8, code_size
call PEWriter_AddCode
; Write executable file
mov rcx, rbx
mov rdx, offset filename
call PEWriter_WriteFile
build.bat to compile PE writer and examplePE_Writer_Example.exe to generate hello.exeAll functions return 0 on failure and non-zero on success. The implementation includes:
The implementation provides a solid foundation for:
This implementation provides a complete, production-ready PE32+ writer suitable for code generation backends, custom compilers, and executable packers.
Assembly
43.9%
C++
42.4%
PowerShell
4.0%
HTML
2.7%
C
2.3%
JavaScript
1.7%
Python
1.1%
This is a complete PE32+ writer and machine code emitter implemented in pure x64 MASM assembly with zero dependencies and no CRT usage. It generates runnable Windows executables from scratch.
The PE writer follows a backend designer approach, providing a clean API for:
Implementation Details:
Implementation Details:
Implementation Details:
Implementation Details:
The implementation uses Windows heap APIs:
All memory allocation includes proper error handling and cleanup.
DOS Header (64 bytes)
DOS Stub (variable size, padded to 0x80)
NT Headers (248 bytes for PE32+)
Section Headers (40 bytes × 3 sections)
Padding to file alignment (0x400)
.text Section (code)
- Machine code
- Padded to file alignment
.rdata Section (read-only data)
- String constants, resources
- Padded to file alignment
.idata Section (import data)
- Import descriptors
- Import lookup table
- Import address table
- Import by name structures
- Padded to file alignment
0x1000: .text section (SECTION_ALIGNMENT)
0x2000: .rdata section
0x3000: .idata section
0x4000: Next available virtual address
; Create PE context
mov rcx, 0 ; Default image base
mov rdx, 1000h ; Entry point RVA
call PEWriter_CreateExecutable
mov rbx, rax ; Save context
; Add kernel32.dll imports
mov rcx, rbx
mov rdx, offset dll_kernel32
mov r8, offset func_GetStdHandle
call PEWriter_AddImport
; Add machine code
mov rcx, rbx
mov rdx, offset code_buffer
mov r8, code_size
call PEWriter_AddCode
; Write executable file
mov rcx, rbx
mov rdx, offset filename
call PEWriter_WriteFile
build.bat to compile PE writer and examplePE_Writer_Example.exe to generate hello.exeAll functions return 0 on failure and non-zero on success. The implementation includes:
The implementation provides a solid foundation for:
This implementation provides a complete, production-ready PE32+ writer suitable for code generation backends, custom compilers, and executable packers.
Assembly
43.9%
C++
42.4%
PowerShell
4.0%
HTML
2.7%
C
2.3%
JavaScript
1.7%
Python
1.1%