A simple RunPE loader written in Zig, designed to load and execute Portable Executable (PE) files in memory.
This project implements a RunPE loader in Zig, allowing for the dynamic loading and execution of PE files directly from memory. It's designed to work with native compiled binaries and provides a set of functions to handle various aspects of PE file manipulation.
- Parse and retrieve DOS_IMAGE_HEADER
- Parse and retrieve NT_IMAGE_HEADER
- Calculate DOS_IMAGE_HEADER size
- Calculate NT_IMAGE_HEADER size
- Allocate memory for PE image binding
- Copy PE file contents to allocated memory
- Write sections to header
- Handle import table (load required DLLs and resolve functions)
- Fix base relocations
- Change Memory Protection
- Execute the PE file's entry point
- Native compiled binary execution
- .NET compiled binary execution (not yet implemented)
- Zig compiler (latest version recommended)
- Windows OS (the project uses Windows-specific APIs)
-
Clone the repository:
git clone https://github.com/yourusername/zig-pe.git cd zig-pe
-
Build the project:
zig build
Here's a basic example of how to use the zig-pe loader:
const std = @import("std");
const pe = @import("pe.zig");
pub fn main() !void {
// Use local PE
// var gpa = std.heap.GeneralPurposeAllocator(.{}){};
// defer _ = gpa.deinit();
// const allocator = gpa.allocator();
// const file_name = "src/bin/putty.exe";
// const file_content = try std.fs.cwd().readFileAlloc(allocator, file_name, std.math.maxInt(usize));
// defer allocator.free(file_content);
// Use embed PE
try pe.RunPE.init(@embedFile("bin/putty.exe")).run();
}
This project involves loading and executing arbitrary code, which can be potentially dangerous. Use this loader only with trusted PE files and in controlled environments. The authors are not responsible for any misuse or damage caused by this software.
Contributions to zig-pe are welcome! Please feel free to submit pull requests, create issues or spread the word.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- The Zig programming language community
- Contributors to PE file format documentation
This project is for educational purposes only. Ensure you have the necessary rights and permissions before loading and executing any PE file.