/// <summary> /// Writes to xbox memory. Performance of ~10MB/s due to a simple xbdm.dll modification. /// </summary> /// <param name="address"></param> /// <param name="length"></param> /// <param name="buffer"></param> /// <param name="offset"></param> public void Write(uint address, int length, byte[] buffer, int offset) { // 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 anyways if (safeMode & !Xbox.IsValidAddress(address)) { throw new Exception("Safe Mode detected invalid base address"); } int iterations = length / bufferSize; int remainder = length % bufferSize; int index = 0; StatusResponse Response; for (int i = 0; i < iterations; i++) { // hack: hijacked writefile routine in xbdm v7887 so that we can send binary data to memory instead of length-limited ascii Response = Xbox.SendCommand("writefile name=| offset=0x" + Convert.ToString(address, 16) + " length=" + bufferSize); if (Response.Type == ResponseType.ReadyForBinary) { Xbox.Connection.Client.Send(buffer, offset, bufferSize, SocketFlags.None); Response = Xbox.ReceiveStatusResponse(); // garbage number of bytes set...it keeps track of total, dont really care to find how to reset it // check for failure index += bufferSize; } else { throw new Exceptions.ApiException("SendCommand"); } } if (remainder > 0) { Response = Xbox.SendCommand("writefile name=| offset=0x" + Convert.ToString(address, 16) + " length=" + remainder); if (Response.Type == ResponseType.ReadyForBinary) { Xbox.Connection.Client.Send(buffer, offset, remainder, SocketFlags.None); Response = Xbox.ReceiveStatusResponse(); // check for failure - parse message and determine bytes written, then return index += bufferSize; } else { throw new Exceptions.ApiException("SendCommand"); } } }
public void Write(string name, int offset, byte[] buffer, int length) { int iterations = length / bufferSize; int remainder = length % bufferSize; int index = 0; this.position = (uint)offset; StatusResponse Response; for (int i = 0; i < iterations; i++) { Response = Xbox.SendCommand("writefile name=\"{0}\" offset={1} length={2}", name, position, bufferSize); if (Response.Type == ResponseType.ReadyForBinary) { Xbox.Connection.Client.Send(buffer, index, bufferSize, SocketFlags.None); if (Xbox.ReceiveStatusResponse().Success) { index += bufferSize; position += (uint)bufferSize; if (position > this.length) { this.length = position; } } else { throw new IOException("File Write Failed"); } } else { throw new IOException("File Write Failed"); } } if (remainder > 0) { Response = Xbox.SendCommand("writefile name=\"{0}\" offset={1} length={2}", name, position, remainder); if (Response.Type == ResponseType.ReadyForBinary) { Xbox.Connection.Client.Send(buffer, index, remainder, SocketFlags.None); if (Xbox.ReceiveStatusResponse().Success) { position += (uint)remainder; if (position > this.length) { this.length = position; } } else { throw new IOException("File Write Failed"); } } else { throw new IOException("File Write Failed"); } } }