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)
5fn main() {
6 let data = vec![17u8, 23u8, 45u8, 0u8];
7 let pid = unsafe { libc::getpid() } as Pid;
8 let addr = data.as_ptr() as usize;
9 let handle: ProcessHandle = pid.try_into().unwrap();
10 copy_address(addr, 4, &handle)
11 .map_err(|e| {
12 println!("Error: {:?}", e);
13 e
14 })
15 .map(|bytes| {
16 assert_eq!(bytes, vec![17u8, 23u8, 45u8, 0u8]);
17 println!("Success!")
18 })
19 .unwrap();
20}More examples
examples/read-process-bytes.rs (line 18)
13fn main() {
14 let pid = env::args().nth(1).unwrap().parse::<usize>().unwrap() as Pid;
15 let addr = usize::from_str_radix(&env::args().nth(2).unwrap(), 16).unwrap();
16 let size = env::args().nth(3).unwrap().parse::<usize>().unwrap();
17 let handle: ProcessHandle = pid.try_into().unwrap();
18 copy_address(addr, size, &handle)
19 .map_err(|e| {
20 println!("Error: {:?}", e);
21 e
22 })
23 .map(|bytes| {
24 println!(
25 "{} bytes at address {:x}:
26{}
27",
28 size,
29 addr,
30 bytes_to_hex(&bytes)
31 )
32 })
33 .unwrap();
34}