public static void HandleAuthResponse(Packet packet)
        {
            var code = (ResponseCode)packet.ReadByte();
            packet.WriteLine("Auth Code: " + code);

            switch (code)
            {
                case ResponseCode.AUTH_OK:
                {
                    ReadAuthResponseInfo(ref packet);
                    break;
                }
                case ResponseCode.AUTH_WAIT_QUEUE:
                {
                    if (packet.GetLength() <= 6)
                    {
                        ReadQueuePositionInfo(ref packet);
                        break;
                    }

                    ReadAuthResponseInfo(ref packet);
                    ReadQueuePositionInfo(ref packet);
                    break;
                }
            }
        }
示例#2
0
        public static string AsHex(this Packet packet)
        {
            var n       = Environment.NewLine;
            var hexDump = new StringBuilder();
            var length  = packet.GetLength();
            var stream  = packet.GetStream(0);

            var header = "|-------------------------------------------------|------------------" +
                         "---------------|" + n +
                         "| 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F | 0 1 2 3 4 5 6 7 8 9 A B C D E F |" +
                         n + "|-------------------------------------------------|------------------" +
                         "---------------|" + n;

            hexDump.Append(header);

            var end = length;

            for (var i = 0; i < end; i += 16)
            {
                var text = new StringBuilder();
                var hex  = new StringBuilder();
                hex.Append("| ");

                for (var j = 0; j < 16; j++)
                {
                    if (j + i < end)
                    {
                        var val = stream[j + i];
                        hex.Append(stream[j + i].ToString("X2"));
                        hex.Append(" ");

                        if (val >= 32 && val <= 127)
                        {
                            text.Append((char)val);
                        }
                        else
                        {
                            text.Append(".");
                        }

                        text.Append(" ");
                    }
                    else
                    {
                        hex.Append("   ");
                        text.Append("  ");
                    }
                }

                hex.Append("| ");
                hex.Append(text + "|");
                hex.Append(n);
                hexDump.Append(hex.ToString());
            }

            hexDump.Append("|-------------------------------------------------|------------------" +
                           "---------------|");

            return(hexDump.ToString());
        }
示例#3
0
 public static void HandleQuestCompletedResponse(Packet packet)
 {
     packet.ReadInt32("Count");
     // Prints ~4k lines of quest IDs, should be DEBUG only or something...
     /*
     for (var i = 0; i < count; i++)
         packet.ReadEntryWithName<Int32>(StoreNameType.Quest, "Rewarded Quest");
     */
     packet.WriteLine("Packet is currently not printed");
     packet.ReadBytes((int)packet.GetLength());
 }
示例#4
0
        public static void Parse(Packet packet, bool headerOnly = false, bool isMultiple = false)
        {
            ParsedStatus status;

            var opcode = packet.Opcode;

            packet.WriteLine("{0}: {1} (0x{2}) Length: {3} Time: {4} Number: {5}{6}",
                packet.Direction, Opcodes.GetOpcodeName(opcode), opcode.ToString("X4"),
                packet.GetLength(), packet.Time.ToString("MM/dd/yyyy HH:mm:ss.fff"),
                packet.Number, isMultiple ? " (part of another packet)" : String.Empty);

            if (opcode == 0)
                return;

            if (headerOnly)
                status = ParsedStatus.Success;
            else
            {
                Action<Packet> handler;
                if (Handlers.TryGetValue(opcode, out handler))
                {
                    try
                    {
                        handler(packet);

                        if (packet.GetPosition() == packet.GetLength())
                            status = ParsedStatus.Success;
                        else
                        {
                            var pos = packet.GetPosition();
                            var len = packet.GetLength();
                            packet.WriteLine("Packet not fully read! Current position is {0}, length is {1}, and diff is {2}.",
                                pos, len, len - pos);

                            if (len < 300) // If the packet isn't "too big" and it is not full read, print its hex table
                                packet.AsHex();

                            status = ParsedStatus.WithErrors;
                        }
                    }
                    catch (Exception ex)
                    {
                        packet.WriteLine(ex.GetType());
                        packet.WriteLine(ex.Message);
                        packet.WriteLine(ex.StackTrace);

                        status = ParsedStatus.WithErrors;
                    }
                }
                else
                {
                    packet.AsHex();
                    status = ParsedStatus.NotParsed;
                }
            }

            if (isMultiple == false)
            {
                packet.Status = status;
                var data = status == ParsedStatus.Success ? Opcodes.GetOpcodeName(packet.Opcode) : status.ToString();
                packet.AddSniffData(StoreNameType.Opcode, packet.Opcode, data);
            }
        }
示例#5
0
        public static void ReadClientAddonsList(ref Packet packet)
        {
            var decompCount = packet.ReadInt32();
            packet = packet.Inflate(decompCount);

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_0_8_9464))
            {
                var count = packet.ReadInt32("Addons Count");
                _addonCount = count;

                for (var i = 0; i < count; i++)
                {
                    packet.ReadCString("Name", i);
                    packet.ReadBoolean("Enabled", i);
                    packet.ReadInt32("CRC", i);
                    packet.ReadInt32("Unk Int32", i);
                }

                packet.ReadTime("Time");
            }
            else
            {
                int count = 0;

                while (packet.GetPosition() != packet.GetLength())
                {
                    packet.ReadCString("Name");
                    packet.ReadBoolean("Enabled");
                    packet.ReadInt32("CRC");
                    packet.ReadInt32("Unk Int32");

                    count++;
                }

                _addonCount = count;
            }
        }
示例#6
0
        public static void Parse(Packet packet, bool headerOnly = false)
        {
            var opcode = packet.Opcode;

            packet.Writer.WriteLine("{0}: {1} (0x{2}) Length: {3} Time: {4} Number: {5}",
                packet.Direction, Opcodes.GetOpcodeName(opcode), opcode.ToString("X4"),
                packet.GetLength(), packet.Time.ToString("MM/dd/yyyy HH:mm:ss.fff"), packet.Number);

            if (headerOnly)
            {
                lock (Handlers)
                {
                    Statistics.PacketsSuccessfullyParsed++;
                }
                return;
            }

            Action<Packet> handler;
            if (Handlers.TryGetValue(opcode, out handler))
            {
                try
                {
                    handler(packet);

                    if (packet.GetPosition() == packet.GetLength())
                        lock (Handlers)
                        {
                            Statistics.PacketsSuccessfullyParsed++;
                        }
                    else
                    {
                        var pos = packet.GetPosition();
                        var len = packet.GetLength();
                        packet.Writer.WriteLine("Packet not fully read! Current position is {0}, length is {1}, and diff is {2}.",
                            pos, len, len - pos);

                        if (len < 300) // If the packet isn't "too big" and it is not full read, print its hex table
                            packet.Writer.WriteLine(packet.AsHex());

                        lock (Handlers)
                        {
                            Statistics.PacketsParsedWithErrors++;
                        }
                    }
                }
                catch (Exception ex)
                {
                    packet.Writer.WriteLine(ex.GetType());
                    packet.Writer.WriteLine(ex.Message);
                    packet.Writer.WriteLine(ex.StackTrace);

                    lock (Handlers)
                    {
                        Statistics.PacketsParsedWithErrors++;
                    }
                }
            }
            else
            {
                packet.Writer.WriteLine(packet.AsHex());
                lock (Handlers)
                {
                    Statistics.PacketsNotParsed++;
                }
            }
        }