Пример #1
0
        private void Recv(TransferBuffer raw_buffer)
        {
            List <TransferBuffer> list = new List <TransferBuffer>();

            lock (m_lock)
            {
                PacketIO.PacketReader reader = new PacketIO.PacketReader(raw_buffer.Buffer);
                while (raw_buffer.Offset < raw_buffer.Size)
                {
                    ushort pLength = reader.ReadUInt16();
                    reader.ReadByte();
                    reader.ReadBytes(pLength - 3);

                    list.Add(new TransferBuffer(raw_buffer.Buffer, raw_buffer.Offset, pLength, false));
                    raw_buffer.Offset += pLength;
                }

                foreach (var item in list)
                {
                    var decryptedBytes = Crypto.CustomXTEA.Decrypt(item.Buffer.Skip(3).ToArray());
                    if (decryptedBytes.Length < 4)
                    {
                        Console.WriteLine("[SecurityAPI::Recv] Packet length cannot be lower than 4 bytes.");
                    }
                    Packet p = new Packet(decryptedBytes[0x02], decryptedBytes[0x03], decryptedBytes.Skip(0x04).ToArray());
                    p.Lock();
                    m_incoming.Add(p);
                }
            }
        }
Пример #2
0
        private bool CheckBuffer(byte[] bytes, int length)
        {
            TransferBuffer raw_buffer = new TransferBuffer(bytes, 0, length, false);

            PacketIO.PacketReader reader = new PacketIO.PacketReader(raw_buffer.Buffer);
            while (raw_buffer.Offset < raw_buffer.Size)
            {
                ushort pLength = reader.ReadUInt16();
                if (pLength + raw_buffer.Offset > raw_buffer.Size)
                {
                    return(false);
                }

                reader.ReadByte();
                reader.ReadBytes(pLength - 3);
                raw_buffer.Offset += pLength;
            }

            return(true);
        }