Пример #1
0
 protected override void ParseBody()
 {
     Decrypt(User.TXProtocol.BufDhShareKey);
     Result = Reader.ReadByte();
     //返回错误
     if (Result == (byte)ResultCode.DoMain || Result == (byte)ResultCode.其它错误 ||
         Result == (byte)ResultCode.密码错误 || Result == (byte)ResultCode.帐号被回收 ||
         Result == (byte)ResultCode.要求切换TCP || Result == (byte)ResultCode.过载保护 ||
         Result == (byte)ResultCode.需要验证密保 || Result == (byte)ResultCode.需要验证码)
     {
         var tlvs = Tlv.ParseTlv(Reader.ReadBytes((int)(Reader.BaseStream.Length - 1)));
         //重置指针(因为tlv解包后指针已经移动到末尾)
         Reader.BaseStream.Position = 1;
         TlvExecutionProcessing(tlvs);
         if (tlvs.Any(c => c.Tag == 0x0100))
         {
             var errorData = tlvs.FirstOrDefault(c => c.Tag == 0x0100);
             var errReader = new BinaryReader(new MemoryStream(errorData.Value));
             var tlv       = new TLV0100();
             tlv.Parser_Tlv2(User, errReader, errorData.Length);
             ErrorMsg = tlv.ErrorMsg;
         }
     }
     else
     {
         BodyDecrypted = QQTea.Decrypt(BodyDecrypted, User.TXProtocol.BufTgtgtKey);
         Reader        = new BinaryReader(new MemoryStream(BodyDecrypted));
         Result        = Reader.ReadByte();
         var tlvs = Tlv.ParseTlv(Reader.ReadBytes((int)(Reader.BaseStream.Length - 1)));
         //重置指针(因为tlv解包后指针已经移动到末尾)
         Reader.BaseStream.Position = 1;
         TlvExecutionProcessing(tlvs);
     }
 }
Пример #2
0
        protected override void ParseBody(ByteBuffer byteBuffer)
        {
            //密文
            byte[] CipherText = byteBuffer.ToByteArray();
            //明文
            bodyDecrypted = QQTea.Decrypt(CipherText, byteBuffer.Position, CipherText.Length - byteBuffer.Position - 1, user.QQ_SessionKey);
            //提取数据
            ByteBuffer buf = new ByteBuffer(bodyDecrypted);

            FromQQ = (long)Util.GetQQNumRetUint(Util.ToHex(buf.GetByteArray(4)));
            buf.GetByteArray(4);//自己的QQ
            buf.GetByteArray(10);
            MessageType = buf.GetByteArray(2);
            buf.GetChar();
            buf.GetByteArray(buf.GetChar()); //未知
            buf.GetChar();                   //消息来源QQ的版本号
            buf.GetByteArray(4);             //FromQQ
            buf.GetByteArray(4);             //自己的QQ
            buf.GetByteArray(20);
            MessageDateTime = buf.GetByteArray(4);
            buf.GetChar();       //00
            buf.GetByteArray(4); //MessageDateTime
            buf.GetByteArray(5); //00
            buf.GetByteArray(3);
            buf.GetByteArray(5); //00
            buf.GetByteArray(4); //MessageDateTime
            buf.GetByteArray(4);
            buf.GetByteArray(8);
            FontStyle = buf.GetByteArray(buf.GetChar());
            buf.GetByteArray(6);
            MessageLength = buf.GetChar();
            MessageData   = Util.ConvertHexToString(Util.ToHex(buf.GetByteArray(MessageLength)));
            buf.GetByteArray(22);
        }
Пример #3
0
        protected override void ParseBody(ByteBuffer byteBuffer)
        {
            //密文
            byte[] CipherText = byteBuffer.ToByteArray();
            //明文
            bodyDecrypted = QQTea.Decrypt(CipherText, byteBuffer.Position, CipherText.Length - byteBuffer.Position - 1, user.QQ_SessionKey);
            //提取数据
            ByteBuffer buf = new ByteBuffer(bodyDecrypted);

            buf.GetByteArray(4);
            buf.GetByteArray(4);         //自己的QQ
            buf.GetByteArray(10);
            MessageType = buf.GetChar(); //消息类型
            if (MessageType == (char)0x0052)
            {
                buf.GetByteArray(2);
                buf.GetByteArray(buf.GetChar());
                Group = (long)Util.GetQQNumRetUint(Util.ToHex(buf.GetByteArray(4)));            //群号
                buf.Get();
                FromQQ = (long)Util.GetQQNumRetUint(Util.ToHex(buf.GetByteArray(4)));           //发消息人的QQ
                buf.GetByteArray(4);
                ReceiveTime = buf.GetByteArray(4);                                              //接收时间
                buf.GetByteArray(24);
                SendTime = buf.GetByteArray(4);                                                 //发送时间
                buf.GetByteArray(12);
                Font = buf.GetByteArray(buf.GetChar());                                         //字体
                buf.GetByteArray(6);
                Message = Util.ConvertHexToString(Util.ToHex(buf.GetByteArray(buf.GetChar()))); //消息
                buf.GetByteArray(58);
                buf.GetByteArray(buf.GetChar());                                                //消息
                buf.GetByteArray(11);
            }
        }
