ReadProcessMemory function Null safety kernel32

int ReadProcessMemory(
  1. int hProcess,
  2. Pointer<NativeType> lpBaseAddress,
  3. Pointer<NativeType> lpBuffer,
  4. int nSize,
  5. Pointer<IntPtr> lpNumberOfBytesRead
)

ReadProcessMemory copies the data in the specified address range from the address space of the specified process into the specified buffer of the current process. Any process that has a handle with PROCESS_VM_READ access can call the function.

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

Implementation

int ReadProcessMemory(int hProcess, Pointer lpBaseAddress, Pointer lpBuffer,
    int nSize, Pointer<IntPtr> lpNumberOfBytesRead) {
  final _ReadProcessMemory = _kernel32.lookupFunction<
      Int32 Function(IntPtr hProcess, Pointer lpBaseAddress, Pointer lpBuffer,
          IntPtr nSize, Pointer<IntPtr> lpNumberOfBytesRead),
      int Function(int hProcess, Pointer lpBaseAddress, Pointer lpBuffer,
          int nSize, Pointer<IntPtr> lpNumberOfBytesRead)>('ReadProcessMemory');
  return _ReadProcessMemory(
      hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead);
}