ReadProcessMemory() private method

private ReadProcessMemory ( IntPtr hProcess, UInt32 lpBaseAddress, IntPtr lpDest, uint nSize, int &lpNumberOfBytesRead ) : int
hProcess System.IntPtr
lpBaseAddress System.UInt32
lpDest System.IntPtr
nSize uint
lpNumberOfBytesRead int
return int
Ejemplo n.º 1
0
        private unsafe int Read(SafeProcessHandle handle, uint offset, uint size, byte *pBuffer)
        {
            if (Address == IntPtr.Zero)
            {
                throw new ObjectDisposedException("RemoteMemoryRegion");
            }
            if ((offset + size) > Size)
            {
                throw new ArgumentException("Size too large for region");
            }

            int bytesRead = 0, result;

            result = Win32.ReadProcessMemory(
                handle.DangerousGetHandle(),
                (uint)(Address.ToInt64() + offset),
                new IntPtr(pBuffer), size, out bytesRead
                );

            if (result == 0 || bytesRead != size)
            {
                var error = Win32.GetLastError();
                throw new Exception(String.Format("Read failed: Error {0:x8}", error));
            }

            return(bytesRead);
        }