Пример #4
0
        protected override void ParseBody(ByteBuffer byteBuffer)
        {
            //密文
            byte[] CipherText = byteBuffer.ToByteArray();
            //明文
            bodyDecrypted = QQTea.Decrypt(CipherText, byteBuffer.Position, CipherText.Length - byteBuffer.Position - 1, _secretKey);
            //提取数据
            ByteBuffer buf = new ByteBuffer(bodyDecrypted);

            VerifyType = buf.Get();
            buf.GetChar();
            Status = buf.Get();
            buf.GetByteArray(4);
            user.QQ_PACKET_00BAVerifyToken = buf.GetByteArray(buf.GetChar());
            VerifyCode    = buf.GetByteArray(buf.GetChar());
            VerifyCommand = buf.Get();
            if (VerifyCommand == 0x00)
            {
                VerifyCommand = buf.Get();
            }
            buf.Get();
            if (user.QQ_PACKET_00BAVerifyCode?.Length == 0 || user.QQ_PACKET_00BAVerifyCode == null)
            {
                user.QQ_PACKET_00BAVerifyCode = VerifyCode;
            }
            else
            {
                byte[] resultArr = new byte[user.QQ_PACKET_00BAVerifyCode.Length + VerifyCode.Length];
                user.QQ_PACKET_00BAVerifyCode.CopyTo(resultArr, 0);
                VerifyCode.CopyTo(resultArr, user.QQ_PACKET_00BAVerifyCode.Length);
                user.QQ_PACKET_00BAVerifyCode = resultArr;
            }
            user.QQ_PACKET_00BAToken = buf.GetByteArray(buf.GetChar());
            buf.GetByteArray(buf.GetChar());
        }
Пример #5
0
 private void Menu_C_tostr(object sender, RoutedEventArgs e)
 {
     if (textEditor.SelectedText.Length > 0)
     {
         textEditor.SelectedText += "  //" + Encoding.Default.GetString(QQTea.Strtobyte(textEditor.SelectedText));
     }
 }
Пример #6
0
        protected override void ParseBody(ByteBuffer byteBuffer)
        {
            //密文
            byte[] CipherText = byteBuffer.ToByteArray();
            //明文
            bodyDecrypted = QQTea.Decrypt(CipherText, byteBuffer.Position, CipherText.Length - byteBuffer.Position - 1, user.QQ_0828_rec_decr_key);

            //提取数据
            ByteBuffer buf = new ByteBuffer(bodyDecrypted);

            if (GetPacketLength() == 407)
            {
                buf.GetByteArray(15);
                user.QQ_SessionKey = buf.GetByteArray(0x10);
            }
            else if (GetPacketLength() == 439 || GetPacketLength() == 527)
            {
                buf.GetByteArray(63);
                user.QQ_SessionKey = buf.GetByteArray(0x10);
            }
            else
            {
                throw new Exception("登录失败");
            }
        }
Пример #7
0
 protected override void ParseBody(ByteBuffer byteBuffer)
 {
     //密文
     byte[] CipherText = byteBuffer.ToByteArray();
     //明文
     bodyDecrypted = QQTea.Decrypt(CipherText, byteBuffer.Position, CipherText.Length - byteBuffer.Position - 1, user.QQ_SessionKey);
     //提取数据
     ByteBuffer buf = new ByteBuffer(bodyDecrypted);
 }
Пример #8
0
        public byte[] Get_Tlv(QQUser user)
        {
            var data = new TLV0015().Get_Tlv(user);

            var encode = QQTea.Encrypt(data, user.TXProtocol.BufTgtgtKey);

            FillHead(Command);
            FillBody(encode, encode.Length);
            SetLength();
            return(GetBuffer());
        }
Пример #9
0
        public byte[] get_tlv_001A(QQClient m_PCClient)
        {
            var data = new TLV_0015().get_tlv_0015(m_PCClient);

            var encode = QQTea.Encrypt(data, m_PCClient.QQUser.TXProtocol.bufTGTGTKey);

            fill_head(cmd);
            fill_body(encode, encode.Length);
            set_length();
            return(get_buf());
        }
Пример #10
0
        public System.Byte[] Get_Tlv(QQAccount user)
        {
            var data = new TLV0015().Get_Tlv(user);

            var encode = QQTea.Encrypt(data, user.TXProtocol.BufTgtgtKey);

            this.FillHead(this.Command);
            this.FillBody(encode, encode.Length);
            this.SetLength();
            return(this.GetBuffer());
        }
Пример #11
0
        public void Decrypt(byte[] key)
        {
            BodyDecrypted = QQTea.Decrypt(Buffer, (int)Reader.BaseStream.Position,
                                          (int)(Buffer.Length - Reader.BaseStream.Position - 1), key);
            if (BodyDecrypted == null)
            {
                throw new Exception($"包内容解析出错,抛弃该包: {ToString()}");
            }

            Reader = new BinaryReader(new MemoryStream(BodyDecrypted));
        }
