public PacketInfoForm(RawPacket packet) { InitializeComponent(); GUIHelpers.DragControl dc = new GUIHelpers.DragControl(this); dc.Add(pnlHeader, lblCaption); btnExit.Click += (s, e) => Close(); string opName = PacketController.Client.Processor.Serializer.Tables.Game.OpCodeToName[packet.OpCode]; lblOpCode.Text = packet.OpCode.ToString(); lblOpName.Text = opName; lblLength.Text = packet.Length.ToString(); tbData.Text = packet.Data.AsString(10000); PacketController.Client.Processor.Serializer.Info.TryGetValue(opName, out PacketReflectionInfo info); if (info != null) { pnlFields.Controls.Clear(); using (TeraBinaryReader reader = new TeraBinaryReader(packet.GetPayloadData())) { foreach (FieldInfo field in info.Fields) { FieldInfoControl ctrl = new FieldInfoControl(field.Name, reader.ReadString(field.FieldType)) { Dock = DockStyle.Top }; pnlFields.Controls.Add(ctrl); ctrl.BringToFront(); } } } }
public PacketLogReader(string fileName) { Stream stream = File.OpenRead(fileName); var magic = new byte[PacketLogEntry.Magic.Count]; if (stream.Read(magic, 0, magic.Length) != magic.Length) { throw new EndOfStreamException(); } if (!magic.SequenceEqual(PacketLogEntry.Magic)) { throw new InvalidDataException(); } Compressed = stream.ReadByte() != 0; if (Compressed) { stream = new DeflateStream(stream, CompressionMode.Decompress); } _reader = new TeraBinaryReader(stream); Version = _reader.ReadUInt32(); if (Version != PacketLogEntry.Version) { throw new InvalidDataException(); } var region = (Region)_reader.ReadByte(); if (!Enum.IsDefined(typeof(Region), region)) { throw new InvalidDataException(); } var clientVersion = _reader.ReadUInt32(); if (!OpCodeTable.Versions.Values.Contains(clientVersion)) { throw new InvalidDataException(); } Messages = new MessageTables(region, clientVersion); var serverCount = (int)_reader.ReadUInt32(); if (serverCount < 0) { throw new InvalidDataException(); } var servers = new Dictionary <int, ServerInfo>(serverCount); for (var i = 0; i < serverCount; i++) { var id = _reader.ReadInt32(); if (servers.ContainsKey(id)) { throw new InvalidDataException(); } var name = _reader.ReadString(); var size = _reader.ReadBoolean() ? 16 : 4; var realIPBytes = _reader.ReadBytes(size); var realPort = _reader.ReadUInt16(); var proxyIPBytes = _reader.ReadBytes(size); var proxyPort = _reader.ReadUInt16(); IPEndPoint realEP; IPEndPoint proxyEP; try { realEP = new IPEndPoint(new IPAddress(realIPBytes), realPort); proxyEP = new IPEndPoint(new IPAddress(proxyIPBytes), proxyPort); } catch (ArgumentException) { throw new InvalidDataException(); } servers.Add(id, new ServerInfo(id, name, realEP, proxyEP)); } Servers = servers; }
public static IEnumerable <PotentialString> FindStrings( byte[] payload, bool whiteSpace, bool control, int minLength) { using (var reader = new TeraBinaryReader(payload)) { for (var i = 0; i < reader.Length; i++) { reader.Position = i; if (!reader.CanRead(sizeof(ushort))) { break; } var offsetPos = reader.Position; var offset = reader.ReadUInt16() - PacketHeader.HeaderSize; if (offset < 0 || offset < offsetPos + sizeof(ushort) || offset > reader.Length - sizeof(char)) { continue; } reader.Position = offset; string str; try { str = reader.ReadString(); if (offset < offsetPos && reader.Position > offsetPos) { continue; } TeraBinaryReader.Encoding.GetString( TeraBinaryReader.Encoding.GetBytes(str)); } catch (Exception e) when(IsStringException(e)) { continue; } if (!whiteSpace && string.IsNullOrWhiteSpace(str)) { continue; } if (minLength != 0 && str.Length < minLength) { continue; } var hasBadChars = str.Any(c => { var cat = char.GetUnicodeCategory(c); return(cat == UnicodeCategory.Control || cat == UnicodeCategory.Format || cat == UnicodeCategory.OtherNotAssigned || cat == UnicodeCategory.PrivateUse || cat == UnicodeCategory.Surrogate); }); if (!control && hasBadChars) { continue; } yield return(new PotentialString(offsetPos, (ushort)offset, str)); } } }