public static void Un_Pack_ErrMsg(int errorType, byte[] bytes) { try { bytes = bytes.Skip(2).ToArray(); bytes = bytes.Skip(1).ToArray(); bytes = bytes.Skip(4).ToArray(); bytes = bytes.Skip(2).ToArray(); var errType = BitConverter.ToInt32(bytes.Take(4).ToArray().Reverse().ToArray(), 0); bytes = bytes.Skip(4).ToArray(); var titleLen = Convert.ToInt32(BitConverter.ToInt16(bytes.Take(2).ToArray().Reverse().ToArray(), 0)); bytes = bytes.Skip(2).ToArray(); var title = Encoding.UTF8.GetString(bytes, 0, titleLen); var messageLen = Convert.ToInt32(BitConverter.ToInt16(bytes.Skip(titleLen).Take(2).ToArray().Reverse().ToArray(), 0)); var message = Encoding.UTF8.GetString(bytes.Skip(titleLen + 2).ToArray(), 0, messageLen); API.last_error = title + ":" + errorType.ToString() + " " + message; Debug.Print(API.last_error); SDK.GetLog(API.last_error); } catch (Exception ex) { } }
public static byte[] UnPackReceiveData(byte[] ReceiveData) { if (ReceiveData.Length == 0) { return(null); } byte[] teaBytes = null; try { UpdateSyncCoookies(); Debug.Print("收到包:" + ReceiveData.Length.ToString() + "\r\n" + BitConverter.ToString(ReceiveData).Replace("-", " ")); var packType = ReceiveData.Skip(7).Take(1).ToArray()[0]; var encrptType = ReceiveData.Skip(8).Take(1).ToArray()[0]; int pos = API.SearchBytes(ReceiveData, API.QQ.UTF8); var bytes = ReceiveData.Skip(pos + API.QQ.UTF8.Length).ToArray(); teaBytes = bytes; HashTea Hash = new HashTea(); if (packType == 0xB && packType == 9) { if (encrptType == 1) { bytes = Hash.UNHashTEA(bytes, API.QQ.key, 0, true); } else if (encrptType == 2) { bytes = Hash.UNHashTEA(bytes, API.QQ.shareKey, 0, true); } } else if (packType == 0xA && packType == 8) { if (encrptType == 1) { bytes = Hash.UNHashTEA(bytes, API.QQ.shareKey, 0, true); } else if (encrptType == 2) { bytes = Hash.UNHashTEA(bytes, API.QQ.key, 0, true); } } else if (packType == 0xA && packType == 10) { if (encrptType == 1) { bytes = Hash.UNHashTEA(bytes, API.UN_Tlv.T305_SessionKey, 0, true); } else if (encrptType == 2) { bytes = Hash.UNHashTEA(bytes, API.QQ.key, 0, true); } } else { bytes = Hash.UNHashTEA(bytes, API.UN_Tlv.T305_SessionKey, 0, true); } Debug.Print("解密后:" + bytes.Length.ToString() + "\r\n" + BitConverter.ToString(bytes).Replace("-", " ")); //取出第一层包头中的包长度值 if (BitConverter.ToInt16(bytes.Take(2).ToArray(), 0) != 0) { Debug.Print("未解析" + "\r\n" + BitConverter.ToString(teaBytes).Replace("-", " ")); Debug.Print("ShareKey" + "\r\n" + BitConverter.ToString(API.QQ.shareKey).Replace("-", " ")); Debug.Print("SessionKey" + "\r\n" + BitConverter.ToString(API.UN_Tlv.T305_SessionKey).Replace("-", " ")); return(null); } var head1_len = BitConverter.ToInt32(bytes.Take(4).ToArray().Reverse().ToArray(), 0); byte[] bodyBytes = bytes.Skip(head1_len).ToArray(); Debug.Print("主包体:" + bodyBytes.Length.ToString() + "\r\n" + BitConverter.ToString(bodyBytes).Replace("-", " ")); if (head1_len > 4) { bytes = bytes.Skip(4).Take(head1_len - 4).ToArray(); bytes = bytes.Skip(4).ToArray(); if (bytes.Skip(4).Take(4).ToArray() == new byte[] { 0, 0, 0, 0 }) { bytes = bytes.Skip(4).ToArray(); } else { var head3_len = BitConverter.ToInt32(bytes.Skip(4).Take(4).ToArray().Reverse().ToArray(), 0); bytes = bytes.Skip(head3_len + 4).ToArray(); } var str_len = BitConverter.ToInt32(bytes.Take(4).ToArray().Reverse().ToArray(), 0); if (str_len > 4) { var serviceCmd = Encoding.UTF8.GetString(bytes.Skip(4).ToArray(), 0, str_len - 4); if (serviceCmd.Contains("wtlogin.login")) { Debug.Print("收到命令:wtlogin.login"); //解析登录包体 var status = Un_Pack_Login(bodyBytes); Debug.Print("status:" + status.ToString()); if (status == 1) { Debug.Print("wtlogin.login"); SDK.GetLog("登录成功"); //发上线包 API.TClient.SendData(Pack.PackOnlineStatus("StatSvc.register", 0)); } else if (status == 0) { Microsoft.VisualBasic.Interaction.MsgBox(API.getLastError(), (Microsoft.VisualBasic.MsgBoxStyle)((int)Microsoft.VisualBasic.Constants.vbInformation + (int)Microsoft.VisualBasic.Constants.vbMsgBoxSetForeground + (int)Microsoft.VisualBasic.Constants.vbSystemModal + (int)Microsoft.VisualBasic.Constants.vbCritical + (int)Microsoft.VisualBasic.Constants.vbInformation), "登录失败"); } else if (status == 2) { API.QQ.loginState = (int)API.LoginState.Logining; if (API.UN_Tlv.T143_token_A2 != null && API.QQ.shareKey != null && API.UN_Tlv.T10A_token_A4 != null) { API.TClient.SendData(Pack.PackOnlineStatus("StatSvc.register", 1)); } } } else if (serviceCmd.Contains("PushService.register")) { Debug.Print("服务器注册成功:PushService.register"); } else if (serviceCmd.Contains("RegPrxySvc.PushParam")) { Debug.Print("RegPrxySvc.PushParam命令"); } else if (serviceCmd.Contains("ConfigPushSvc.PushDomain")) { Debug.Print("成功登录服务器:ConfigPushSvc.PushDomain"); SDK.GetLog("上线成功"); } else if (serviceCmd.Contains("OnlinePush.ReqPush")) { Debug.Print("OnlinePush.ReqPush系统推送消息、撤回、加好友等"); } else if (serviceCmd.Contains("ConfigPushSvc.PushReq")) { Debug.Print("回执ConfigPushSvc.PushReq"); JceStructSDK.ReplyConfigPushSvc(bodyBytes, API.QQ.mRequestID); } else if (serviceCmd.Contains("StatSvc.SimpleGet")) { Debug.Print("收到心跳包"); SDK.GetHeartBeatResult(true); } else if (serviceCmd.Contains("MessageSvc.PushNotify")) { Debug.Print("通知好友消息:" + bytes.Length.ToString() + "\r\n" + BitConverter.ToString(bytes).Replace("-", " ")); bytes = bytes.Reverse().ToArray(); var code = bytes.Skip(15).Take(4).ToArray().Reverse().ToArray(); var sendByte = Pack.PackFriendMsg(code); //组包获取好友消息 API.TClient.SendData(sendByte); } else if (serviceCmd.Contains("MessageSvc.PbGetMsg")) { Debug.Print("收到好友消息"); FriendMsg.ParsingFriendMsg(bodyBytes); } else if (serviceCmd.Contains("OnlinePush.PbPushGroupMsg")) { Debug.Print("群聊消息"); GroupMsg.ParsingGroupMsg(bodyBytes); } else if (serviceCmd.Contains("MessageSvc.RequestPushStatus")) { Debug.Print("上线下线状态改变"); } else if (serviceCmd.Contains("MessageSvc.PushReaded")) { Debug.Print("已读私人消息"); } else if (serviceCmd.Contains("OnlinePush.PbC2CMsgSync")) { Debug.Print("发私人消息"); } else if (serviceCmd.Contains("RegPrxySvc.PbGetGroupMsg")) { Debug.Print("群消息"); } else if (serviceCmd.Contains("RegPrxySvc.PullGroupMsgSeq")) { Debug.Print("拉取群消息Seq"); } else if (serviceCmd.Contains("MessageSvc.PbGetOneDayRoamMsg")) { Debug.Print("解析漫游消息"); } else if (serviceCmd.Contains("RegPrxySvc.PbSyncMsg")) { Debug.Print("同步历史消息"); } else if (serviceCmd.Contains("SSO.HelloPush")) { Debug.Print("回执SSO.HelloPush"); Pack.ReplySSOHelloPush(bodyBytes, API.QQ.mRequestID); } else if (serviceCmd.Contains("StatSvc.SvcReqMSFLoginNotify")) { Debug.Print("平板上/下线通知"); } else if (serviceCmd.Contains("MessageSvc.RequestPushStatus")) { Debug.Print("电脑上/下线通知"); } else if (serviceCmd.Contains("StatSvc.ReqMSFOffline")) { Debug.Print("异常提醒"); } else if (serviceCmd.Contains("StatSvc.QueryHB")) { Debug.Print("StatSvc.QueryHB"); } else if (serviceCmd.Contains("MessageSvc.PushForceOffline")) { Debug.Print("被顶下线"); SDK.GetLog("被顶下线"); } else if (serviceCmd.Contains("MessageSvc.PbSendMsg")) { Debug.Print("递增发送信息"); API.QQ.mRequestID = API.QQ.mRequestID + 1; } else if (serviceCmd.Contains("OnlinePush.PbC2CMsgSync")) { Debug.Print("同步递增发送信息"); } else if (serviceCmd.Contains("OnlinePush.PbPushDisMsg")) { Debug.Print("讨论组消息"); } else if (serviceCmd.Contains("OnlinePush.PbPushTransMsg")) { Debug.Print("管理员变动"); } else if (serviceCmd.Contains("friendlist.GetTroopListReqV2")) { Debug.Print("群列表"); JceStructSDK.GetGrouplist(bodyBytes); } else if (serviceCmd.Contains("friendlist.getFriendGroupList")) { Debug.Print("好友列表"); JceStructSDK.GetFriendlist(bodyBytes); } else if (serviceCmd.Contains("friendlist.GetTroopMemberList")) { Debug.Print("群成员列表"); JceStructSDK.GetGroupMemberlist(bodyBytes); } else if (serviceCmd.Contains("OidbSvc.0x899_0")) { Debug.Print("群管理列表"); ProtoSDK.GetGroupAdminlist(bodyBytes); } else if (serviceCmd.Contains("ProfileService.Pb.ReqSystemMsgNew.Friend")) { Debug.Print("新好友提醒"); } else if (serviceCmd.Contains("ProfileService.Pb.ReqNextSystemMsg.Friend")) { Debug.Print("加好友消息提醒"); } else if (serviceCmd.Contains("ProfileService.Pb.ReqSystemMsgNew.Group")) { Debug.Print("新群提醒"); } else if (serviceCmd.Contains("QualityTest.PushList")) { Debug.Print("回执QualityTest.PushList"); Pack.ReplyQualityTest(API.QQ.mRequestID + 1); } else if (serviceCmd.Contains("OnlinePush.SidTicketExpired")) { Debug.Print("回执门票过期"); } else if (serviceCmd.Contains("PubAccountSvc.get_follow_list")) { Debug.Print("获取列表"); } else if (serviceCmd.Contains("account.RequestQueryQQMobileContactsV3")) { Debug.Print("查询内容"); } else if (serviceCmd.Contains("ProfileService.GetSimpleInfo")) { Debug.Print("获取QQ资料信息"); JceStructSDK.GetSimpleInfo(bodyBytes); } else if (serviceCmd.Contains("StatSvc.register")) { Debug.Print("注册上线:StatSvc.register"); } else if (serviceCmd.Contains("PbMessageSvc.PbMsgReadedReport")) { Debug.Print("已读消息"); } else if (serviceCmd.Contains("OidbSvc.0x59f")) { Debug.Print("OidbSvc.0x59f命令"); JceStructSDK.GetRegSync_Info(); } else if (serviceCmd.Contains("RegPrxySvc.infoSync")) { Debug.Print("RegPrxySvc.infoSync命令"); } else if (serviceCmd.Contains("RegPrxySvc.GetMsgV2")) { Debug.Print("RegPrxySvc.GetMsgV2命令"); } else if (serviceCmd.Contains("LongConn.OffPicUp")) { Debug.Print("收到图片反馈LongConn.OffPicUp"); FriendMsg.SendFriendMsg(API.ThisQQ, API.SendQQ, bodyBytes, API.MsgType.PicMsg); } else if (serviceCmd.Contains("ImgStore.GroupPicUp")) { Debug.Print("收到群图片反馈ImgStore.GroupPicUp"); GroupMsg.SendGroupMsg(API.ThisQQ, API.GroupId, bodyBytes, API.MsgType.PicMsg, API.SendQQ); } else if (serviceCmd.Contains("PttStore.GroupPttUp")) { Debug.Print("收到群语音反馈PttStore.GroupPttUp"); GroupMsg.SendGroupAudio(bodyBytes, API.FileHash); } else if (serviceCmd.Contains("PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_UPLOAD-500")) { Debug.Print("收到好友语音反馈PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_UPLOAD-500"); FriendMsg.SendFriendAudio(API.ThisQQ, API.SendQQ, bodyBytes, API.FileHash); } else if (serviceCmd.Contains("PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_DOWNLOAD-1200")) { Debug.Print("取语音下载地址PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_DOWNLOAD-1200"); //FriendMsg.GetFriendAudioUrl(bodyBytes) } else if (serviceCmd.Contains("PbMessageSvc.PbMsgWithDraw")) { Debug.Print("撤回消息反馈PbMessageSvc.PbMsgWithDraw"); } else if (serviceCmd.Contains("SharpSvr.s2c")) { Debug.Print("语音视频电话SharpSvr.s2c"); } else { Debug.Print("其他命令" + serviceCmd); } } } } catch (Exception ex) { Debug.Print(ex.Message.ToString()); } return(null); }
public static int Un_Pack_Login(byte[] bytes) { var head1_len = BitConverter.ToInt32(bytes.Take(4).ToArray().Reverse().ToArray(), 0); bytes = bytes.Skip(4).ToArray(); bytes = bytes.Skip(1).ToArray(); var head2_len = Convert.ToInt32(BitConverter.ToInt16(bytes.Take(2).ToArray().Reverse().ToArray(), 0)); bytes = bytes.Skip(14).ToArray(); int result = bytes[0]; Debug.Print("验证类型码:" + result.ToString()); bytes = bytes.Skip(1).Take(head2_len - 16 - 1).ToArray(); HashTea Hash = new HashTea(); bytes = Hash.UNHashTEA(bytes, API.QQ.shareKey, 0, true); Debug.Print("Un_Pack_Login:"******"-", " ")); if (bytes.Take(2).ToArray()[1] == 25) { var len = BitConverter.ToInt16(bytes.Take(2).ToArray().Reverse().ToArray(), 0); bytes = bytes.Skip(2).ToArray(); var publickey = bytes.Take(len).ToArray(); bytes = bytes.Skip(len).ToArray(); var sharekey = ECDH.GetECDHKeysEx(publickey, API.QQ.pub_key, API.QQ.prikey); bytes = Hash.UNHashTEA(bytes, sharekey, 0, true); } if (result == 0) { bytes = bytes.Skip(7).ToArray(); var len = Convert.ToInt32(BitConverter.ToInt16(bytes.Take(2).ToArray().Reverse().ToArray(), 0)); bytes = bytes.Skip(2).Take(len).ToArray(); bytes = Hash.UNHashTEA(bytes, API.QQ.TGTKey, 0, true); Debug.Print("解密后登录成功数组:" + Environment.NewLine + BitConverter.ToString(bytes).Replace("-", " ")); DecodeTlv(bytes); API.QQ.key = API.UN_Tlv.T305_SessionKey; API.QQ.loginState = (int)API.LoginState.LoginSccess; return(1); } if (result == 2) { DecodeTlv(bytes.Skip(3).ToArray()); if (API.UN_Tlv.T192_captcha != null) { WebForm.Url = API.UN_Tlv.T192_captcha; WebForm f1 = new WebForm(); f1.ShowDialog(); API.QQ.loginState = (int)API.LoginState.Logining; if (API.QQ.Ticket != null) { API.TClient.SendData(Pack.VieryTicket(API.QQ.Ticket)); } } API.QQ.loginState = (int)API.LoginState.LoginFaild; return(2); } else if (result == 3) { Debug.Print("接收异常"); API.QQ.loginState = (int)API.LoginState.LoginFaild; } else if (result == 1) { Debug.Print("登录账号或密码错误"); API.QQ.loginState = (int)API.LoginState.LoginFaild; } else if (result == 40) { Debug.Print("账号被回收或无此账号"); API.QQ.loginState = (int)API.LoginState.LoginFaild; } else if (result == 40) { Debug.Print("账号被冻结,或者账号密码已泄漏,存在被盗风险"); API.QQ.loginState = (int)API.LoginState.LoginFaild; } else if (result == 160) { Debug.Print(result.ToString() + ":" + "\r\n" + BitConverter.ToString(bytes).Replace("-", " ")); DecodeTlv(bytes.Skip(3).ToArray()); SDK.GetLog(API.UN_Tlv.T17E_message); Debug.Print(API.UN_Tlv.T17E_message); if (API.UN_Tlv.T204_url_safeVerify != null) { WebForm2.Url = API.UN_Tlv.T204_url_safeVerify; WebForm2 f1 = new WebForm2(); f1.ShowDialog(); ClearWebDate(); } else { API.TClient.SendData(Pack.VieryPhoneCode()); string Answer = Microsoft.VisualBasic.Interaction.InputBox("请输入手机验证码"); if (!string.IsNullOrEmpty(Answer)) { Pack.SubmitVertificationCode(Answer); } } API.QQ.loginState = (int)API.LoginState.LoginVertify; return(2); } else if (result == 161) { Debug.Print("今日操作次数过多,请等待一天后再试"); DecodeTlv(bytes.Skip(3).ToArray()); WebForm2.Url = API.UN_Tlv.T204_url_safeVerify; WebForm f1 = new WebForm(); f1.ShowDialog(); ClearWebDate(); API.QQ.loginState = (int)API.LoginState.LoginVertify; return(2); } else if (result == 162) { Debug.Print("验证码获取频繁,60s后重试"); DecodeTlv(bytes.Skip(3).ToArray()); WebForm2.Url = API.UN_Tlv.T204_url_safeVerify; WebForm2 f1 = new WebForm2(); f1.ShowDialog(); ClearWebDate(); SendMobile = 3; //Thread.Sleep(60 * 1000) API.QQ.loginState = (int)API.LoginState.LoginVertify; return(2); } else if (result == 180) { Debug.Print("腾讯服务器繁忙,请重启框架重试"); SDK.GetLog("腾讯服务器繁忙,请重启框架重试."); API.QQ.loginState = (int)API.LoginState.LoginVertify; return(2); } else if (result == 204) { if (API.UN_Tlv.T104 == null) { Debug.Print("正在验证设备锁..."); //SDK.GetLog("正在验证设备锁..."); DecodeTlv(bytes.Skip(3).ToArray()); API.TClient.SendData(Pack.VieryLock()); API.QQ.loginState = (int)API.LoginState.LoginVertify; } return(2); } else if (result == 235) { Debug.Print("账号密码错误"); API.QQ.loginState = (int)API.LoginState.LoginVertify; } else if (result == 237) { Debug.Print("验证ticket输入错误或环境异常"); API.QQ.loginState = (int)API.LoginState.LoginVertify; } else if (result == 239) { Debug.Print(result.ToString() + ":" + "\r\n" + BitConverter.ToString(bytes).Replace("-", " ")); DecodeTlv(bytes.Skip(3).ToArray()); SDK.GetLog(API.UN_Tlv.T17E_message); Debug.Print(API.UN_Tlv.T17E_message); if (API.UN_Tlv.T204_url_safeVerify != null) { WebForm2.Url = API.UN_Tlv.T204_url_safeVerify; WebForm2 f1 = new WebForm2(); f1.ShowDialog(); ClearWebDate(); } else { API.TClient.SendData(Pack.VieryPhoneCode()); string Answer = Microsoft.VisualBasic.Interaction.InputBox("请输入手机验证码"); if (!string.IsNullOrEmpty(Answer)) { Pack.SubmitVertificationCode(Answer); } } API.QQ.loginState = (int)API.LoginState.LoginVertify; return(2); } else { Debug.Print("错误的验证类型:" + result.ToString()); API.QQ.loginState = (int)API.LoginState.LoginVertify; } Un_Pack_ErrMsg(result, bytes); return(3); }