maple-rs 0.1.0

A Rust library for loading Windows PE executables and DLLs directly from memory without writing to disk
Documentation

๐Ÿ maple-rs

Crates.io Documentation Build Status License: MIT

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
  • ๐Ÿ”น 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:

[dependencies]
maple-rs = "0.1.0"

Basic Usage

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 with Builder Pattern

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(())
}

๐Ÿ“– Documentation

Comprehensive API documentation is available on docs.rs.

๐Ÿ› ๏ธ Platform Support

Platform Status Features
Windows โœ… Complete Full PE parsing, import resolution, memory protection
Linux ๐Ÿ”„ Planned ELF support planned for future release
macOS ๐Ÿ”„ Planned Mach-O support planned for future release

๐Ÿงช Testing

The library includes comprehensive tests covering:

# Run all tests
cargo test

# Run with coverage
cargo tarpaulin --verbose --all-features --workspace --timeout 120

# Run examples
cargo run --example load_demo
cargo run --example load_focus

Tested with real-world executables including:

  • Console applications with dependencies
  • GUI applications with multiple DLLs
  • Complex import/export scenarios

๐Ÿ”ง Error Handling

All operations return a Result<T, MapleError> with detailed 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(MapleError::ImportResolution(msg)) => {
        eprintln!("Failed to resolve imports: {}", msg);
    },
    Err(e) => {
        eprintln!("Other error: {}", e);
    }
}

๐Ÿ—๏ธ Architecture

maple-rs/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ lib.rs              # Main library interface
โ”‚   โ”œโ”€โ”€ error.rs            # Error definitions  
โ”‚   โ”œโ”€โ”€ memory_module.rs    # Core trait and builder
โ”‚   โ”œโ”€โ”€ pe.rs              # PE format parser
โ”‚   โ”œโ”€โ”€ windows.rs         # Windows implementation
โ”‚   โ””โ”€โ”€ linux.rs           # Linux placeholder
โ”œโ”€โ”€ examples/              # Usage examples
โ”œโ”€โ”€ tests/                # Integration tests
โ””โ”€โ”€ .github/workflows/    # CI/CD pipeline

๐Ÿ” Security Considerations

  • Memory is properly allocated and protected with appropriate permissions
  • No disk writes required (stealth loading capability)
  • Import validation prevents malicious DLL injection
  • Proper cleanup prevents memory leaks
  • PE validation prevents malformed executables
  • Comprehensive error handling for security failures

๐Ÿค 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.

Development Setup

git clone https://github.com/K4HVH/maple-rs.git
cd maple-rs
cargo build
cargo test

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Inspired by the original MemoryModule C library
  • Built with modern Rust safety and performance characteristics
  • Thanks to the Rust community for excellent crates and tooling

๐Ÿ“š Related Projects

  • MemoryModule - Original C implementation
  • pe - PE format parsing
  • goblin - Multi-format binary parsing

โš ๏ธ Disclaimer: This software is provided for educational and legitimate use cases only. Users must ensure compliance with all applicable laws and regulations in their jurisdiction.