/// <summary> /// Reads memory from an external process into a buffer of allocated memory in the local process. /// </summary> /// <param name="hProcess">Handle to the external process from which memory will be read.</param> /// <param name="dwAddress">Address in external process from which memory will be read.</param> /// <param name="lpBuffer">Pointer to a buffer of allocated memory of at least nSize bytes.</param> /// <param name="nSize">Number of bytes to be read.</param> /// <returns>Returns the number of bytes actually read.</returns> public static int ReadRawMemory(IntPtr hProcess, uint dwAddress, IntPtr lpBuffer, int nSize) { int lpBytesRead = 0; try { if (!Imports.ReadProcessMemory(hProcess, dwAddress, lpBuffer, nSize, out lpBytesRead)) { throw new ReadMemoryException("ReadProcessMemory failed"); } return((int)lpBytesRead); } catch { return(0); } }