Пример #1
0
        public void Add(params object[] subListValues)
        {
            var dn = new DNodeList();

            foreach (var obj in subListValues)
            {
                dn.Add(obj);
            }
            base.Add(dn);
        }
Пример #2
0
 public Message(MessageType type, MessageCode code, DNodeList args, byte numA, byte numB)
 {
     Type = type;
     Code = code;
     if (args == null)
     {
         args = new DNodeList();
     }
     Data = args;
     NumA = numA;
     NumB = numB;
 }
Пример #3
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;
        }
Пример #4
0
        protected DNodeList(byte[] data, ref int pos)
        {
            for (; pos < data.Length;)
            {
                byte type = data[pos];
                pos++;

                switch (type)
                {
                case (byte)'s':
                    int endPos;
                    for (endPos = pos; endPos < data.Length && data[endPos] != 0; endPos++)
                    {
                        ;
                    }
                    Add(new DNodeString(Global.ServerEncoding.GetString(data, pos, endPos - pos)));
                    pos = endPos + 1;
                    break;

                case (byte)'b':
                    int binLen = (data[pos] << 24) + (data[pos + 1] << 16) + (data[pos + 2] << 8) + data[pos + 3];

                    if (pos + 4 + binLen > data.Length)
                    {
                        throw new Exception("Binary DataElement too large!");
                    }

                    var binData = new byte[binLen];
                    Array.Copy(data, pos + 4, binData, 0, binLen);

                    Add(new DNodeBinary(binData));
                    pos += 4 + binLen;
                    break;

                case (byte)'[':
                    var subList = new DNodeList(data, ref pos);
                    if (data[pos - 1] != (byte)']')
                    {
                        throw new Exception("List not finished!");
                    }
                    Add(subList);
                    break;

                case (byte)']':
                    return;

                default:
                    throw new Exception("Unknown Element in DataList!");
                }
            }
        }
Пример #5
0
        public Message GetBfKeyResponse()
        {
            var rng = new RNGCryptoServiceProvider();

            Key = new byte[16];
            rng.GetBytes(Key);
            var encryptedBF = rsa.Encrypt(Key, false);

            var data = new DNodeList {
                2, { 1, encryptedBF.Length, encryptedBF }
            };

            return(new Message(MessageType.GSMessage, MessageCode.RSAEXCHANGE, data, 8, 2));
        }
Пример #6
0
 public Message(MessageType type, LobbyMessageCode lobbyCode, DNodeList lobbyArgs, byte numA, byte numB)
 {
     Type = type;
     Code = MessageCode.LOBBY_MSG;
     if (lobbyArgs == null)
     {
         lobbyArgs = new DNodeList();
     }
     Data = new DNodeList {
         (int)lobbyCode, lobbyArgs
     };
     NumA = numA;
     NumB = numB;
 }
Пример #7
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);
        }
Пример #8
0
        public void Add(IEnumerable <IDNode> nodes)
        {
            if (nodes == null)
            {
                return;
            }

            var dn = new DNodeList();

            foreach (var obj in nodes)
            {
                dn.Add(obj);
            }
            base.Add(dn);
        }
Пример #9
0
        public Message GetPublicKeyRequest() //sends the pubkey, requests a encrypted BF key
        {
            rsa = new RSACryptoServiceProvider(512);
            var rsaParams = rsa.ExportParameters(false);

            var pkData = new byte[260];

            pkData[1]   = 2; //0x200 = 512Bit
            pkData[259] = 3; //exp = 3
            Array.Copy(rsaParams.Modulus, 0, pkData, 0x44, 64);

            var data = new DNodeList {
                1, { 1, pkData.Length, pkData }
            };

            return(new Message(MessageType.GSMessage, MessageCode.RSAEXCHANGE, data, 8, 2));
        }
Пример #10
0
 public Message LobbyFailResponse(DNodeList args = null)
 {
     return(new Message(MessageType.GSMessage, LobbyMessageCode.LB_GSFAIL, new DNodeList {
         Data[0].AsString, args
     }, 1, 4));
 }
Пример #11
0
 public Message LobbySuccessResponse(DNodeList args = null)
 {
     return(new Message(MessageType.GSMessage, LobbyMessageCode.LB_GSSUCCESS, new DNodeList {
         Data[0].AsString, args
     }, 1, 4));
 }
Пример #12
0
 public Message FailResponse(DNodeList args = null)
 {
     return(new Message(MessageType.GSMessage, MessageCode.GSFAIL, new DNodeList {
         (byte)Code, args
     }, 1, 4));
 }
Пример #13
0
 public Message SuccessResponse(DNodeList args = null)
 {
     return(new Message(MessageType.GSMessage, MessageCode.GSSUCCESS, new DNodeList {
         (byte)Code, args
     }, 1, 4));
 }
Пример #14
0
 public Message(LobbyMessageCode lobbyCode, DNodeList lobbyArgs) : this(MessageType.GSMessage, lobbyCode, lobbyArgs, 1, 4)
 {
 }
Пример #15
0
 public Message(MessageCode code, DNodeList args) : this(MessageType.GSMessage, code, args, 1, 4)
 {
 }
Пример #16
0
 public CDKeyMessage(DNodeList data)
 {
     Data = data;
 }