public void Read(uint address, int length, byte[] buffer, int offset, ref int read) { // only check base address - would add too much overhead to check range // plus, it's much more likely that the entire range will be valid if the base address is if (safeMode & !Xbox.IsValidAddress(address)) { throw new Exception("Safe Mode detected invalid base address"); } int iterations = (int)length / bufferSize; int remainder = (int)length % bufferSize; read = 0; StatusResponse response; for (int i = 0; i < iterations; i++) { response = Xbox.SendCommand("getmem2 addr=0x{0} length={1}", Convert.ToString(address + read, 16).PadLeft(8, '0'), bufferSize); Xbox.Wait(bufferSize); Xbox.Connection.Client.Receive(buffer, (int)(offset + read), bufferSize, SocketFlags.None); read += bufferSize; } if (remainder > 0) { response = Xbox.SendCommand("getmem2 addr=0x{0} length={1}", Convert.ToString(address + read, 16).PadLeft(8, '0'), remainder); Xbox.Wait(remainder); Xbox.Connection.Client.Receive(buffer, (int)(offset + read), remainder, SocketFlags.None); read += remainder; } }
public void Read(string name, int offset, byte[] buffer, int length, ref int read) { int iterations = length / bufferSize; int remainder = length % bufferSize; int index = 0; StatusResponse Response; for (int i = 0; i < iterations; i++) { Response = Xbox.SendCommand("getfile name=\"{0}\" offset={1} size={2}", name, position + offset + index, bufferSize); if (Response.Type == ResponseType.BinaryResponse) { Xbox.Wait(4); byte[] temp = new byte[4]; Xbox.Connection.Client.Receive(temp, 4, SocketFlags.None); int bytesRead = BitConverter.ToInt32(temp, 0); if (bytesRead > 0) { Xbox.Wait((int)bytesRead); Xbox.Connection.Client.Receive(buffer, index, bufferSize, SocketFlags.None); read += bytesRead; index += bufferSize; position += (uint)read; } else { throw new IOException("File Read Failed"); } } else { throw new IOException("File Read Failed"); } } if (remainder > 0) { Response = Xbox.SendCommand("getfile name=\"{0}\" offset={1} size={2}", name, position + offset + index, remainder); if (Response.Type == ResponseType.BinaryResponse) { Xbox.Wait(4); byte[] temp = new byte[4]; Xbox.Connection.Client.Receive(temp, 4, SocketFlags.None); int bytesRead = BitConverter.ToInt32(temp, 0); if (bytesRead > 0) { Xbox.Wait((int)bytesRead); Xbox.Connection.Client.Receive(buffer, index, remainder, SocketFlags.None); read += bytesRead; position += (uint)read; } else { throw new IOException("File Read Failed"); } } else { throw new IOException("File Read Failed"); } } }