protected override void PutBody(ByteBuffer buf) { buf.Put(0x01); buf.PutInt(0); buf.PutInt(0); buf.Put(0x02); buf.PutUShort(StartPosition); buf.Put(0); #if DEBUG Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray())); #endif }
/// <summary> /// 初始化请求发送文件包的其余部分 /// </summary> /// <param name="buf">The buf.</param> private void InitSendFileContent(ByteBuffer buf) { // 17 - 19. 怀疑也和发送消息包相同,但是在这种情况中,这部分没有使用,为全0,一共11个0字节 buf.PutLong(0); buf.PutChar((char)0); buf.Put((byte)0); // 我们先尝试UDP方式 buf.Put((byte)TransferType); buf.Put((byte)0x0); if (FakeIp) { buf.PutInt(0); buf.PutChar((char)0); } else { // 四个字节的发送者IP,这是外部IP buf.Put(user.IP); // 发送者端口 buf.PutChar((char)user.Port); } // 直接端口 buf.PutUShort(DirectPort); buf.PutInt(0); buf.PutChar((char)0); buf.Put((byte)0x20); buf.Put(DELIMIT); buf.Put(Utils.Util.GetBytes(FileName)); buf.Put(DELIMIT); buf.Put(Utils.Util.GetBytes(FileSize)); }
/// <summary>初始化同意接收文件包的其余部分 /// <remark>abu 2008-02-29 </remark> /// </summary> /// <param name="buf">The buf.</param> private void InitSendFileAcceptContent(ByteBuffer buf) { // 17 - 19. 怀疑也和发送消息包相同,但是在这种情况中,这部分没有使用,为全0,一共11个0字节 buf.PutLong(0); buf.PutChar((char)0); buf.Put((byte)0); // 我们先尝试UDP方式 buf.Put((byte)TransferType); buf.Put((byte)0x0); // 四个字节的发送者IP,这是外部IP buf.Put(user.IP); // 发送者端口 buf.PutChar((char)user.Port); // 监听端口,含义未知,为连接服务器的端口,先随便写一个值 buf.PutUShort(DirectPort); // 后面全0 buf.PutInt(0); buf.PutChar((char)0); }
/// <summary> /// 初始化IP信息通知包 /// </summary> /// <param name="buf">The buf.</param> private void InitNotifyFilePortUDP(ByteBuffer buf) { // 17 - 19. 怀疑也和发送消息包相同,但是在这种情况中,这部分没有使用,为全0,一共11个0字节 buf.PutLong(0); buf.PutChar((char)0); buf.Put((byte)0); // 我们先尝试UDP方式 buf.Put((byte)TransferType); buf.Put((byte)0x0); // 四个字节的发送者IP,这是外部IP buf.Put(user.IP); // 发送者端口 buf.PutChar((char)user.Port); // 监听端口,含义未知,为连接服务器的端口,先随便写一个值 buf.PutUShort(DirectPort); // 真实IP和第二个端口 buf.Put(LocalIp); buf.PutUShort(LocalPort); }
protected override void PutBody(ByteBuffer buf) { if (MessageId == 0) { MessageId = (ushort)this.Sequence; } // 发送者QQ号 buf.PutInt(user.QQ); // 接收者QQ号 //00 00 00 08 00 01 00 04 00 00 00 00 09SP1 changes buf.PutInt(Receiver); buf.PutInt(0x00000008); buf.PutInt(0x00010004); buf.PutInt(0x00000000); // 发送者QQ版本 buf.PutChar(Source); // 发送者QQ号 buf.PutInt(user.QQ); // 接收者QQ号 buf.PutInt(Receiver); // 文件传输会话密钥 buf.Put(user.QQKey.SessionKey); // 消息类型 buf.PutUShort((ushort)MessageType); // 顺序号 if (SessionId == 0) buf.PutChar(Sequence); else buf.PutUShort(SessionId); // 发送时间 int time = (int)(Utils.Util.GetTimeMillis(DateTime.Now) / 1000); buf.PutInt(time); // 发送者头像 char face = (char)user.ContactInfo.Head; buf.PutChar(face); // 字体信息,设成1 buf.PutInt(1); if (MessageType != NormalIMType.Vibration) { // 暂时为如来神掌做的设置 if (FakeIp) buf.PutInt(0); else { // 分片数 buf.Put((byte)TotalFragments); // 分片序号 buf.Put((byte)FragmentSequence); // 消息id buf.PutUShort(MessageId); } } // 判断消息类型 switch (MessageType) { case NormalIMType.TEXT: InitTextContent(buf); break; case NormalIMType.UDP_REQUEST: InitSendFileContent(buf); break; case NormalIMType.ACCEPT_UDP_REQUEST: InitSendFileAcceptContent(buf); break; case NormalIMType.REJECT_UDP_REQUEST: case NormalIMType.REJECT_TCP_REQUEST: InitSendFileRejectContent(buf); break; case NormalIMType.NOTIFY_IP: InitNotifyFilePortUDP(buf); break; case NormalIMType.REQUEST_CANCELED: InitConnectionCanceled(buf); break; case NormalIMType.ARE_YOU_BEHIND_FIREWALL: InitPleaseConnectMe(buf); break; case NormalIMType.Vibration: InitVibrationContent(buf); break; } #if DEBUG Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray())); #endif }
protected override void PutBody(ByteBuffer buf) { if (Code != 0) { buf.Put(0x02);//sub cmd buf.PutUShort(Type); buf.PutInt(QQ); buf.PutUShort(4); buf.PutInt(Code); buf.PutUShort((ushort)VCodeSession.Length); buf.Put(VCodeSession); } else { buf.Put(0x01);//sub cmd buf.PutUShort(Type); buf.PutInt(QQ); } #if DEBUG Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray())); #endif }
protected override void PutBody(ByteBuffer buf) { switch (SubCommand) { case AddFriendAuthSubCmd.Approve: case AddFriendAuthSubCmd.ApproveAndAdd: case AddFriendAuthSubCmd.Reject: case AddFriendAuthSubCmd.NoAuth: //03 (01表示不需要验证时的加对方为好友,03表示接受并加对方为好友,04表示只接受,05表示拒绝) //25 D0 1F E1 //00 00 00 buf.Put((byte)SubCommand); buf.PutInt(To); buf.PutUShort(0);//00 00 byte[] b = Utils.Util.GetBytes(Message); buf.Put((byte)b.Length);//长度 buf.Put(b); break; case AddFriendAuthSubCmd.Add: case AddFriendAuthSubCmd.AnswerAdd: case AddFriendAuthSubCmd.NeedAuthor: buf.Put((byte)SubCommand); buf.PutInt(To); buf.Put((byte)ReverseAdd);//00 buf.Put((byte)DestGroup);//00 buf.PutUShort((ushort)AddFriendToken.Length); buf.Put(AddFriendToken); if (AnswerToken != null) { buf.PutUShort((ushort)AnswerToken.Length); buf.Put(AnswerToken); } buf.Put(0x01); buf.Put(0x00); if (!string.IsNullOrEmpty(Message)) { b = Utils.Util.GetBytes(Message); buf.Put((byte)b.Length); buf.Put(b); } break; default: throw new Exception("unknown AddFriendAuthSubCmd=0x" + SubCommand.ToString("X")); } #if DEBUG Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray())); #endif }
protected override void PostFill(ByteBuffer buf, int startPos) { // 如果是tcp包,到包的开头处填上包长度,然后回到目前的pos if (!user.IsUdp) { int len = buf.Length - startPos; buf.PutUShort(startPos, (ushort)len); } }
/// <summary> /// Puts the body. /// </summary> /// <param name="buf">The buf.</param> protected override void PutBody(ByteBuffer buf) { // 命令类型 buf.Put((byte)SubCommand); // 群内部ID buf.PutInt(ClusterId); // 后面数据的长度,这个长度需要根据后面的长度计算才能知道, // 所以先占个位置 //int pos = buf.Position; //buf.PutChar((char)0); ByteBuffer MsgBuf = new ByteBuffer(); // 未知的2字节 MsgBuf.PutChar((char)1); // 分片数 MsgBuf.Put((byte)TotalFragments); // 分片序号 MsgBuf.Put((byte)FragmentSequence); if (MessageId == 0) { MessageId = (ushort)this.Sequence; } // 消息id MsgBuf.PutUShort(MessageId); // 未知4字节 MsgBuf.PutInt(0); // 以0结束的消息,首先我们要根据用户设置的message,解析出一个网络可发送的格式 // 这一步比较麻烦,暂时想不到好的办法 MsgBuf.PutInt(0x4D534700);//"MSG" MsgBuf.PutInt(0); // 发送时间 int time = (int)(Utils.Util.GetTimeMillis(DateTime.Now) / 1000); MsgBuf.PutInt(time); MsgBuf.PutInt((MessageId << 16) | MessageId);//maybe a random interger MsgBuf.PutInt(0); MsgBuf.PutInt(0x09008600); byte[] Font_Name = Utils.Util.GetBytes(FontStyle.FontName); MsgBuf.PutUShort((ushort)Font_Name.Length); MsgBuf.Put(Font_Name); MsgBuf.PutUShort(0); MsgBuf.Put(0x01); MsgBuf.PutUShort((ushort)(MessageBytes.Length + 3)); MsgBuf.Put(1); MsgBuf.PutUShort((ushort)(MessageBytes.Length)); // 写入消息正文字节数组 if (MessageBytes != null) MsgBuf.Put(MessageBytes); //if (FragmentSequence == TotalFragments - 1) //{ // MsgBuf.Put((byte)0x20); //} byte[] MsgData = MsgBuf.ToByteArray(); buf.PutUShort((ushort)MsgData.Length); buf.Put(MsgData); MsgData = null; MsgBuf = null; //byte[] msgBytes = null; //int j, i = 0; //while ((j = Message.IndexOf((char)FaceType.DEFAULT, i)) != -1) //{ // string sub = Message.Substring(i, j); // if (!sub.Equals("")) // { // msgBytes = Utils.Util.GetBytes(sub); // buf.Put(msgBytes); // } // buf.Put((byte)FaceType.DEFAULT); // buf.Put((byte)(Message[j + 1] & 0xFF)); // i = j + 2; //} //if (i < Message.Length) //{ // string sub = Message.Substring(i); // msgBytes = Utils.Util.GetBytes(sub); // buf.Put(msgBytes); //} //// 只有最后一个分片有空格和字体属性 //if (FragmentSequence == TotalFragments - 1) //{ // buf.Put((byte)0x20); // FontStyle.Write(buf); //} // 写入长度 //int cur = buf.Position; //buf.Position = pos; //buf.PutChar((char)(cur - pos - 2)); //buf.Position = cur; #if DEBUG Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray())); #endif }
/// <summary> /// </summary> /// <param name="buf">The buf.</param> public void Write(ByteBuffer buf) { buf.PutUShort(fontFlag); // 字体颜色红绿篮 buf.Put((byte)Red); buf.Put((byte)Green); buf.Put((byte)Blue); // 一个未知字节 buf.Put((byte)0); // 消息编码 buf.PutUShort((ushort)EncodingCode); // 字体 byte[] fontBytes = Utils.Util.GetBytes(FontName); buf.Put(fontBytes); // 字体属性长度(包括本字节) buf.Put((byte)(fontBytes.Length + 9)); }
protected override void PutBody(ByteBuffer buf) { // 命令类型 buf.Put((byte)SubCommand); // 群类型 buf.Put((byte)Type); // 父群ID buf.PutInt(ParentClusterId); // 群内部ID buf.PutInt(ClusterId); // 后面数据的长度,这个长度需要根据消息长度和字体名称长度计算才能知道, // 所以先来产生消息和字体名称字节数组,先占个位置 int pos = buf.Position; buf.PutChar((char)0); // 未知2字节 buf.PutChar((char)1); // 分片数 buf.Put((byte)TotalFragments); // 分片序号 buf.Put((byte)FragmentSequence); // 消息id buf.PutUShort(MessageId); // 未知4字节 buf.PutInt(0); // 以0结束的消息,首先我们要根据用户设置的message,解析出一个网络可发送的格式 // 这一步比较麻烦,暂时想不到好的办法 byte[] msgBytes = null; int j, i = 0; while ((j = Message.IndexOf((char)FaceType.DEFAULT, i)) != -1) { String sub = Message.Substring(i, j); if (!sub.Equals("")) { msgBytes = Utils.Util.GetBytes(sub); buf.Put(msgBytes); } buf.Put((byte)FaceType.DEFAULT); buf.Put((byte)(Message[j + 1] & 0xFF)); i = j + 2; } if (i < Message.Length) { String sub = Message.Substring(i); msgBytes = Utils.Util.GetBytes(sub); buf.Put(msgBytes); } // 只有最后一个分片有空格和字体属性 if (FragmentSequence == TotalFragments - 1) { buf.Put((byte)0x20); FontStyle.Write(buf); } // 写入长度 int cur = buf.Position; buf.Position = pos; buf.PutChar((char)(cur - pos - 2)); buf.Position = cur; }
protected override void PutBody(ByteBuffer buf) { buf.Put((byte)SubCommand); buf.PutUShort(StartPosition); }
protected override void PutBody(ByteBuffer buf) { // 设置状态 buf.Put((byte)Status); buf.PutInt(0);//00 00 00 00 buf.PutInt(ShowFakeCam ? 1 : 0);// 显示虚拟摄像头 buf.PutUShort(0); #if DEBUG Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray())); #endif }
/// <summary> /// 初始化普通消息包的其余部分 /// </summary> /// <param name="buf">The buf.</param> private void InitTextContent(ByteBuffer buf) { // 消息方式,是发送的,还是自动回复的,1字节 buf.Put((byte)ReplyType); //09 add buf.PutInt(0x4D534700);//"MSG" buf.PutInt(0); // 发送时间 int time = (int)(Utils.Util.GetTimeMillis(DateTime.Now) / 1000); buf.PutInt(time); buf.PutInt((MessageId << 16) | MessageId);//maybe a random interger buf.PutInt(0); buf.PutInt(0x09008600); byte[] Font_Name = Utils.Util.GetBytes(FontStyle.FontName); buf.PutUShort((ushort)Font_Name.Length); buf.Put(Font_Name); buf.PutUShort(0); buf.Put(0x01); buf.PutUShort((ushort)(Message.Length+3)); buf.Put(1); buf.PutUShort((ushort)(Message.Length)); // 写入消息正文字节数组 if (Message != null) buf.Put(Message); //// 最后一个分片时追加空格 //if (FragmentSequence == TotalFragments - 1) // buf.Put((byte)0x20); //// 消息尾部,字体修饰属性 //FontStyle.Write(buf); }
protected override void PutBody(ByteBuffer buf) { // 短消息序号 buf.PutUShort(MessageSequence); // 未知2字节 buf.PutChar((char)0); // 未知4字节 buf.PutInt(0); // 发送者昵称 byte[] b = Utils.Util.GetBytes(SenderName); if (b.Length > QQGlobal.QQ_MAX_SMS_SENDER_NAME) { buf.Put(b, 0, QQGlobal.QQ_MAX_SMS_SENDER_NAME); } else { buf.Put(b); int stuff = QQGlobal.QQ_MAX_SMS_SENDER_NAME - b.Length; while (stuff-- > 0) buf.Put((byte)0); } // 未知1字节 buf.Put((byte)0x01); // 发送模式 buf.Put((byte)SendMode); // 内容类型 buf.Put((byte)ContentType); // 内容编号 buf.PutInt(ContentId); // 未知1字节 buf.Put((byte)0x01); // 手机个数 if (ReceiverMobile == null) buf.Put((byte)0); else { buf.Put((byte)ReceiverMobile.Count); foreach (String mobile in ReceiverMobile) { b = Utils.Util.GetBytes(mobile); if (b.Length > QQGlobal.QQ_MAX_SMS_MOBILE_LENGTH) { buf.Put(b, 0, QQGlobal.QQ_MAX_SMS_MOBILE_LENGTH); } else { buf.Put(b); int stuff = QQGlobal.QQ_MAX_SMS_MOBILE_LENGTH - b.Length; while (stuff-- > 0) buf.Put((byte)0); } // 未知的2字节 buf.PutChar((char)0); // 未知的1字节 buf.Put((byte)0); } } // QQ号码个数 if (ReceiverQQ == null) buf.Put((byte)0); else { buf.Put((byte)ReceiverQQ.Count); foreach (int qq in ReceiverQQ) buf.PutInt(qq); } // 未知1字节 buf.Put((byte)0x03); // 消息 if (Message == null) buf.PutChar((char)0); else { buf.PutChar((char)Message.Length); // 消息 buf.Put(Message); } }
protected override void PutBody(ByteBuffer buf) { buf.PutChar((char)Client.QQUser.QQKey.LoginInfo_Magic_Token.Length); buf.Put(user.QQKey.LoginInfo_Magic_Token); ByteBuffer DecodedBuf = new ByteBuffer(); DecodedBuf.PutChar((char)0x011A); DecodedBuf.PutChar((char)0x0001); DecodedBuf.Put(VersionData.QQ09_LOCALE); DecodedBuf.Put(VersionData.QQ09_VERSION_SPEC); DecodedBuf.Put((byte)0x00); DecodedBuf.Put((byte)Client.QQUser.QQKey.Answer_Token.Length); DecodedBuf.Put(Client.QQUser.QQKey.Answer_Token); DecodedBuf.Put(Client.QQUser.QQKey.LoginInfo_UnknowData2); DecodedBuf.Put(Client.ServerTime); DecodedBuf.Put(Client.ClientIP); DecodedBuf.Position += 4;//00 00 00 00 DecodedBuf.PutChar((char)Client.QQUser.QQKey.LoginInfo_Large_Token.Length); DecodedBuf.Put(Client.QQUser.QQKey.LoginInfo_Large_Token); DecodedBuf.PutUShort(this.Pos); DecodedBuf.Position += 2;// 00 00 DecodedBuf.PutChar((char)0x0071); DecodedBuf.Position += 0x0070;//0x0071 zeros DecodedBuf.Put(0x00); byte[] EncodedBuf = crypter.Encrypt(DecodedBuf.ToByteArray(), user.QQKey.LoginInfo_Key1); #if DEBUG Client.LogManager.Log(ToString() + " QQKey.LoginInfo_Key1:" + Utils.Util.ToHex(user.QQKey.LoginInfo_Key1)); Client.LogManager.Log(ToString() + " pos:"+this.Pos+" UnBody:" + Utils.Util.ToHex(DecodedBuf.ToByteArray())); #endif buf.Put(EncodedBuf); #if DEBUG Client.LogManager.Log(ToString() + " EnBody:" + Utils.Util.ToHex(buf.ToByteArray())); #endif }
protected override void PutBody(ByteBuffer buf) { // 初始密钥 buf.PutChar((char)user.QQKey.LoginInfo_Magic_Token.Length); buf.Put(user.QQKey.LoginInfo_Magic_Token); ByteBuffer DecodedBuf = new ByteBuffer(); DecodedBuf.PutChar((char)0x0001); DecodedBuf.Put(VersionData.QQ09_VERSION_SPEC); DecodedBuf.Put(Client.QQUser.QQKey.LoginInfo_UnknowData2); DecodedBuf.Put(Client.ServerTime); DecodedBuf.Put(Client.ClientIP); DecodedBuf.Position += 4;//00 00 00 00 DecodedBuf.PutChar((char)Client.QQUser.QQKey.LoginInfo_Large_Token.Length); DecodedBuf.Put(Client.QQUser.QQKey.LoginInfo_Large_Token); DecodedBuf.Position += 35;// 00 00 00...... DecodedBuf.Put(VersionData.QQ09_EXE_HASH); DecodedBuf.Put((byte)Utils.Util.Random.Next()); DecodedBuf.Put((byte)Client.QQUser.LoginMode); DecodedBuf.Put(unknown5); ServerInfo si=Client.ServerInfo; si.CSP_dwConnIP=Client.QQUser.ServerIp; DecodedBuf.Put(0x00); DecodedBuf.Put(si.GetBytes()); DecodedBuf.Put(VersionData.QQ09_LOCALE); DecodedBuf.Position += 16; DecodedBuf.PutUShort((ushort)Client.QQUser.QQKey.Answer_Token.Length); DecodedBuf.Put(Client.QQUser.QQKey.Answer_Token); DecodedBuf.PutInt(0x00000007); DecodedBuf.PutInt(0x00000000); DecodedBuf.PutInt(0x08041001); DecodedBuf.PutInt(0x40);//length of the following --To comment //DecodedBuf.Put(0x40); DecodedBuf.Put(0x01); DecodedBuf.PutInt(Utils.Util.Random.Next()); //DecodedBuf.PutInt(0x0741E9748); DecodedBuf.PutChar((char)unknown6.Length); DecodedBuf.Put(unknown6); DecodedBuf.Put(unknown5); DecodedBuf.Put(0x00); DecodedBuf.Put(si.GetBytes()); DecodedBuf.Put(0x02); DecodedBuf.PutInt(Utils.Util.Random.Next()); //DecodedBuf.PutInt(0x8BED382E); DecodedBuf.PutChar((char)unknown7.Length); DecodedBuf.Put(unknown7); DecodedBuf.Position += 248;//all zeros DecodedBuf.Put(0x00); byte[] EncodedBuf = crypter.Encrypt(DecodedBuf.ToByteArray(), user.QQKey.LoginInfo_Key1); #if DEBUG Client.LogManager.Log(ToString() + " QQKey.LoginInfo_Key1:" + Utils.Util.ToHex(user.QQKey.LoginInfo_Key1)); Client.LogManager.Log(ToString() + " Uncoded Body:" + Utils.Util.ToHex(DecodedBuf.ToByteArray())); #endif buf.Put(EncodedBuf); #if DEBUG Client.LogManager.Log(ToString() + " Encoded Body:" + Utils.Util.ToHex(buf.ToByteArray())); #endif }
protected override void PutHeader(ByteBuffer buf) { if (!user.IsUdp) buf.PutUShort(0); buf.Put(Header); buf.PutChar(Source); buf.PutUShort((ushort)Command); buf.PutChar(Sequence); buf.PutInt((uint)user.QQ); }
protected override void PutBody(ByteBuffer buf) { // 2. 页数,从0开始 buf.PutUShort(Page); // 3. 在线与否,1字节,0x01表示在线,0x00表示不在线 buf.Put(SearchOnline ? (byte)0x01 : (byte)0x00); // 4. 是否有摄像头,1字节,0x01表示有,0x00表示无,TX QQ 2004中的处理是如果要查找 // 有摄像头的用户,则必须查找在线用户,不知道不这样行不行 buf.Put(HasCam ? (byte)0x01 : (byte)0x00); // 5. 年龄,1字节,表示在下拉框中的索引 buf.Put(AgeIndex); // 6. 性别,1字节,表示在下拉框中的索引 buf.Put(GenderIndex); // 7. 省份,2字节,表示在下拉框中的索引 buf.PutUShort(ProvinceIndex); // 8. 城市,2字节,表示在下拉框中的索引 buf.PutUShort(CityIndex); }