WriteProcessMemory function Null safety kernel32

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

Writes data to an area of memory in a specified process. The entire area to be written to must be accessible or the operation fails.

BOOL WriteProcessMemory(
  HANDLE  hProcess,
  LPVOID  lpBaseAddress,
  LPCVOID lpBuffer,
  SIZE_T  nSize,
  SIZE_T  *lpNumberOfBytesWritten
);

Implementation

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