public void Dump(string reason) { byte[] numArray = new byte[this._buffer.Length]; Buffer.BlockCopy((Array)this._buffer, this._bufferPosition, (Array)numArray, 0, this._buffer.Length - this._bufferPosition); Buffer.BlockCopy((Array)this._buffer, 0, (Array)numArray, this._buffer.Length - this._bufferPosition, this._bufferPosition); StringBuilder stringBuilder = new StringBuilder(); int num = 1; for (int index1 = 0; index1 < this._packets.Length; ++index1) { PacketHistory.PacketView packet = this._packets[(index1 + this._historyPosition) % this._packets.Length]; if (packet.Offset != 0 || packet.Length != 0) { stringBuilder.Append(string.Format("Packet {0} [Assumed MessageID: {4}, Size: {2}, Buffer Position: {1}, Timestamp: {3:G}]\r\n", (object)num++, (object)packet.Offset, (object)packet.Length, (object)packet.Time, (object)this._buffer[packet.Offset])); for (int index2 = 0; index2 < packet.Length; ++index2) { stringBuilder.Append(this._buffer[packet.Offset + index2].ToString("X2") + " "); if (index2 % 16 == 15 && index2 != this._packets.Length - 1) { stringBuilder.Append("\r\n"); } } stringBuilder.Append("\r\n\r\n"); } } stringBuilder.Append(reason); Directory.CreateDirectory(Path.Combine(Main.SavePath, "NetDump")); File.WriteAllText(Path.Combine(Main.SavePath, "NetDump", this.CreateDumpFileName()), stringBuilder.ToString()); }
private PacketHistory.PacketView AppendPacket(int size) { int offset = this._bufferPosition; if (offset + size > this._buffer.Length) { offset = 0; } PacketHistory.PacketView packetView = new PacketHistory.PacketView(offset, size, DateTime.Now); this._packets[this._historyPosition] = packetView; this._historyPosition = (this._historyPosition + 1) % this._packets.Length; this._bufferPosition = offset + size; return(packetView); }
public void Record(byte[] buffer, int offset, int length) { length = Math.Max(0, length); PacketHistory.PacketView packetView = this.AppendPacket(length); Buffer.BlockCopy((Array)buffer, offset, (Array)this._buffer, packetView.Offset, length); }