0

I'm trying to read health in rust from a game called Assault cube. However i allways have 0 stored in buffer. can anyone explain what i´m doing wrong?

my code looks like this:

fn main(){
unsafe{
use std::ffi::c_void;
use windows_sys::Win32::Foundation::HANDLE;
let process_id:HANDLE = 13488;
let health_adress = 0x005954FC as *const c_void;
let buffer: *mut c_void = std::ptr::null_mut();
let mut number_read:usize= 0;
windows_sys::Win32::System::Diagnostics::Debug::ReadProcessMemory(process_id, health_adress, buffer,4 , &mut number_read);
println!("{:?}", buffer as i32);
}
}

the picture below shows how I got the address with Cheat Engine.

enter image description here

johnsc
  • 21
  • 5
  • Your `buffer` is null, `ReadProcessMemory` will not allocate space for you. Instead you'll want something like `let mut buffer: [u8; 4] = [0; 4]` and pass `buffer.as_mut_ptr().cast()` (or something similar) as the parameter. – kmdreko Nov 10 '22 at 15:30
  • You should also get in the habit of checking for failures when you call OS functions. – kmdreko Nov 10 '22 at 15:33
  • First ty for the help @kmdreko. That sounds logical to me but after changing the buffer to [u8; 4] = [0; 4] and casting the buffer in the function call the buffer is still equal to [0, 0, 0, 0] – johnsc Nov 10 '22 at 20:58
  • @johnsc You have the wrong [address and offset](https://www.unknowncheats.me/forum/other-fps-games/296747-assault-cube-base-address-offsets.html). – SuperUser Jan 16 '23 at 14:33

0 Answers0