I have this script written in rust that grabs the raw pointer of an initialized u8 value, prints the address of that pointer, then basically goes on pause waiting for a user input.
fn main() {
// Initialize `x` as raw pointer of `u8` value `43`
let x = &mut (43 as u8) as *mut u8;
println!("{:?}", x);
// Wait for user input so that `x` stays in place
drop(std::io::stdin().read_line(&mut String::new()));
}
The script above runs, prints the address of where x is being stored, then goes to "sleep", leaving x at that specific memory location. I was wondering if it were possible to run another process and use that specific memory address to grab the value of x. I used the following script that I wrote:
unsafe fn read<T>(addr: i64) -> &'static T {
&*(addr as *mut T)
}
fn main() {
unsafe {
println!("{}", read::<u8>(0xe1110ff9ef))
}
}
But it would always result with this error:
error: process didn't exit successfully: target\debug\t3.exe (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
Is this possible?