-1

When I use the ReadProcessMemory function from the windows-rs package it returns 0. This is wrong, so I used the GetLastError() function and it returned "Only part of a ReadProcessMemory or WriteProcessMemory request was completed."

Here is the code for ReadProcessMemory:

unsafe{
    let mut healthValue: i32 = 0;
    ReadProcessMemory(
                      hProcess,
                      0xE6A848 as *mut c_void, 
                      healthValue as *mut c_void, 
                      std::mem::size_of::<i32> as usize, 
                      &mut 0
                      );

    println!("{}", healthValue);
    match GetLastError().ok() {
        Ok(_) => println!("no eror"),
        Err(t) => println!("error: {}", t),
    }
};

The code to get handle to the process:


let hProcess: HANDLE;
    unsafe{
        match OpenProcess(PROCESS_ALL_ACCESS, false, procId as u32) {
            Ok(T) => hProcess = T,
            Err(A) => {
                hProcess = INVALID_HANDLE_VALUE;
                println!("hproc is INVALID");  
            }
        }
    }

I have checked and the ProcId is right, I have used cheat engine to get the memory address, both apps are run in 32-bit, and my trainer is being run as admin. None of these have helped.

  • Whether to confirm that the entire area to be read must be accessible? Any process that has a handle with `PROCESS_VM_READ access` can call the function. I suggest you could specify the minimum set of access rights required for the operation. Try to use `PROCESS_VM_READ` instead of `PROCESS_ALL_ACCESS`. What is the return value of GetLastError? – Jeaninez - MSFT Nov 09 '22 at 07:06
  • @Jeaninez-MSFT I have changed the access rights to PROCESS_VM_READ. GetLastError still returns "Only part of a ReadProcessMemory or WriteProcessMemory request was completed." Do you think casting the base address and buffer to c_void is causing issues? – callfordoody Nov 09 '22 at 12:41

1 Answers1

0

Fixed it by changing healthValue as *mut c_void to ptr::addr_of_mut!(healthValue) as *mut c_void.