🍁 maple-rs
A Rust library for loading Windows PE executables and DLLs directly from memory, without needing to write them to disk first. This is a modern, memory-safe Rust replacement for the C memorymodule library.
Security Notice
This library enables loading and executing code from memory buffers. While this has legitimate uses such as:
- Dynamic code loading in game engines
- Plugin systems
- Testing and debugging tools
- Memory-efficient application packaging
Users are responsible for ensuring they only load trusted code and comply with all applicable laws and security policies.
Features
- 🔹 In-Memory Loading: Load PE executables (.exe) and libraries (.dll) directly from memory
- 🔹 Application DLL Support: Execute applications compiled as DLLs with proper threading
- 🔹 Full PE Support: Complete PE parsing, import resolution, and relocation processing
- 🔹 Native Execution: Code runs exactly as if loaded from disk
- 🔹 Memory Safety: Proper memory management with automatic cleanup
- 🔹 Cross-Platform Ready: Windows implementation complete, Linux planned
- 🔹 Zero-Copy: Efficient memory usage with minimal overhead
Quick Start
Add this to your Cargo.toml
:
[]
= "0.1.0"
Basic Usage
use ;
use fs;
Loading Regular DLLs
use ;
use fs;
Loading Application DLLs
Application DLLs are applications that have been compiled as DLL files instead of executables. They typically start a thread in DllMain
to run the application logic.
use ;
use fs;
Manual Control with Builder Pattern
For advanced control over application DLL loading:
use ;
use fs;
API Reference
Main Entry Points
Maple::load_executable_from_memory(data)
- Load a standard executableMaple::load_library_from_memory(data)
- Load a standard DLL/libraryMaple::load_application_dll_from_memory(data)
- Load an application DLL
MemoryModule Trait Methods
execute_entry_point()
- Execute an executable's entry pointexecute_dll_application()
- Execute an application DLL (starts thread in DllMain)call_dll_entry_point(reason)
- Manually call DllMain with specific reasonget_proc_address(name)
- Get function address by nameget_proc_address_ordinal(ordinal)
- Get function address by ordinal
Builder Options
resolve_imports(bool)
- Enable/disable import resolutionprocess_relocations(bool)
- Enable/disable relocation processingcall_dll_main(bool)
- Auto-call DllMain on loadis_application_dll(bool)
- Mark as application DLLignore_missing_imports(bool)
- Continue loading with missing imports
Documentation
Comprehensive API documentation is available on docs.rs.
Platform Support
Platform | Status | Features |
---|---|---|
Windows | ✅ Complete | Full PE parsing, import resolution, memory protection, application DLLs |
Linux | 🔄 Planned | ELF support planned for future release |
macOS | 🔄 Planned | Mach-O support planned for future release |
Error Handling
All operations return a Result<T, MapleError>
with detailed error information:
use ;
match load_executable_from_memory
Architecture
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the GNU GPLv3 License - see the LICENSE file for details.
Acknowledgments
- Inspired by the original MemoryModule C library