/ bindings / rust / emf-rs / src / memory.rs
memory.rs
 1  use std::ffi::c_void;
 2  
 3  use crate::sys;
 4  
 5  pub struct Memory;
 6  
 7  impl Memory {
 8  	/// Scan memory for a signature.
 9  	///
10  	/// # Safety
11  	///
12  	/// This function is unsafe because it crosses the FFI boundary.
13  	pub unsafe fn sig_scan(sig: &str) -> *mut c_void {
14  		sys::scan_memory(sig.into())
15  	}
16  
17  	/// Read bytes from memory.
18  	///
19  	/// # Safety
20  	///
21  	/// This function is unsafe because it crosses the FFI boundary.
22  	pub unsafe fn read_bytes(address: *const u8, size: usize) -> Vec<u8> {
23  		sys::read_bytes(address as _, size).into()
24  	}
25  
26  	/// Write bytes to memory.
27  	///
28  	/// # Safety
29  	///
30  	/// This function is unsafe because it crosses the FFI boundary and writes directly to memory.
31  	pub unsafe fn write_bytes(address: *mut u8, bytes: Vec<u8>) {
32  		sys::write_bytes(address as _, bytes.into());
33  	}
34  
35  	/// Reassemble an instruction at an offset.
36  	///
37  	/// # Safety
38  	///
39  	/// This function is unsafe because it crosses the FFI boundary.
40  	pub unsafe fn reassemble_at_offset(bytes: Vec<u8>, offset: usize) -> Vec<u8> {
41  		sys::reassemble_instruction_at_offset(bytes.into(), offset).into()
42  	}
43  }