internal int ReadFromDevice(ref byte[] buffer, long offset, int index = 0, int count = -1) { SeekFSStream(offset); if (count <= 0) { count = buffer.Length; } #if DEBUG Main.SendDebug("Reading 0x{0:X} bytes from the device @ offset 0x{1:X} index in the buf: 0x{2:X}", count, offset, index); #endif if (NANDMMCStyle) { return(_fileStream.Read(buffer, index, count)); } uint readcount; bool res; if (index != 0) { res = NativeWin32.ReadFile(_deviceHandle, buffer, (uint)count, out readcount, IntPtr.Zero); } else { var tmp = new byte[count]; res = NativeWin32.ReadFile(_deviceHandle, tmp, (uint)count, out readcount, IntPtr.Zero); if (res) { Buffer.BlockCopy(tmp, 0, buffer, index, count); } } if (!res) { throw new X360NANDManagerException(X360NANDManagerException.ErrorLevels.Win32Error); } return((int)readcount); }