Game Memory Utils
A Rust library for reading and writing process memory on Linux, designed for easy trainer creation!
Features
- Process Memory Access: Read and write to any process memory using
/proc/pid/mem - Pattern Scanning: Advanced byte pattern matching with wildcard support
- Module Management: Find and work with loaded modules/libraries
- Safe Memory Operations: Type-safe memory operations with error handling
- Ptrace Integration: Automatic process attachment and detachment
- Debug Support: Optional debug output for troubleshooting
Installation
Add to your Cargo.toml:
[]
= "0.2.0"
Or use cargo add:
Quick Start
use ;
Usage Examples
Process Attachment
// Attach by process name
let mut mem = new?;
// Attach by PID
let mut mem = from_pid?;
// Enable debug output
let mut mem = new?;
Reading Memory
// Read at absolute address
let value: u32 = mem.read_at?;
// Read at offset from base address
let value: u32 = mem.read?;
// Read using hex string offset
let value: u32 = mem.read_hex?;
// Read raw bytes
let bytes = mem.read_bytes?;
// Read null-terminated string
let text = mem.read_string?;
// Read specific integer types
let val_u32 = mem.read_u32_le?;
let val_u64 = mem.read_u64_le?;
Writing Memory
// Write at absolute address
mem.write_at?;
// Write at offset from base address
mem.write?;
// Write using hex string offset
mem.write_hex?;
// Write raw bytes
mem.write_bytes?;
// Write specific integer types
mem.write_u32_le?;
mem.write_u64_le?;
Pattern Scanning
// Scan all readable+executable memory regions
if let Some = mem.pattern_scan_all_process_memory?
// Scan specific module
if let Some = mem.pattern_scan_module?
// Pattern syntax: hex bytes with ?? for wildcards
// Examples:
// "48 89 E5" - exact bytes
// "48 ?? E5" - wildcard in middle
// "?? 89 ?? ?? ?? C3" - multiple wildcards
Module Management
// Get process and base address info
let pid = mem.pid;
let base_addr = mem.base_address;
// Find module base address
let module_base = mem.find_module_base?;
// List all loaded modules
let modules = mem.find_loaded_modules?;
for in modules
// Filter modules by regex
let filtered = mem.filter_modules_by_regex?;
Using the hex! Macro
use hex;
// Convert hex strings to u64 at compile time
let address = hex!; // 0x8320b84
let value: u32 = mem.read_at?;
Error Handling
The library uses a comprehensive error system:
use MemoryError;
match mem.
Debug Mode
Enable debug output to troubleshoot memory operations:
let mut mem = new?; // Enable debug
// Debug output will show:
// - Memory region scanning details
// - Pattern matching progress
// - Ptrace operation results
// - Module loading information
Requirements
- Linux: This library is Linux-specific and uses
/proc/pid/memandptrace - Permissions: May require
sudoor appropriate capabilities to attach to processes - Target Process: The target process should be running and accessible
Supported Platforms
- Linux (x86_64, ARM64, and other architectures supported by Rust)
- Wine/Proton games
Safety Notes
- This library directly manipulates process memory, which can cause crashes if used incorrectly
- Always validate addresses and data before writing
- The target process will be temporarily stopped during attachment
- Automatic cleanup ensures processes are properly detached
License
Licensed under the MIT license. See LICENSE for details.
Changelog
0.2.0
- Added comprehensive pattern scanning with wildcard support
- Added debug mode for troubleshooting
- Enhanced error handling and reporting
- Added support for regex-based module filtering
- Process attachment via ptrace
0.1.2
- Initial release with basic memory read/write operations
- Module base address detection