Пример #12
0
        /// <summary>
        ///     初始化包体
        /// </summary>
        protected override void PutBody()
        {
            var pic      = new Bitmap(FileName);
            var width    = pic.Size.Width;  // 图片的宽度
            var height   = pic.Size.Height; // 图片的高度
            var picBytes = ImageHelper.ImageToBytes(pic);
            var md5      = QQTea.MD5(picBytes);

            var data = new BinaryWriter(new MemoryStream());

            data.Write(new byte[]
            {
                0x01, 0x08, 0x01, 0x12
            });
            data.Write((byte)0x5A);
            data.Write((byte)0x08);
            data.Write(Util.HexStringToByteArray(Util.PB_toLength(User.QQ)));
            data.Write((byte)0x10);
            data.Write(Util.HexStringToByteArray(Util.PB_toLength(ToQQ)));
            data.BeWrite((ushort)0x1800);
            data.Write((byte)0x22);
            data.Write((byte)0x10);
            data.Write(md5);
            data.Write((byte)0x28);
            data.Write(Util.HexStringToByteArray(Util.PB_toLength(picBytes.Length)));
            data.Write((byte)0x32);
            data.Write((byte)0x1A);
            data.Write(new byte[]
            {
                0x57, 0x00, 0x53, 0x00, 0x4E, 0x00, 0x53, 0x00, 0x4C, 0x00, 0x54, 0x00,
                0x31, 0x00, 0x36, 0x00, 0x47, 0x00, 0x45, 0x00, 0x4F, 0x00, 0x5B, 0x00,
                0x5F, 0x00
            });
            data.BeWrite((ushort)0x3801);
            data.BeWrite((ushort)0x4801);
            data.Write((byte)0x70);
            data.Write(Util.HexStringToByteArray(Util.PB_toLength(width)));
            data.Write((byte)0x78);
            data.Write(Util.HexStringToByteArray(Util.PB_toLength(height)));

            BodyWriter.Write(new byte[]
            {
                0x00, 0x00, 0x00, 0x07
            });
            //数据长度
            BodyWriter.BeWrite(data.BaseStream.Length);
            BodyWriter.Write(new byte[]
            {
                0x08, 0x01, 0x12, 0x03, 0x98, 0x01
            });
            //数据
            BodyWriter.Write(data.BaseStream.ToBytesArray());
        }
Пример #13
0
 private void Btn_click_d(object sender, RoutedEventArgs e)
 {
     byte[] tmp_key  = QQTea.Strtobyte(Tea_key.Text);
     byte[] tmp_data = QQTea.Strtobyte(Tea_in.Text);
     if (tmp_data.Length > 0 && tmp_key.Length > 0)
     {
         byte[] redata = QQTea.Decrypt(tmp_data, 0, tmp_data.Length, tmp_key);
         if (redata != null)
         {
             Tea_out.Text = QQTea.Bytetostr(redata);
         }
     }
 }
Пример #14
0
 private void Menu_Tea_d0(object sender, RoutedEventArgs e)
 {
     byte[] tmp_key  = new byte[16];
     byte[] tmp_data = QQTea.Strtobyte(textEditor.SelectedText);
     if (tmp_data.Length > 0 && tmp_key.Length > 0)
     {
         byte[] redata = QQTea.Decrypt(tmp_data, 0, tmp_data.Length, tmp_key);
         if (redata != null)
         {
             textEditor.SelectedText += "\nTea解密 key " + QQTea.Bytetostr(tmp_key) + "\n" + QQTea.Bytetostr(redata) + "\nTea解密end";
         }
     }
 }
Пример #15
0
        /// <summary>
        ///     初始化包体
        /// </summary>
        protected override void PutBody()
        {
            var pic    = new Bitmap(FileName);
            var width  = pic.Size.Width;  // 图片的宽度
            var height = pic.Size.Height; // 图片的高度
            //var Md5 = Util.GetMD5ToGuidHashFromFile(fileName);
            var picBytes = ImageHelper.ImageToBytes(pic);
            var md5      = QQTea.MD5(picBytes);

            BodyWriter.Write(new byte[]
            {
                0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x5E, 0x08,
                0x01, 0x12, 0x03, 0x98, 0x01, 0x01, 0x10, 0x01, 0x1A
            });
            BodyWriter.Write((byte)0x5A);
            BodyWriter.Write((byte)0x08);
            BodyWriter.Write(Util.HexStringToByteArray(Util.PB_toLength(Group)));
            BodyWriter.Write((byte)0x10);
            BodyWriter.Write(Util.HexStringToByteArray(Util.PB_toLength(User.QQ)));
            BodyWriter.BeWrite((ushort)0x1800);
            BodyWriter.Write((byte)0x22);
            BodyWriter.Write((byte)0x10);
            BodyWriter.Write(md5);
            BodyWriter.Write((byte)0x28);
            BodyWriter.Write(Util.HexStringToByteArray(Util.PB_toLength(picBytes.Length))); //TODO:
            BodyWriter.Write((byte)0x32);
            BodyWriter.Write((byte)0x1A);
            BodyWriter.Write(new byte[]
            {
                0x37, 0x00, 0x4D, 0x00, 0x32, 0x00, 0x25, 0x00, 0x4C,
                0x00, 0x31, 0x00, 0x56, 0x00, 0x32, 0x00, 0x7B, 0x00,
                0x39, 0x00, 0x30, 0x00, 0x29, 0x00, 0x52, 0x00
            });
            BodyWriter.BeWrite((ushort)0x3801);
            BodyWriter.BeWrite((ushort)0x4801);
            BodyWriter.Write((byte)0x50);
            BodyWriter.Write(Util.HexStringToByteArray(Util.PB_toLength(width)));  //TODO:
            BodyWriter.Write((byte)0x58);
            BodyWriter.Write(Util.HexStringToByteArray(Util.PB_toLength(height))); //TODO:
            BodyWriter.BeWrite((ushort)0x6004);
            BodyWriter.BeWrite((ushort)0x6A05);
            BodyWriter.Write(new byte[]
            {
                0x32, 0x36, 0x36, 0x35, 0x36
            });
            BodyWriter.BeWrite((ushort)0x7000);
            BodyWriter.BeWrite((ushort)0x7803);
            BodyWriter.BeWrite((ushort)0x8001);
            BodyWriter.Write((byte)0x00);
        }
