Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
shay-V opened this issue Sep 13, 2023 · 2 comments
Closed

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

shay-V opened this issue Sep 13, 2023 · 2 comments

Comments

@shay-V
Copy link

shay-V commented Sep 13, 2023

ReadProcessMemory returns a Boolean value

@rdbo
Copy link
Owner

rdbo commented Sep 14, 2023

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 rdbo closed this as completed Sep 14, 2023
@rdbo
Copy link
Owner

rdbo commented Sep 14, 2023

@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
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants