public unsafe int ReadMemory(UniPtr address, byte[] buffer, int offset, int count, bool throwOnError) { if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } if (offset + count > buffer.Length) { throw new ArgumentException(); } long actualCount = 0; int result; fixed(byte *p = buffer) { result = NativeMethods.NtWow64ReadVirtualMemory64( _hProcess, address.ToInt64(), p + offset, count, ref actualCount); } if (result != NativeMethods.STATUS_SUCCESS) { return(-1); } return((int)actualCount); }
public ProcessMemoryStream(IProcessMemoryAdapter adapter, UniPtr baseAddress, long regionLength) { _adapter = adapter; _baseAddress = baseAddress; _regionLength = regionLength; _pageSize = (uint)adapter.PageSize; _firstPageAddress = GetPageLowerBound(baseAddress); }
public unsafe int ReadMemory(UniPtr address, byte[] buffer, int offset, int count, bool throwOnError) { if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } if (offset + count > buffer.Length) { throw new ArgumentException(); } var actualCount = IntPtr.Zero; bool result; fixed(byte *p = buffer) { result = NativeMethods.ReadProcessMemory( _hProcess, address, p + offset, new IntPtr(count), ref actualCount); } if (!result) { if (throwOnError) { int error = Marshal.GetLastWin32Error(); if (error != 0) { throw new Win32Exception(error); } } return(-1); } return(actualCount.ToInt32()); }