read_process_bytes/
read-process-bytes.rs

1extern crate libc;
2extern crate read_process_memory;
3
4use read_process_memory::*;
5use std::convert::TryInto;
6use std::env;
7
8fn bytes_to_hex(bytes: &[u8]) -> String {
9    let hex_bytes: Vec<String> = bytes.iter().map(|b| format!("{:02x}", b)).collect();
10    hex_bytes.join("")
11}
12
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}