QQ应用程序源代码.doc_第1页
QQ应用程序源代码.doc_第2页
QQ应用程序源代码.doc_第3页
QQ应用程序源代码.doc_第4页
QQ应用程序源代码.doc_第5页
免费预览已结束,剩余5页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

QQ源代码/MyQQ.cpp:implementationoftheMyQQclass./#include#include#includewinsock2.h#includeMyQQ.h#includemd5.h#ifdef_DEBUG#undefTHIS_FILEstaticcharTHIS_FILE=_FILE_;#definenewDEBUG_NEW#endif/Construction/Destruction/MyQQ:MyQQ()s=NULL;LoginToken=NULL;LoginTokenLength=0;Status=0;/下线IsLogin=false;LastID=0;MessageText=NULL;FriendListHead=NULL;FriendListTail=NULL;send_seq=random()&0x0000ffff;LastOnline=time(NULL);UDPServerNum=0;/服务器地址LoginServer=(char*)malloc(16*sizeof(char);/QQ号UserID=0;/密码Password=NULL;/得到初始化密钥,按2004版InitKey=(unsignedchar*)malloc(QQ_KEY_LENGTH);inti;for(i=0;inext;while(p!=NULL)free(FriendListHead);FriendListHead=p;p=p-next;if(FriendListTail!=NULL)free(FriendListTail);voidMyQQ:Login(intpMode)unsignedchar*buf,*cursor,*raw_data,*encrypted_data;intseq_ret;intencrypted_len,bytes;/登录模式:1为正常登录,2为隐身登录,3登录即离开LoginMode=pMode;if(LoginToken=NULL)/发送获取登录令牌的包qq_get_logintoken();else/2004登录包buf=(unsignedchar*)malloc(MAX_PACKAGE_LENGTH);/包长65535raw_data=(unsignedchar*)malloc(QQ_LOGIN_DATA_LENGTH);/数据长encrypted_data=(unsignedchar*)malloc(QQ_LOGIN_DATA_LENGTH+16);/加密数据长度多16/产生密文/000-015用PwdKey加密空串MCrypter.qq_crypt(ENCRYPT,(unsignedchar*),0,PwdKey,raw_data,&encrypted_len);/016-05136字节的固定内容memmove(raw_data+16,login_16_51,36);/052-052登录方式raw_data52=(unsignedchar)LoginMode;/053-06816字节固定内容memmove(raw_data+53,login_53_68,16);/069登录令牌长度intpos=69;raw_datapos+=(unsignedchar)LoginTokenLength;/070-?登录令牌memmove(raw_data+pos,LoginToken,LoginTokenLength);pos+=LoginTokenLength;/未知字节0x40raw_datapos+=0x40;/固定字节memmove(raw_data+pos,LOGIN_SEGMENTS,100);pos+=100;/剩下的字节填零for(;posQQ_LOGIN_DATA_LENGTH;pos+)raw_datapos=0x00;/加密MCrypter.qq_crypt(ENCRYPT,raw_data,QQ_LOGIN_DATA_LENGTH,InitKey,encrypted_data,&encrypted_len);cursor=buf;bytes=0;bytes+=create_packet_head_seq(buf,&cursor,QQ_CMD_LOGIN,true,&seq_ret);bytes+=create_packet_dw(buf,&cursor,UserID);bytes+=create_packet_data(buf,&cursor,InitKey,QQ_KEY_LENGTH);bytes+=create_packet_data(buf,&cursor,encrypted_data,encrypted_len);bytes+=create_packet_b(buf,&cursor,QQ_PACKET_TAIL);if(bytes=(cursor-buf)/包被无误创建qq_send_packet(buf,bytes,QQ_CMD_LOGIN);free(buf);free(raw_data);free(encrypted_data);/从包中读取一个字节intMyQQ:read_packet_b(unsignedchar*buf,unsignedchar*cursor,intbuflen,unsignedchar*b)if(*cursor=buf+buflen-sizeof(*b)*b=*(unsignedchar*)cursor;*cursor+=sizeof(*b);returnsizeof(*b);elsereturn-1;/从包中读取一个字intMyQQ:read_packet_w(unsignedchar*buf,unsignedchar*cursor,intbuflen,short*w)if(*cursor=buf+buflen-sizeof(*w)*w=ntohs(*(short*)cursor);*cursor+=sizeof(*w);returnsizeof(*w);elsereturn-1;/处理收到的消息voidMyQQ:qq_process_recv_im(unsignedchar*buf,intbuf_len,shortseq)intlen,bytes;unsignedchar*data,*cursor;qq_recv_im_header*im_header;len=buf_len;data=(unsignedchar*)malloc(len);if(MCrypter.qq_crypt(DECRYPT,buf,buf_len,SessionKey,data,&len)if(lensender_uid);bytes+=read_packet_dw(data,&cursor,len,&(im_header-receiver_uid);bytes+=read_packet_dw(data,&cursor,len,&(im_header-server_im_seq);bytes+=read_packet_data(data,&cursor,len,(unsignedchar*)&(im_header-sender_ip),4);bytes+=read_packet_w(data,&cursor,len,&(im_header-sender_port);bytes+=read_packet_w(data,&cursor,len,&(im_header-im_type);if(bytes!=20)/im_header的长度return;if(im_header-receiver_uid!=UserID)return;LastID=im_header-sender_uid;switch(im_header-im_type)caseQQ_RECV_IM_TO_BUDDY:qq_process_recv_normal_im(data,&cursor,len);break;caseQQ_RECV_IM_TO_UNKNOWN:qq_process_recv_normal_im(data,&cursor,len);break;caseQQ_RECV_IM_GROUP_IM:/qq_process_recv_group_im(data,&cursor,len,im_header-sender_uid,gc);break;caseQQ_RECV_IM_ADD_TO_GROUP:/qq_process_recv_group_im_been_added(data,&cursor,len,im_header-sender_uid,gc);break;caseQQ_RECV_IM_DEL_FROM_GROUP:/qq_process_recv_group_im_been_removed(data,&cursor,len,im_header-sender_uid,gc);break;caseQQ_RECV_IM_APPLY_ADD_TO_GROUP:/qq_process_recv_group_im_apply_join(data,&cursor,len,im_header-sender_uid,gc);break;caseQQ_RECV_IM_APPROVE_APPLY_ADD_TO_GROUP:/qq_process_recv_group_im_been_approved(data,&cursor,len,im_header-sender_uid,gc);break;caseQQ_RECV_IM_REJCT_APPLY_ADD_TO_GROUP:/qq_process_recv_group_im_been_rejected(data,&cursor,len,im_header-sender_uid,gc);break;caseQQ_RECV_IM_SYS_NOTIFICATION:/_qq_process_recv_sys_im(data,&cursor,len,gc);break;default:break;/switch/处理登录Reply的消息voidMyQQ:qq_process_login_reply(unsignedchar*buf,intbuf_len)if(IsLogin=true)return;intlen,ret,bytes;unsignedchar*data;len=buf_len;data=(unsignedchar*)malloc(len);if(MCrypter.qq_crypt(DECRYPT,buf,buf_len,PwdKey,data,&len)if(data0=QQ_LOGIN_REPLY_OK)ret=qq_process_login_ok(data,len);elseret=QQ_LOGIN_REPLY_MISC_ERROR;elselen=buf_len;if(MCrypter.qq_crypt(DECRYPT,buf,buf_len,InitKey,data,&len)bytes=0;switch(data0)caseQQ_LOGIN_REPLY_REDIRECT:ret=qq_process_login_redirect(data,len);break;caseQQ_LOGIN_REPLY_PWD_ERROR:ret=qq_process_login_wrong_pwd(data,len);break;default:ret=QQ_LOGIN_REPLY_MISC_ERROR;elseret=QQ_LOGIN_REPLY_MISC_ERROR;switch(ret)caseQQ_LOGIN_REPLY_PWD_ERROR:MessageBox(NULL,QQ密码错误!,错误,MB_OK);break;caseQQ_LOGIN_REPLY_MISC_ERROR:MessageBox(NULL,QQ登录出错,请重试!,错误,MB_OK);break;caseQQ_LOGIN_REPLY_OK:break;caseQQ_LOGIN_REPLY_REDIRECT:break;default:break;/switchretvoidMyQQ:qq_process_group_cmd_reply(unsignedchar*cursor,intlen,shortseq)voidMyQQ:qq_process_msg_sys(unsignedchar*cursor,intlen,shortseq)voidMyQQ:qq_process_friend_change_status(unsignedchar*buf,intbuf_len)intlen,bytes;unsignedchar*data,*cursor;len=buf_len;data=(unsignedchar*)malloc(len);cursor=data;qq_buddy_status*ss;if(MCrypter.qq_crypt(DECRYPT,buf,buf_len,SessionKey,data,&len)ss=(qq_buddy_status*)malloc(sizeof(qq_buddy_status);bytes=0;/000-003:uidbytes+=read_packet_dw(data,&cursor,len,&ss-uid);/004-004:0x01bytes+=read_packet_b(data,&cursor,len,&ss-unknown1);/005-008:ipss-ip=(unsignedchar*)malloc(4);bytes+=read_packet_data(data,&cursor,len,ss-ip,4);/009-010:portbytes+=read_packet_w(data,&cursor,len,&ss-port);/011-011:0x00bytes+=read_packet_b(data,&cursor,len,&ss-unknown2);/012-012:statusbytes+=read_packet_b(data,&cursor,len,&ss-status);/013-014:bytes+=read_packet_w(data,&cursor,len,&ss-unknown3);/015-030:unknownkeyss-unknown_key=(unsignedchar*)malloc(QQ_KEY_LENGTH);bytes+=read_packet_data(data,&cursor,len,ss-unknown_key,QQ_KEY_LENGTH);/这里是更新好友的状态,可自己实现接口/I_QQChangeBuddyStatus(ss-uid,ss-status);intMyQQ:qq_process_login_ok(unsignedchar*data,intlen)qq_login_reply_oklrop;intbytes;unsignedchar*cursor;cursor=data;bytes=0;/000-000:replycodebytes+=read_packet_b(data,&cursor,len,&lrop.result);/001-016:sessionkeylrop.session_key=(unsignedchar*)malloc(QQ_KEY_LENGTH);memcpy(lrop.session_key,cursor,QQ_KEY_LENGTH);cursor+=QQ_KEY_LENGTH;bytes+=QQ_KEY_LENGTH;/017-020:loginuidbytes+=read_packet_dw(data,&cursor,len,&lrop.uid);/021-024:serverdetecteduserpublicIPbytes+=read_packet_data(data,&cursor,len,(unsignedchar*)&lrop.client_ip,4);/025-026:serverdetecteduserportbytes+=read_packet_w(data,&cursor,len,&lrop.client_port);/027-030:serverdetecteditselfip?bytes+=read_packet_data(data,&cursor,len,(unsignedchar*)&lrop.server_ip,4);/031-032:serverlisteningportbytes+=read_packet_w(data,&cursor,len,&lrop.server_port);/033-036:logintimeforcurrentsessionbytes+=read_packet_dw(data,&cursor,len,(DWORD*)&lrop.login_time);/037-062:26bytes,unknownbytes+=read_packet_data(data,&cursor,len,(unsignedchar*)&lrop.unknown1,26);/063-066:unknownserver1ipaddressbytes+=read_packet_data(data,&cursor,len,(unsignedchar*)&lrop.unknown_server1_ip,4);/067-068:unknownserver1portbytes+=read_packet_w(data,&cursor,len,&lrop.unknown_server1_port);/069-072:unknownserver2ipaddressbytes+=read_packet_data(data,&cursor,len,(unsignedchar*)&lrop.unknown_server2_ip,4);/073-074:unknownserver2portbytes+=read_packet_w(data,&cursor,len,&lrop.unknown_server2_port);/075-076:2bytesunknownbytes+=read_packet_w(data,&cursor,len,&lrop.unknown2);/077-078:2bytesunknownbytes+=read_packet_w(data,&cursor,len,&lrop.unknown3);/079-110:32bytesunknownbytes+=read_packet_data(data,&cursor,len,(unsignedchar*)&lrop.unknown4,32);/111-122:12bytesunknownbytes+=read_packet_data(data,&cursor,len,(unsignedchar*)&lrop.unknown5,12);/123-126:loginIPoflastsessionbytes+=read_packet_data(data,&cursor,len,(unsignedchar*)&lrop.last_client_ip,4);/127-130:logintimeoflastsessionbytes+=read_packet_dw(data,&cursor,len,(DWORD*)&lrop.last_login_time);/131-138:8bytesunknownbytes+=read_packet_data(data,&cursor,len,(unsignedchar*)&lrop.unknown6,8);memcpy(SessionKey,lrop.session_key,QQ_KEY_LENGTH);sprintf(MyIP,%d.%d.%d.%d,lrop.client_ip0,lrop.client_ip1,lrop.client_ip2,lrop.client_ip3);MyPort=lrop.client_port;IsLogin=true;qq_send_packet_get_info(UserID);switch(LoginMode)case1:Status=1;break;case2:Status=3;break;default:break;qq_send_packet_change_status();GetFriendList();returnQQ_LOGIN_REPLY_OK;intMyQQ:qq_process_login_redirect(unsignedchar*data,intlen)intbytes,ret;unsignedchar*cursor;qq_login_reply_redirect_packetlrrp;cursor=data;bytes=0;/000-000:replycodebytes+=read_packet_b(data,&cursor,len,&lrrp.result);/001-004:loginuidbytes+=read_packet_dw(data,&cursor,len,&lrrp.uid);/005-008:redirectednewserverIPbytes+=read_packet_data(data,&cursor,len,lrrp.new_server_ip,4);/009-010:redirectednewserverportbytes+=read_packet_w(data,&cursor,len,&lrrp.new_server_port);if(bytes!=QQ_LOGIN_REPLY_REDIRECT_PACKET_LEN)ret=QQ_LOGIN_REPLY_MISC_ERROR;elsesprintf(LoginServer,%d.%d.%d.%d,lrrp.new_server_ip0,lrrp.new_server_ip1,lrrp.new_server_ip2,lrrp.new_server_ip3);/服务器端口LoginPort=lrrp.new_server_port;ServerAddr.sin_family=AF_INET;ServerAddr.sin_addr.s_addr=inet_addr(LoginServer);ServerAddr.sin_port=htons(LoginPort);/向新的服务器地址发送登录请求Login(LoginMode);ret=QQ_LOGIN_REPLY_REDIRECT;returnret;intMyQQ:qq_process_login_wrong_pwd(unsignedchar*data,intlen)returnQQ_LOGIN_REPLY_PWD_ERROR;voidMyQQ:qq_send_packet_change_status()unsignedchar*raw_data,*cursor,away_cmd;DWORDmisc_status;if(IsLogin=false)return;switch(Status)case1:away_cmd=QQ_BUDDY_ONLINE_NORMAL;break;case2:away_cmd=QQ_BUDDY_ONLINE_INVISIBLE;break;case3:away_cmd=QQ_BUDDY_ONLINE_AWAY;break;default:away_cmd=QQ_BUDDY_ONLINE_NORMAL;/switchraw_data=(unsignedchar*)malloc(5);cursor=raw_data;misc_status=0x00000000;create_packet_b(raw_data,&cursor,away_cmd);create_packet_dw(raw_data,&cursor,misc_status);qq_send_cmd(QQ_CMD_CHANGE_ONLINE_STATUS,TRUE,0,TRUE,raw_data,5);voidMyQQ:TurnInvisible()Status=2;qq_send_packet_change_status();voidMyQQ:TurnVisible()Status=1;qq_send_packet_change_status();voidMyQQ:TurnAway()Status=3;qq_send_packet_change_status();voidMyQQ:Logout()inti;for(i=0;imy_icon);bytes+=create_packet_b(raw_data,&cursor,MyIcon);/044-046:always0x00bytes+=create_packet_w(raw_data,&cursor,0x0000);bytes+=create_packet_b(raw_data,&cursor,0x00);/047-047:weusefontattrbytes+=create_packet_b(raw_data,&cursor,0x01);/048-051:always0x00bytes+=create_packet_dw(raw_data,&cursor,0x00000000);/052-052:textmessagetype(normal/auto-reply)bytes+=create_packet_b(raw_data,&cursor,type);/053-:msgendswith0x00bytes+=create_packet_data(raw_data,&cursor,(unsignedchar*)msg_filtered,msg_len);unsignedchar*send_im_tail=qq_get_send_im_tail(font_color,font_size,font_name,false,false,false,tail_len);bytes+=create_packet_data(raw_data,&cursor,send_im_tail,tail_len);if(bytes=raw_len)/createpacketOKqq_send_cmd(QQ_CMD_SEND_IM,TRUE,0,TRUE,raw_data,cursor-raw_data);constunsignedcharsimsun=0xcb,0xce,0xcc,0xe5;font_name_len=DEFAULT_FONT_NAME_LEN;font_name=(constchar*)&(simsun0);send_im_tail=(unsignedchar*)malloc(tail_len);memcpy(send_im_tail+QQ_SEND_IM_AFTER_MSG_HEADER_LEN,font_name,tail_len-QQ_SEND_IM_AFTER_MSG_HEADER_LEN);send_im_tailtail_len-1=tail_len;send_im_tail0=0x00;send_im_tail1=10;if(is_bold)send_im_tail1|=0x20;if(is_italic)send_im_tail1|=0x40;if(is_underline)send_im_tail1|=0x80;send_im_tail2=send_im_tail3=send_im_tail4=0;send_im_tail5=0x00;send_im_tail6=0x86;send_im_tail7=0x22;return(unsignedchar*)send_im_tail;/处理普通的QQ消息voidMyQQ:qq_process_recv_normal_im(unsignedchar*data,unsignedchar*cursor,intlen)intbytes;qq_recv_normal_im_common*common;qq_recv_normal_im_unprocessed*im_unprocessed;if(*cursor=(data+len-1)return;elsecommon=(qq_recv_normal_im_common*)malloc(sizeof(qq_recv_normal_im_common);bytes=qq_normal_im_common_read(data,cursor,len,common);if(bytesnormal_im_type)caseQQ_NORMAL_IM_TEXT:qq_process_recv_normal_im_text(data,cursor,len,common);break;caseQQ_NORMAL_

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论