read_self/
read-self.rs

1/// Read bytes from the current process.
2use read_process_memory::*;
3use std::convert::TryInto;
4
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}