/// <summary> Read the specified amount of memory at the given memory address </summary> /// <returns> The content of the memory. The amount of the read memory may be less then requested. </returns> public unsafe byte[] ReadMemory(ulong address, int size) { byte[] buffer = new byte[size]; int readCount; fixed(byte* pBuffer = buffer) { readCount = (int)corProcess.ReadMemory(address, (uint)size, new IntPtr(pBuffer)); } if (readCount != size) Array.Resize(ref buffer, readCount); return buffer; }
public byte[] ReadMemory(ulong address, uint size) { IntPtr bytesPtr = Marshal.AllocHGlobal((int)size); try { _comProcess.ReadMemory(address, size, bytesPtr, out size); byte[] bytes = new byte[size]; Marshal.Copy(bytesPtr, bytes, 0, (int)size); return(bytes); } finally { Marshal.FreeHGlobal(bytesPtr); } }