Exemplo n.º 1
0
        public static void Hexdump(Packet packet, bool S_C, bool udp = false)
        {
            var bytes = packet.GetBytes();

            Console.WriteLine("[{0}] [{1:X2}-{2:X2}] [{3} bytes] [{4}]", S_C ? "S -> C" : "C -> S", packet.Opcode1, packet.Opcode2, bytes.Length, udp ? "UDP" : "TCP");

            for (int i = 0; i < bytes.Length; i += 16)
            {
                string strdump  = "";
                string hexBytes = "";
                for (int j = 0; j < 16; j++)
                {
                    if (i + j >= bytes.Length)
                    {
                        strdump  += " ";
                        hexBytes += "   ";
                    }
                    else
                    {
                        if (!char.IsControl((char)bytes[i + j]))
                        {
                            strdump += (char)bytes[i + j];
                        }
                        else
                        {
                            strdump += ".";
                        }

                        hexBytes += bytes[i + j].ToString("X2") + " ";
                    }
                }
                Console.WriteLine($"{i.ToString("x6")}: {hexBytes}    {strdump}");
            }
            Console.WriteLine();
        }
Exemplo n.º 2
0
        private TransferBuffer FormatPacket(Packet packet)
        {
            var bytes = packet.GetBytes();

            if (packet.Opcode == 0x00)
            {
                return(new TransferBuffer(bytes, 0, bytes.Length, false));
            }

            using (var pWriter = new PacketIO.PacketWriter())
            {
                pWriter.Write((ushort)(count | 2));
                pWriter.Write((byte)0x00);
                pWriter.Write((ushort)(bytes.Length));
                pWriter.Write(packet.Opcode1);
                pWriter.Write(packet.Opcode2);
                pWriter.Write((ushort)(bytes.Length + 7));
                pWriter.Write((byte)0x00); //USUALLY 0, UNKNOWN CURRENTLY
                pWriter.Write(bytes);

                var pbytes = pWriter.GetBytes().Skip(3).ToArray();

                var data = Crypto.UDPCrypto.Encrypt(pbytes);
                pWriter.Seek(0x03, System.IO.SeekOrigin.Begin);
                pWriter.Write(data);

                data    = pWriter.GetBytes();
                data[2] = (byte)((data.Length + 0x78) - (data.Sum(x => x) & 0xFF));

                count += 8;
                return(new TransferBuffer(data, 0, data.Length, false));
            }
        }
Exemplo n.º 3
0
        private TransferBuffer FormatPacket(Packet packet)
        {
            var pWriter   = new PacketIO.PacketWriter();
            var raw_bytes = packet.GetBytes();

            pWriter.Write((ushort)(raw_bytes.Length + 0x07));
            pWriter.Write((byte)0x00);
            pWriter.Write((ushort)(raw_bytes.Length + 0x04));
            pWriter.Write(packet.Opcode1);
            pWriter.Write(packet.Opcode2);
            pWriter.Write(raw_bytes);
            raw_bytes = Crypto.CustomXTEA.Encrypt(pWriter.GetBytes().Skip(3).ToArray());
            pWriter.Seek(0x03, System.IO.SeekOrigin.Begin);
            pWriter.Write(raw_bytes);
            return(new TransferBuffer(pWriter.GetBytes(), 0, raw_bytes.Length + 0x03, false));
        }
Exemplo n.º 4
0
 public static byte[] HexdumpBytes(Packet packet)
 {
     return(HexdumpBytes(packet.GetBytes()));
 }