public static void WriteChatString(this StreamHandler Writer, string text) { byte[] bytes = Encoding.UTF8.GetBytes(text); Writer.WriteInt32(bytes.Length + 1); Writer.WriteBytes(bytes); Writer.WriteByte(0); }
protected override void ElementWrite(StreamHandler writer, int index) { if (index == -5) { writer.WriteUInt32(this.Unk); } else { index = -index - 1; writer.WriteInt32(this.Data[index].Length); writer.WriteBytes(this.Data[index]); } }
protected override unsafe void InternalWriteMetaData() { m_stream.DoAt(m_streamOriginalPosition, () => { var bytes = new byte[MainHeader.Size]; byte[] extraData; using (var writer = new StreamHandler()) { var flags = this.ExtraInfoFlags; if (flags.HasFlag(ExtraDataFlags.HasClientIPv4) || flags.HasFlag(ExtraDataFlags.HasClientIPv6)) { writer.WriteBytes(this.ClientAddress.GetAddressBytes()); } if (flags.HasFlag(ExtraDataFlags.HasServerIPv4) || flags.HasFlag(ExtraDataFlags.HasServerIPv6)) { writer.WriteBytes(this.ServerAddress.GetAddressBytes()); } if (flags.HasFlag(ExtraDataFlags.HasClientPort)) { writer.WriteInt32(this.ClientPort); } if (flags.HasFlag(ExtraDataFlags.HasServerPort)) { writer.WriteInt32(this.ServerPort); } if (flags.HasFlag(ExtraDataFlags.HasSnifferIdString)) { byte[] arr = Encoding.UTF8.GetBytes(this.SnifferDesc ?? string.Empty); writer.WriteInt32(arr.Length); using (MemoryStream oStream = new MemoryStream()) { // BUG http://blogs.msdn.com/b/bclteam/archive/2006/05/10/592551.aspx using (var ds = new DeflateStream(oStream, CompressionMode.Compress, true)) ds.Write(arr, 0, arr.Length); arr = oStream.ToArray(); } writer.WriteInt32(arr.Length); writer.WriteBytes(arr); } extraData = writer.ToByteArray(); } fixed(byte *bytesPtr = bytes) { var header = (MainHeader *)bytesPtr; header->PacketCount = this.Count; Marshal.Copy(SignatureBytes, 0, new IntPtr(header->Signature), SignatureBytes.Length); header->StartedOnTicks = this.StartTicks; header->StartedOnUnix = this.StartTime.ToUnixTime(); header->ExtraDataLength = extraData.Length; header->ExtraInfoFlags = this.ExtraInfoFlags; } m_stream.WriteBytes(bytes); m_stream.WriteBytes(extraData); }); }
protected unsafe override void InternalWriteMetaData() { m_stream.DoAt(m_streamOriginalPosition, () => { var bytes = new byte[MainHeader.Size]; byte[] extraData; using (var writer = new StreamHandler()) { var flags = this.ExtraInfoFlags; if (flags.HasFlag(ExtraDataFlags.HasClientIPv4) || flags.HasFlag(ExtraDataFlags.HasClientIPv6)) writer.WriteBytes(this.ClientAddress.GetAddressBytes()); if (flags.HasFlag(ExtraDataFlags.HasServerIPv4) || flags.HasFlag(ExtraDataFlags.HasServerIPv6)) writer.WriteBytes(this.ServerAddress.GetAddressBytes()); if (flags.HasFlag(ExtraDataFlags.HasClientPort)) writer.WriteInt32(this.ClientPort); if (flags.HasFlag(ExtraDataFlags.HasServerPort)) writer.WriteInt32(this.ServerPort); if (flags.HasFlag(ExtraDataFlags.HasSnifferIdString)) { byte[] arr = Encoding.UTF8.GetBytes(this.SnifferDesc ?? string.Empty); writer.WriteInt32(arr.Length); using (MemoryStream oStream = new MemoryStream()) { // BUG http://blogs.msdn.com/b/bclteam/archive/2006/05/10/592551.aspx using (var ds = new DeflateStream(oStream, CompressionMode.Compress, true)) ds.Write(arr, 0, arr.Length); arr = oStream.ToArray(); } writer.WriteInt32(arr.Length); writer.WriteBytes(arr); } extraData = writer.ToByteArray(); } fixed (byte* bytesPtr = bytes) { var header = (MainHeader*)bytesPtr; header->PacketCount = this.Count; Marshal.Copy(SignatureBytes, 0, new IntPtr(header->Signature), SignatureBytes.Length); header->StartedOnTicks = this.StartTicks; header->StartedOnUnix = this.StartTime.ToUnixTime(); header->ExtraDataLength = extraData.Length; header->ExtraInfoFlags = this.ExtraInfoFlags; } m_stream.WriteBytes(bytes); m_stream.WriteBytes(extraData); }); }