/// <summary> /// Read memory out of the target process. /// </summary> /// <param name="address">The address of memory to read</param> /// <param name="buffer">The buffer to read memory into</param> /// <param name="bytesRead">The number of bytes actually read out of the target process</param> /// <returns>true if any bytes were read at all, false if the read failed (and no bytes were read)</returns> public bool ReadMemory(ulong address, Span <byte> buffer, out int bytesRead) { int bytesRequested = buffer.Length; bool result = false; unsafe { fixed(byte *ptr = buffer) { result = _dataReader.ReadMemory(address, new IntPtr(ptr), bytesRequested, out bytesRead); } } // If the read failed or a successful partial read if (!result || (bytesRequested != bytesRead)) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // Check if the memory is in a module and cache it if it is if (_memoryCache.ReadMemory(address + (uint)bytesRead, buffer.Slice(bytesRead), out int read)) { bytesRead += read; result = true; } } } return(result); }
/// <summary> /// Read memory out of the target process. /// </summary> /// <param name="address">The address of memory to read</param> /// <param name="buffer">The buffer to read memory into</param> /// <param name="bytesRead">The number of bytes actually read out of the target process</param> /// <returns>true if any bytes were read at all, false if the read failed (and no bytes were read)</returns> public bool ReadMemory(ulong address, Span <byte> buffer, out int bytesRead) { int bytesRequested = buffer.Length; bytesRead = _dataReader.Read(address, buffer); // If the read failed or a successful partial read if (bytesRequested != bytesRead) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // Check if the memory is in a module and cache it if it is if (_memoryCache.ReadMemory(address + (uint)bytesRead, buffer.Slice(bytesRead), out int read)) { bytesRead += read; } } } return(bytesRead > 0); }