Пример #16
0
        /// <summary>
        ///     初始化包体
        /// </summary>
        protected override void PutBody()
        {
            Bitmap pic    = new Bitmap(fileName);
            int    Width  = pic.Size.Width;  // 图片的宽度
            int    Height = pic.Size.Height; // 图片的高度
            //var Md5 = Util.GetMD5ToGuidHashFromFile(fileName);
            var picBytes = ImageHelper.ImageToBytes(pic);
            var Md5      = QQTea.MD5(picBytes);

            bodyWriter.Write(new byte[] {
                0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x5E, 0x08,
                0x01, 0x12, 0x03, 0x98, 0x01, 0x01, 0x10, 0x01, 0x1A
            });
            bodyWriter.BEWrite((char)0x5A);
            bodyWriter.Write((byte)0x08);
            bodyWriter.BEWrite(user.QQ);
            bodyWriter.Write((byte)0x10);
            bodyWriter.BEWrite(user.QQ);
            bodyWriter.BEWrite((char)0x1800);
            bodyWriter.Write((byte)0x22);
            bodyWriter.BEWrite((char)0x10);
            bodyWriter.Write(Md5);
            bodyWriter.Write((byte)0x28);
            bodyWriter.BEWrite(picBytes.Length);
            bodyWriter.Write((byte)0x32);
            bodyWriter.BEWrite((char)0x1A);
            bodyWriter.Write(new byte[] {
                0x37, 0x00, 0x4D, 0x00, 0x32, 0x00, 0x25, 0x00, 0x4C,
                0x00, 0x31, 0x00, 0x56, 0x00, 0x32, 0x00, 0x7B, 0x00,
                0x39, 0x00, 0x30, 0x00, 0x29, 0x00, 0x52, 0x00
            });
            bodyWriter.BEWrite((char)0x3801);
            bodyWriter.BEWrite((char)0x4801);
            bodyWriter.Write((byte)0x50);
            bodyWriter.BEWrite(Width);
            bodyWriter.Write((byte)0x58);
            bodyWriter.BEWrite(Height);
            bodyWriter.BEWrite((char)0x6004);
            bodyWriter.BEWrite((char)0x6A05);
            bodyWriter.Write(new byte[] {
                0x32, 0x36, 0x36, 0x35, 0x36
            });
            bodyWriter.BEWrite((char)0x7000);
            bodyWriter.BEWrite((char)0x7803);
            bodyWriter.BEWrite((char)0x8001);
            bodyWriter.Write((byte)0x00);
        }
Пример #17
0
        protected override void ParseBody(ByteBuffer byteBuffer)
        {
            //密文
            byte[] CipherText = byteBuffer.ToByteArray();
            //明文
            if (!user.IsLoginRedirect)
            {
                bodyDecrypted = QQTea.Decrypt(CipherText, byteBuffer.Position, CipherText.Length - byteBuffer.Position - 1, user.QQ_PACKET_0825KEY);
            }
            else
            {
                bodyDecrypted = QQTea.Decrypt(CipherText, byteBuffer.Position, CipherText.Length - byteBuffer.Position - 1, user.QQ_PACKET_REDIRECTIONKEY);
            }
            if (bodyDecrypted == null)
            {
                throw new Exception($"包内容解析出错,抛弃该包: {ToString()}");
            }
            ByteBuffer buf = new ByteBuffer(bodyDecrypted);

            DataHead = buf.Get();
            buf.GetChar(); //0112
            buf.GetChar(); //0038
            user.QQ_0825Token = buf.GetByteArray(0x38);
            if (DataHead == 0xFE)
            {
                buf.GetByteArray(6);
                user.LoginTime = buf.GetByteArray(4);
                buf.GetByteArray(2);
                buf.GetByteArray(4);
                buf.GetByteArray(18);
                user.ServerIp = buf.GetByteArray(4);
                buf.GetByteArray(6);
            }
            else
            {
                buf.GetByteArray(6);
                user.LoginTime = buf.GetByteArray(4);
                buf.GetByteArray(2);
                buf.GetByteArray(4);
                buf.GetByteArray(6);
                user.ServerIp = buf.GetByteArray(4);
            }
            //从原始数据包提取加密包
            byteBuffer.GetByteArray(CipherText.Length - 1);
        }
Пример #18
0
        /// <summary>
        ///     初始化包体
        /// </summary>
        protected override void PutBody()
        {
            var pic      = new Bitmap(FileName.Content);
            var width    = pic.Size.Width;  // 图片的宽度
            var height   = pic.Size.Height; // 图片的高度
            var picBytes = ImageHelper.ImageToBytes(pic);

            _md5 = QQTea.MD5(picBytes);

            FileName.Set("Md5", Md5);

            BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x07 });
            var data = new BinaryWriter(new MemoryStream());

            data.Write(new byte[] { 0x10, 0x01, 0x1A, 0x5A, 0x08 });
            data.Write(Util.HexStringToByteArray(Util.PB_toLength(Group)));
            data.Write((byte)0x10);
            data.Write(Util.HexStringToByteArray(Util.PB_toLength(User.QQ)));
            data.Write(new byte[] { 0x18, 0x00, 0x22, 0x10 });
            data.Write(_md5);
            data.Write((byte)0x28);
            data.Write(Util.HexStringToByteArray(Util.PB_toLength(picBytes.Length)));
            data.Write(new byte[] { 0x32, 0x1a });
            data.Write(new byte[] { 0x50, 0x00, 0x42, 0x00, 0x41, 0x00, 0x42, 0x00, 0x52, 0x00, 0x24, 0x00, 0x4d, 0x00, 0x36, 0x00, 0x5f, 0x00, 0x5a, 0x00, 0x32, 0x00, 0x25, 0x00, 0x39, 0x00 });
            data.Write(new byte[] { 0x38, 0x01, 0x48, 0x01 });
            data.Write((byte)0x50);
            data.Write(Util.HexStringToByteArray(Util.PB_toLength(width)));
            data.Write((byte)0x58);
            data.Write(Util.HexStringToByteArray(Util.PB_toLength(height)));
            data.Write(new byte[] { 0x60, 0x04, 0x6a, 0x05 });
            data.Write(new byte[] { 0x32, 0x36, 0x36, 0x35, 0x32 });
            data.Write(new byte[] { 0x70, 0x00, 0x78, 0x03, 0x80, 0x01, 0x00 });

            //数据长度
            BodyWriter.BeWrite(data.BaseStream.Length);
            BodyWriter.Write(new byte[] { 0x08, 0x01, 0x12, 0x03, 0x98, 0x01, 0x01 });
            //数据
            BodyWriter.Write(data.BaseStream.ToBytesArray());

            //使用之后释放文件
            pic.Dispose();
        }
