Beispiel #1
0
        public static IEnumerable <Message> ParseIncoming(byte[] data, Blowfish blowfishContext = null)
        {
            for (int pos = 0; pos < data.Length;)
            {
                if (pos + 6 > data.Length)
                {
                    throw new Exception("Incomplete Header received!");
                }

                int         packetSize = data[pos + 2] + 256 * data[pos + 1] + 256 * 256 * data[pos + 0];
                MessageType type       = (MessageType)(data[pos + 3] >> 6);
                MessageCode code       = (MessageCode)(data[pos + 4]);
                byte        numA       = (byte)(data[pos + 5] >> 4);
                byte        numB       = (byte)(data[pos + 5] & 0x0F);

                if (pos + packetSize > data.Length)
                {
                    throw new Exception("Incomplete message body received!");
                }

                var    argLen  = packetSize - 6;
                byte[] msgData = new byte[argLen];

                if (argLen != 0)
                {
                    Array.Copy(data, pos + 6, msgData, 0, argLen);

                    switch (type)
                    {
                    case MessageType.GSMessage:
                        XorCrypt.Decrypt(msgData);
                        break;

                    case MessageType.GSEncryptMessage:
                        if (blowfishContext == null)
                        {
                            throw new Exception("Received BF encrypted message, but no key available!");
                        }

                        blowfishContext.DecipherPadded(ref msgData);
                        break;

                    case MessageType.GameMessage:
                        throw new NotImplementedException("GameMessage received, WAT DO?");
                    }
                }

                yield return(new Message(type, code, DNodeList.Parse(msgData), numA, numB));

                pos += packetSize;
            }
            yield break;
        }
Beispiel #2
0
        public CDKeyMessage(byte[] data)
        {
            if (data[0] != 0xD3)
            {
                throw new Exception("CDKey Message: Unknown packet!");
            }

            int dataLen    = data[4];
            var packetData = new byte[dataLen];

            Array.Copy(data, 5, packetData, 0, dataLen);
            Global.CDKeyCrypt.DecipherPadded(ref packetData);

            Data = DNodeList.Parse(packetData);
        }