rdbo / libmem

Advanced Game Hacking Library for C, Modern C++, Rust and Python (Windows/Linux/FreeBSD) (Process/Memory Hacking) (Hooking/Detouring) (Cross Platform) (x86/x64/ARM/ARM64) (DLL/SO Injection) (Internal/External) (Assembler/Disassembler)
GNU Affero General Public License v3.0
764 stars 92 forks source link

LM_ReadMemoryEx in rust returns bool type instead of number of bytes #138

Closed shay-V closed 11 months ago

shay-V commented 11 months ago

ReadProcessMemory returns a Boolean value

rdbo commented 11 months ago

It doesn't. It returns an Option<T>, where T is the type you're trying to read. libmem C binding:

        pub(super) fn LM_ReadMemoryEx(
            pproc: *const lm_process_t,
            src: lm_address_t,
            dst: *mut lm_byte_t,
            size: lm_size_t,
        ) -> lm_size_t;

Rust API:

pub fn LM_ReadMemoryEx<T>(pproc: &lm_process_t, src: lm_address_t) -> Option<T> 

The size of the read would be the size of T.

If it fails, it returns None instead of Some(val)

rdbo commented 11 months ago

@shay11111111111111111111 If you're talking about the actual Windows function, yes, it does return a boolean. But, the last parameter of ReadProcessMemory is a pointer to a variable that will store the size of the read operation:

BOOL ReadProcessMemory(
  [in]  HANDLE  hProcess,
  [in]  LPCVOID lpBaseAddress,
  [out] LPVOID  lpBuffer,
  [in]  SIZE_T  nSize,
  [out] SIZE_T  *lpNumberOfBytesRead
);