Пример #19
0
        public byte[] GET_TLV_0006(byte[] m_loginTime, byte[] m_loginIP)
        {
            ByteBuffer buf = new ByteBuffer();

            buf.Put(Util.RandomKey(4));
            buf.Put(new byte[] { 0x00, 0x02 });
            buf.PutLong(user.QQ);
            buf.Put(user.QQ_PACKET_0825DATA2);
            buf.Put(new byte[] { 0x00, 0x00, 0x01 });
            buf.Put(user.MD51);
            buf.Put(m_loginTime);
            buf.Put(new byte[] { 0x00 });//下面有时间时为01
            buf.Put(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
            buf.Put(m_loginIP);
            buf.Put(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
            buf.Put(new byte[] { 0x00, 0x10 });
            buf.Put(new byte[] { 0x15, 0x74, 0xC4, 0x89, 0x85, 0x7A, 0x19, 0xF5, 0x5E, 0xA9, 0xC9, 0xA3, 0x5E, 0x8A, 0x5A, 0x9B });
            buf.Put(user.QQ_PACKET_TgtgtKey);
            return(QQTea.Encrypt(buf.ToByteArray(), user.Md52()));
        }
Пример #20
0
        public byte[] get_tlv_0006(QQClient m_PCClient)
        {
            if (wSubVer == 0x0002)
            {
                if (m_PCClient.QQUser.TXProtocol.bufTGTGT == null)
                {
                    var data = new BinaryWriter(new MemoryStream());
                    data.BEWrite(new Random(Guid.NewGuid().GetHashCode()).Next()); //随机4字节??
                    data.BEWrite(wSubVer);                                         //wSubVer
                    data.BEWrite((uint)m_PCClient.QQUser.QQ);                      //QQ号码
                    data.BEWrite(QQGlobal.dwSSOVersion);
                    data.BEWrite(QQGlobal.dwServiceId);
                    data.BEWrite(QQGlobal.dwClientVer);
                    data.BEWrite(0);
                    data.Write(m_PCClient.QQUser.bRememberPwdLogin);
                    data.Write(m_PCClient.QQUser.MD51);                       //密码的一次MD5值,服务器用该MD5值验证用户密码是否正确
                    data.Write(m_PCClient.QQUser.LoginTime);                  //登录时间
                    data.Write(new byte[13]);                                 //固定13字节
                    data.Write(m_PCClient.QQUser.IP);                         //IP地址
                    data.BEWrite(QQGlobal.dwISP);                             //dwISP
                    data.BEWrite(QQGlobal.dwIDC);                             //dwIDC
                    data.Write(m_PCClient.QQUser.TXProtocol.bufComputerIDEx); //机器码
                    data.Write(m_PCClient.QQUser.QQ_PACKET_TgtgtKey);         //00DD临时密钥(通过验证时客户端用该密钥解密服务端发送回来的数据)

                    m_PCClient.QQUser.TXProtocol.bufTGTGT =
                        QQTea.Encrypt(data.BaseStream.ToBytesArray(), m_PCClient.QQUser.Md52());
                }
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {wSubVer}");
            }

            var tlv = new BinaryWriter(new MemoryStream());

            tlv.Write(m_PCClient.QQUser.TXProtocol.bufTGTGT);
            fill_head(cmd);
            fill_body(tlv.BaseStream.ToBytesArray(), tlv.BaseStream.Length);
            set_length();
            return(get_buf());
        }
Пример #21
0
        public byte[] Get_Tlv(QQUser user)
        {
            if (WSubVer == 0x0002)
            {
                if (user.TXProtocol.BufTgtgt == null)
                {
                    var data = new BinaryWriter(new MemoryStream());
                    data.BeWrite(new Random(Guid.NewGuid().GetHashCode()).Next()); //随机4字节??
                    data.BeWrite(WSubVer);                                         //wSubVer
                    data.BeWrite(user.QQ);                                         //QQ号码
                    data.BeWrite(user.TXProtocol.DwSsoVersion);
                    data.BeWrite(user.TXProtocol.DwServiceId);
                    data.BeWrite(user.TXProtocol.DwClientVer);
                    data.BeWrite((ushort)0);
                    data.Write(user.TXProtocol.BRememberPwdLogin);
                    data.Write(user.MD51);                                            //密码的一次MD5值,服务器用该MD5值验证用户密码是否正确
                    data.BeWrite(user.TXProtocol.DwServerTime);                       //登录时间
                    data.Write(new byte[13]);                                         //固定13字节
                    data.Write(Util.IPStringToByteArray(user.TXProtocol.DwClientIP)); //IP地址
                    data.BeWrite(user.TXProtocol.DwIsp);                              //dwISP
                    data.BeWrite(user.TXProtocol.DwIdc);                              //dwIDC
                    data.WriteKey(user.TXProtocol.BufComputerIdEx);                   //机器码
                    data.Write(user.TXProtocol.BufTgtgtKey);                          //00DD临时密钥(通过验证时客户端用该密钥解密服务端发送回来的数据)

                    user.TXProtocol.BufTgtgt =
                        QQTea.Encrypt(data.BaseStream.ToBytesArray(), user.Md52());
                }
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }

            var tlv = new BinaryWriter(new MemoryStream());

            tlv.Write(user.TXProtocol.BufTgtgt);
            FillHead(Command);
            FillBody(tlv.BaseStream.ToBytesArray(), tlv.BaseStream.Length);
            SetLength();
            return(GetBuffer());
        }
Пример #22
0
        public byte[] GET_TLV_0006(byte[] m_loginTime, byte[] m_loginIP)
        {
            var bw = new BinaryWriter(new MemoryStream());

            bw.Write(Util.RandomKey(4));
            bw.Write(new byte[] { 0x00, 0x02 });
            bw.BEWrite(user.QQ);
            bw.Write(user.QQ_PACKET_0825DATA2);
            bw.Write(new byte[] { 0x00, 0x00, 0x01 });
            bw.Write(user.MD51);
            bw.Write(m_loginTime);
            bw.Write(new byte[] { 0x00 }); //下面有时间时为01
            bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
            bw.Write(m_loginIP);
            bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
            bw.Write(new byte[] { 0x00, 0x10 });
            bw.Write(new byte[]
                     { 0x15, 0x74, 0xC4, 0x89, 0x85, 0x7A, 0x19, 0xF5, 0x5E, 0xA9, 0xC9, 0xA3, 0x5E, 0x8A, 0x5A, 0x9B });
            bw.Write(user.QQ_PACKET_TgtgtKey);
            return(QQTea.Encrypt(bw.BaseStream.ToBytesArray(), user.Md52()));
        }
Пример #23
0
        protected override void ParseBody(ByteBuffer byteBuffer)
        {
            //密文
            byte[] CipherText = byteBuffer.ToByteArray();
            //明文
            bodyDecrypted = QQTea.Decrypt(CipherText, byteBuffer.Position, CipherText.Length - byteBuffer.Position - 1, user.QQ_SessionKey);
            //提取数据
            ByteBuffer buf = new ByteBuffer(bodyDecrypted);

            buf.GetByteArray(4);
            user.QQ_Skey = Util.ConvertHexToString(Util.ToHex(buf.GetByteArray(10)));
            if (string.IsNullOrEmpty(user.QQ_Skey))
            {
                throw new Exception("skey获取失败");
            }
            else
            {
                user.QQ_Cookies = "uin=o" + user.QQ + ";skey=" + user.QQ_Skey + ";";
                user.QQ_Gtk     = Util.GET_GTK(user.QQ_Skey);
            }
        }
Пример #24
0
        /// <summary>
        /// 初始化包体
        /// </summary>
        /// <param name="buf">The buf.</param>
        protected override void PutBody(ByteBuffer buf)
        {
            user.QQ_tlv_001A_encr = QQTea.Encrypt(user.QQ_PACKET_FIX2, user.QQ_PACKET_TgtgtKey);
            if (_type == Login0x0836Type.Login0x0836_622)
            {
                user.QQ_tlv_0006_encr = GET_TLV_0006(user.LoginTime, user.ServerIp);
            }
            buf.Put(new byte[] { 0x01, 0x12 });
            buf.Put(new byte[] { 0x00, 0x38 });
            buf.Put(user.QQ_0825Token);
            buf.Put(new byte[] { 0x03, 0x0F });
            buf.Put(new byte[] { 0x00 });
            buf.Put((byte)(Util.HexStringToByteArray(Util.ConvertStringToHex(user.PcName)).Length + 2));
            buf.Put(new byte[] { 0x00 });
            buf.Put((byte)Util.HexStringToByteArray(Util.ConvertStringToHex(user.PcName)).Length);
            buf.Put(Util.HexStringToByteArray(Util.ConvertStringToHex(user.PcName)));
            buf.Put(new byte[] { 0x00, 0x05, 0x00, 0x06, 0x00, 0x02 });
            buf.PutLong(user.QQ);
            buf.Put(new byte[] { 0x00, 0x06 });
            buf.Put(new byte[] { 0x00, 0x78 });
            buf.Put(user.QQ_tlv_0006_encr);
            buf.Put(user.QQ_PACKET_FIX2);
            buf.Put(new byte[] { 0x00, 0x1A });
            buf.Put(new byte[] { 0x00, 0x40 });
            buf.Put(user.QQ_tlv_001A_encr);
            buf.Put(user.QQ_PACKET_0825DATA0);
            buf.Put(user.QQ_PACKET_0825DATA2);
            buf.PutLong(user.QQ);
            buf.Put(new byte[] { 0x00, 0x00, 0x00, 0x00 });
            buf.Put(new byte[] { 0x01, 0x03 });
            buf.Put(new byte[] { 0x00, 0x14 });
            buf.Put(new byte[] { 0x00, 0x01 });
            buf.Put(new byte[] { 0x00, 0x10 });
            buf.Put(new byte[] { 0x60, 0xC9, 0x5D, 0xA7, 0x45, 0x70, 0x04, 0x7F, 0x21, 0x7D, 0x84, 0x50, 0x5C, 0x66, 0xA5, 0xC6 });

            if (_type == Login0x0836Type.Login0x0836_686)
            {
                buf.Put(new byte[] { 0x01, 0x10 });
                buf.Put(new byte[] { 0x00, 0x3C });
                buf.Put(new byte[] { 0x00, 0x01 });
                buf.Put(new byte[] { 0x00, 0x38 });
                buf.Put(user.QQ_0836Token);
            }

            buf.Put(new byte[] { 0x03, 0x12 });
            buf.Put(new byte[] { 0x00, 0x05 });
            buf.Put(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x01 });
            buf.Put(new byte[] { 0x05, 0x08 });
            buf.Put(new byte[] { 0x00, 0x05 });
            buf.Put(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00 });
            buf.Put(new byte[] { 0x03, 0x13 });
            buf.Put(new byte[] { 0x00, 0x19 });
            buf.Put(new byte[] { 0x01 });
            buf.Put(new byte[] { 0x01, 0x02 });
            buf.Put(new byte[] { 0x00, 0x10 });
            buf.Put(new byte[] { 0x04, 0xEA, 0x78, 0xD1, 0xA4, 0xFF, 0xCD, 0xCC, 0x7C, 0xB8, 0xD4, 0x12, 0x7D, 0xBB, 0x03, 0xAA }); //两次0836包相同
            buf.Put(new byte[] { 0x00, 0x00, 0x00 });
            buf.Put(new byte[] { 0x00 });                                                                                           //可能为00,0F,1F
            buf.Put(new byte[] { 0x01, 0x02 });
            buf.Put(new byte[] { 0x00, 0x62 });
            buf.Put(new byte[] { 0x00, 0x01 });
            buf.Put(new byte[] { 0x04, 0xEB, 0xB7, 0xC1, 0x86, 0xF9, 0x08, 0x96, 0xED, 0x56, 0x84, 0xAB, 0x50, 0x85, 0x2E, 0x48 });//两次0836包不同
            buf.Put(new byte[] { 0x00, 0x38 });
            buf.Put(new byte[] { 0xE9, 0xAA, 0x2B, 0x4D, 0x26, 0x4C, 0x76, 0x18, 0xFE, 0x59, 0xD5, 0xA9, 0x82, 0x6A, 0x0C, 0x04, 0xB4, 0x49, 0x50, 0xD7, 0x9B, 0xB1, 0xFE, 0x5D, 0x97, 0x54, 0x8D, 0x82, 0xF3, 0x22, 0xC2, 0x48, 0xB9, 0xC9, 0x22, 0x69, 0xCA, 0x78, 0xAD, 0x3E, 0x2D, 0xE9, 0xC9, 0xDF, 0xA8, 0x9E, 0x7D, 0x8C, 0x8D, 0x6B, 0xDF, 0x4C, 0xD7, 0x34, 0xD0, 0xD3 });
            buf.Put(new byte[] { 0x00, 0x14 });
            buf.Put(user.QQ_PACKET_Crc32_Code);
            buf.PutULong(CRC32cs.GetCRC32Str(Util.ToHex(user.QQ_PACKET_Crc32_Code)));
        }
