Function read_process_memory::copy_address
source · pub fn copy_address<T>(
addr: usize,
length: usize,
source: &T
) -> Result<Vec<u8>>where
T: CopyAddress,
Expand description
Copy length
bytes of memory at addr
from source
.
This is just a convenient way to call CopyAddress::copy_address
without
having to provide your own buffer.
Examples found in repository?
examples/read-self.rs (line 10)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
let data = vec![17u8, 23u8, 45u8, 0u8];
let pid = unsafe { libc::getpid() } as Pid;
let addr = data.as_ptr() as usize;
let handle: ProcessHandle = pid.try_into().unwrap();
copy_address(addr, 4, &handle)
.map_err(|e| {
println!("Error: {:?}", e);
e
})
.map(|bytes| {
assert_eq!(bytes, vec![17u8, 23u8, 45u8, 0u8]);
println!("Success!")
})
.unwrap();
}
More examples
examples/read-process-bytes.rs (line 18)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
let pid = env::args().nth(1).unwrap().parse::<usize>().unwrap() as Pid;
let addr = usize::from_str_radix(&env::args().nth(2).unwrap(), 16).unwrap();
let size = env::args().nth(3).unwrap().parse::<usize>().unwrap();
let handle: ProcessHandle = pid.try_into().unwrap();
copy_address(addr, size, &handle)
.map_err(|e| {
println!("Error: {:?}", e);
e
})
.map(|bytes| {
println!(
"{} bytes at address {:x}:
{}
",
size,
addr,
bytes_to_hex(&bytes)
)
})
.unwrap();
}