Expand description
§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, safe Rust replacement for the C memorymodule library.
§⚠️ Security Notice
This library enables loading and executing code from memory buffers, which can be used for legitimate purposes such as:
- Dynamic code loading in game engines
- Plugin systems
- Testing and debugging tools
- Memory-efficient application packaging
However, it could also be misused for malicious purposes. 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) from memory
- 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
§Quick Start
use maple_rs::{Maple, Result};
use std::fs;
fn main() -> Result<()> {
// Load an executable from memory
let data = fs::read("program.exe")?;
let module = Maple::load_executable_from_memory(&data)?;
// Execute the program's entry point
module.execute_entry_point()?;
Ok(())
}
§Advanced Usage
use maple_rs::{MemoryModuleBuilder, Result};
use std::fs;
fn main() -> Result<()> {
let data = fs::read("library.dll")?;
let module = MemoryModuleBuilder::new()
.resolve_imports(true)
.process_relocations(true)
.call_dll_main(true)
.load_from_memory(&data)?;
// Get a function from the loaded library
let function = module.get_proc_address("MyFunction")?;
Ok(())
}
§Platform Support
- Windows: Full support for PE executables and DLLs
- Linux: Placeholder implementation (planned for future release)
§Error Handling
All operations return a Result<T, MapleError>
with comprehensive error information:
use maple_rs::{Maple, MapleError};
match Maple::load_executable_from_memory(data) {
Ok(module) => {
// Successfully loaded
},
Err(MapleError::InvalidPEFormat(msg)) => {
eprintln!("Invalid PE file: {}", msg);
},
Err(MapleError::MemoryAllocation(msg)) => {
eprintln!("Memory allocation failed: {}", msg);
},
Err(e) => {
eprintln!("Other error: {}", e);
}
}
Re-exports§
pub use error::MapleError;
pub use memory_module::MemoryModule;
pub use memory_module::MemoryModuleBuilder;
Modules§
Structs§
- Maple
- Main entry point for the maple-rs library.
Type Aliases§
- Result
- Result type alias for all maple-rs operations.