Пример #25
0
        protected override void ParseBody()
        {
            var CipherText2 = QQTea.Decrypt(buffer, (int)reader.BaseStream.Position,
                                            (int)(buffer.Length - reader.BaseStream.Position - 1), user.QQ_SHARE_KEY);

            if (CipherText2 == null)
            {
                throw new Exception($"包内容解析出错,抛弃该包: {ToString()}");
            }

            if (GetPacketLength() == 871)
            {
                bodyDecrypted = CipherText2;
                reader        = new BinaryReader(new MemoryStream(bodyDecrypted));
                reader.ReadBytes(20);
                user.QQ_PACKET_00BAVerifyToken = reader.ReadBytes(reader.BEReadChar());
                VerifyCode    = reader.ReadBytes(reader.BEReadChar());
                VerifyCommand = reader.ReadByte();
                if (VerifyCommand == 0x00)
                {
                    VerifyCommand = reader.ReadByte();
                }

                user.QQ_PACKET_00BAVerifyCode = VerifyCode;
                user.QQ_PACKET_00BAToken      = reader.ReadBytes(reader.BEReadChar());
                reader.ReadBytes(reader.BEReadChar());
            }
            else
            {
                bodyDecrypted = QQTea.Decrypt(CipherText2, _secretKey);
                if (bodyDecrypted == null)
                {
                    throw new Exception($"包内容解析出错,抛弃该包: {ToString()}");
                }

                //提取数据
                reader   = new BinaryReader(new MemoryStream(bodyDecrypted));
                DataHead = reader.ReadByte();
                if (GetPacketLength() == 271 || GetPacketLength() == 207)
                {
                    reader.BEReadChar();
                    user.QQ_PACKET_TgtgtKey = reader.ReadBytes(reader.BEReadChar());
                    reader.BEReadChar();
                    user.QQ_tlv_0006_encr = reader.ReadBytes(reader.BEReadChar());
                    reader.ReadBytes(6);
                    if (GetPacketLength() == 271)
                    {
                        user.QQ_0836Token = reader.ReadBytes(reader.BEReadChar());
                    }

                    reader.BEReadChar();
                    reader.ReadBytes(reader.BEReadChar());
                }
                else if (GetPacketLength() > 700)
                {
                    reader.ReadBytes(6);
                    user.QQ_0828_rec_ecr_key = reader.ReadBytes(0x10);
                    reader.BEReadChar();
                    user.QQ_0836_038Token = reader.ReadBytes(0x38);
                    reader.ReadBytes(60);
                    var Judge     = reader.ReadBytes(2);
                    var MsgLength = 0;
                    if (Util.ToHex(Judge) == "01 07")
                    {
                        MsgLength = 0;
                    }
                    else if (Util.ToHex(Judge) == "00 33")
                    {
                        MsgLength = 28;
                    }
                    else if (Util.ToHex(Judge) == "01 10")
                    {
                        MsgLength = 64;
                    }

                    reader.ReadBytes(28);
                    reader.ReadBytes(MsgLength);
                    user.QQ_0828_rec_decr_key = reader.ReadBytes(0x10);
                    reader.BEReadChar();
                    user.QQ_0836_088Token = reader.ReadBytes(0x88);
                    reader.ReadBytes(159);
                    user.QQ_ClientKey = reader.ReadBytes(112);
                    reader.ReadBytes(28);
                    var nick_length = reader.ReadByte();
                    user.NickName = Encoding.UTF8.GetString(reader.ReadBytes(nick_length));
                    user.Gender   = reader.ReadByte();
                    reader.ReadBytes(4);
                    user.Age = reader.ReadByte();
                    reader.ReadBytes(10);
                    reader.ReadBytes(0x10);
                }
            }
        }
