QQ应用程序源代码.docx
- 文档编号:1155841
- 上传时间:2022-10-18
- 格式:DOCX
- 页数:14
- 大小:19.79KB
QQ应用程序源代码.docx
《QQ应用程序源代码.docx》由会员分享,可在线阅读,更多相关《QQ应用程序源代码.docx(14页珍藏版)》请在冰豆网上搜索。
QQ应用程序源代码
QQ源代码
// MyQQ.cpp:
implementation of the MyQQ class. ////////////////////////////////////////////////////////////////////// #include #include
#include "winsock2.h"
#include "MyQQ.h" #include "md5.h"
#ifdef _DEBUG #undef THIS_FILE
static char THIS_FILE[]=__FILE__; #define new DEBUG_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 = (unsigned char*)malloc(QQ_KEY_LENGTH);
int i;
for(i = 0; i < 16; i++) InitKey = rand();
SessionKey = (unsigned char*)malloc(QQ_KEY_LENGTH); }
MyQQ:
:
~MyQQ() {
if(LoginServer !
= NULL) free(LoginServer); if(MyIP !
= NULL) free(MyIP);
if(MessageText !
= NULL) free(MessageText); if(Password !
= NULL) free(Password); if(InitKey !
= NULL) free(InitKey); if(PwdKey !
= NULL) free(PwdKey);
if(SessionKey !
= NULL) free(SessionKey);
if(FriendListHead !
= NULL) {
QQFriend *p = FriendListHead->next; while(p !
= NULL) {
free(FriendListHead); FriendListHead = p; p = p->next; }
if(FriendListTail !
= NULL) free(FriendListTail); } }
void MyQQ:
:
Login(int pMode) {
unsigned char *buf, *cursor, *raw_data, *encrypted_data; int seq_ret;
int encrypted_len, bytes;
//登录模式:
1 为正常登录,2为隐身登录 ,3登录即离开 LoginMode = pMode;
if(LoginToken == NULL) {
//发送获取登录令牌的包 qq_get_logintoken(); } else {
//2004登录包
buf = (unsigned char*)malloc(MAX_PACKAGE_LENGTH); //包长65535 raw_data = (unsigned char*)malloc(QQ_LOGIN_DATA_LENGTH); //数据长
encrypted_data = (unsigned char*)malloc(QQ_LOGIN_DATA_LENGTH + 16); //加密数据长度多16
// 产生密文
// 000-015 用PwdKey加密空串
MCrypter.qq_crypt(ENCRYPT, (unsigned char*)"", 0, PwdKey, raw_data, &encrypted_len);
//016-051 36字节的固定内容
memmove(raw_data + 16, login_16_51, 36);
//052-052 登录方式
raw_data[52] = (unsigned char)LoginMode;
//053-068 16字节固定内容
memmove(raw_data + 53, login_53_68, 16);
//069 登录令牌长度 int pos = 69;
raw_data[pos++] = (unsigned char)LoginTokenLength;
//070-?
登录令牌
memmove(raw_data + pos, LoginToken, LoginTokenLength);
pos += LoginTokenLength;
//未知字节0x40
raw_data[pos++] = 0x40;
//固定字节
memmove(raw_data + pos, LOGIN_SEGMENTS, 100);
pos += 100;
//剩下的字节填零
for(; pos < QQ_LOGIN_DATA_LENGTH; pos++) raw_data[pos] = 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); } }
//从包中读取一个字节
int MyQQ:
:
read_packet_b(unsigned char * buf, unsigned char ** cursor, int buflen, unsigned char * b) {
if(*cursor <= buf + buflen - sizeof(*b)) {
*b = **(unsigned char **) cursor; *cursor += sizeof(*b); return sizeof(*b); } else
return -1; }
//从包中读取一个字
int MyQQ:
:
read_packet_w(unsigned char * buf, unsigned char ** cursor, int buflen, short * w) {
if(*cursor <= buf + buflen - sizeof(*w)) {
*w = ntohs(**(short **) cursor); *cursor += sizeof(*w); return sizeof(*w); } else
return -1; }
//处理收到的消息
void MyQQ:
:
qq_process_recv_im(unsigned char* buf, int buf_len, short seq) {
int len, bytes;
unsigned char *data, *cursor; qq_recv_im_header *im_header;
len = buf_len;
data = (unsigned char *)malloc(len);
if (MCrypter.qq_crypt(DECRYPT, buf, buf_len, SessionKey, data, &len)) {
if(len < 16) return;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- QQ 应用程序 源代码
![提示](https://static.bdocx.com/images/bang_tan.gif)