Пример #26
0
 public void SetPassword(String pwd)
 {
     this.MD51 = QQTea.MD5(ByteHelper.GetBytes(pwd));
 }
Пример #27
0
        protected override void ParseBody(ByteBuffer byteBuffer)
        {
            //密文
            byte[] CipherText = byteBuffer.ToByteArray();
            //明文
            byte[] CipherText2 = QQTea.Decrypt(CipherText, byteBuffer.Position, CipherText.Length - byteBuffer.Position - 1, user.QQ_SHARE_KEY);
            if (CipherText2 == null)
            {
                throw new Exception($"包内容解析出错,抛弃该包: {ToString()}");
            }
            bodyDecrypted = QQTea.Decrypt(CipherText2, _secretKey);
            if (bodyDecrypted == null)
            {
                throw new Exception($"包内容解析出错,抛弃该包: {ToString()}");
            }
            //提取数据
            ByteBuffer buf = new ByteBuffer(bodyDecrypted);

            DataHead = buf.Get();
            if (GetPacketLength() == 271 || GetPacketLength() == 207)
            {
                buf.GetChar();
                buf.GetChar();
                user.QQ_PACKET_TgtgtKey = buf.GetByteArray(0x10);
                buf.GetChar();
                buf.GetChar();
                user.QQ_tlv_0006_encr = buf.GetByteArray(0x78);
                buf.GetByteArray(6);
                buf.GetChar();
                user.QQ_0836Token = buf.GetByteArray(0x38);
                buf.GetChar();
                buf.GetChar();
                buf.GetByteArray(0x10);
            }
            else if (GetPacketLength() > 700)
            {
                buf.GetByteArray(6);
                user.QQ_0828_rec_ecr_key = buf.GetByteArray(0x10);
                buf.GetChar();
                user.QQ_0836_038Token = buf.GetByteArray(0x38);
                buf.GetByteArray(60);
                var Judge     = buf.GetByteArray(2);
                var MsgLength = 0;
                if (Util.ToHex(Judge) == "01 07")
                {
                    MsgLength = 0;
                }
                else if (Util.ToHex(Judge) == "00 33")
                {
                    MsgLength = 28;
                }
                else if (Util.ToHex(Judge) == "01 10")
                {
                    MsgLength = 64;
                }
                buf.GetByteArray(28);
                buf.GetByteArray(MsgLength);
                user.QQ_0828_rec_decr_key = buf.GetByteArray(0x10);
                buf.GetChar();
                user.QQ_0836_088Token = buf.GetByteArray(0x88);
                buf.GetByteArray(159);
                user.QQ_ClientKey = buf.GetByteArray(112);
                buf.GetByteArray(28);
                var nick_length = buf.Get();
                user.NickName = Util.ConvertHexToString(Util.ToHex(buf.GetByteArray(nick_length)));
                user.Gender   = buf.Get();
                buf.GetByteArray(4);
                user.Age = buf.Get();
                buf.GetByteArray(10);
                buf.GetByteArray(0x10);
            }
        }
Пример #28
0
 /// <summary>
 ///     设置用户的密码,不会保存明文形式的密码,立刻用Double MD5算法加密
 /// </summary>
 /// <param name="pwd">明文形式的密码</param>
 public void SetPassword(string pwd)
 {
     MD51 = QQTea.MD5(Util.GetBytes(pwd));
 }
Пример #29
0
 /// <summary>
 ///     加密包体
 /// </summary>
 /// <param name="buf">未加密的字节数组.</param>
 /// <param name="offset">包体开始的偏移.</param>
 /// <param name="length">包体长度.</param>
 /// <returns>加密的包体</returns>
 public byte[] EncryptBody(byte[] buf, int offset, int length)
 {
     return(QQTea.Encrypt(buf, offset, length, SecretKey));
 }
Пример #30
0
 public Byte[] EncryptBody(Byte[] buf, Int32 offset, Int32 length, Byte[] key)
 {
     return(QQTea.Encrypt(buf, offset, length, key));
 }