|
unsigned char * MyQQ::gen_session_md5(int uid, unsigned char * session_key)
{
unsigned char *src, md5_str[QQ_KEY_LENGTH];
unsigned char *cursor;
md5_state_t ctx;
src = (unsigned char *)malloc(20);
cursor = src;
create_packet_dw(src, &cursor, uid);
create_packet_data(src, &cursor, session_key, QQ_KEY_LENGTH);
md5_init(&ctx);
md5_append(&ctx, src, 20);
md5_finish(&ctx, (md5_byte_t *) md5_str);
unsigned char * t = (unsigned char *)malloc(QQ_KEY_LENGTH);
memcpy(t,md5_str, QQ_KEY_LENGTH);
return t;
}
unsigned char * MyQQ::qq_get_send_im_tail(const char * font_color,
const char * font_size,
const char * font_name,
bool is_bold, bool is_italic, bool is_underline, int tail_len)
{
char *s1, *s2;
unsigned char *rgb;
int font_name_len;
unsigned char *send_im_tail;
const unsigned char simsun[] = { 0xcb, 0xce, 0xcc, 0xe5 };
font_name_len = DEFAULT_FONT_NAME_LEN;
font_name = (const char*)&(simsun[0]);
send_im_tail = (unsigned char*)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_tail[tail_len - 1] = tail_len;
send_im_tail[0] = 0x00;
send_im_tail[1] = 10;
if (is_bold)
send_im_tail[1] |= 0x20;
if (is_italic)
send_im_tail[1] |= 0x40;
if (is_underline)
send_im_tail[1] |= 0x80;
send_im_tail[2] = send_im_tail[3] = send_im_tail[4] = 0;
send_im_tail[5] = 0x00;
send_im_tail[6] = 0x86;
send_im_tail[7] = 0x22;
return (unsigned char *) send_im_tail;
}
//处理普通的QQ消息
void MyQQ::qq_process_recv_normal_im(unsigned char * data, unsigned char ** cursor, int len)
{
int bytes;
qq_recv_normal_im_common *common;
qq_recv_normal_im_unprocessed *im_unprocessed;
if (*cursor >= (data + len - 1)) {
return;
}
else
common = (qq_recv_normal_im_common *)malloc(sizeof(qq_recv_normal_im_common));
bytes = qq_normal_im_common_read(data, cursor, len, common);
if (bytes < 0) {
return;
}
switch (common->normal_im_type) {
case QQ_NORMAL_IM_TEXT:
qq_process_recv_normal_im_text (data, cursor, len, common);
break;
case QQ_NORMAL_IM_FILE_REJECT_UDP:
//qq_process_recv_file_reject (data, cursor, len,
// common->sender_uid, gc);
break;
case QQ_NORMAL_IM_FILE_APPROVE_UDP:
//qq_process_recv_file_accept (data, cursor, len,
// common->sender_uid, gc);
break;
case QQ_NORMAL_IM_FILE_REQUEST:
//qq_process_recv_file_request (data, cursor, len,
// common->sender_uid, gc);
break;
case QQ_NORMAL_IM_FILE_CANCEL:
//qq_process_recv_file_cancel (data, cursor, len,
// common->sender_uid, gc);
break;
case QQ_NORMAL_IM_FILE_NOTIFY:
//qq_process_recv_file_notify (data, cursor, len,
// common->sender_uid, gc);
break;
default:
return;
} // normal_im_type
g_free (common->session_md5);
}
void MyQQ::qq_process_recv_normal_im_text(unsigned char * data, unsigned char ** cursor, int len, qq_recv_normal_im_common * common)
{
short gaim_msg_type;
char *name;
char *msg_with_gaim_smiley;
char *msg_utf8_encoded;
qq_recv_normal_im_text *im_text;
if (*cursor >= (data + len - 1)) {
return;
} else
im_text = (qq_recv_normal_im_text *)malloc(sizeof(qq_recv_normal_im_text));
im_text->common = common;
read_packet_w(data, cursor, len, &(im_text->msg_seq));
read_packet_dw(data, cursor, len, &(im_text->send_time));
read_packet_b(data, cursor, len, &(im_text->unknown1));
read_packet_b(data, cursor, len, &(im_text->sender_icon));
read_packet_data(data, cursor, len, (unsigned char *) & (im_text->unknown2), 3);
read_packet_b(data, cursor, len, &(im_text->is_there_font_attr));
read_packet_data(data, cursor, len, (unsigned char *) & (im_text->unknown3), 4);
read_packet_b(data, cursor, len, &(im_text->msg_type));
if (im_text->msg_type == QQ_IM_AUTO_REPLY) {
im_text->is_there_font_attr = 0x00;
im_text->msg = (unsigned char *)malloc(1024);
memcpy(im_text->msg,*cursor, data + len - *cursor);
} else {
if (im_text->is_there_font_attr) {
im_text->msg = (unsigned char *)malloc(1500);
memcpy(im_text->msg,*cursor, strlen((const char *)*cursor));
im_text->msg[strlen((const char *)*cursor)] = 0;
}
else
{ im_text->msg = (unsigned char *)malloc(1024);
memcpy(im_text->msg,*cursor, data + len - *cursor);
im_text->msg[data + len - *cursor] = 0;
}
}
MessageText = im_text->msg;
//如果需要自动回复
if(Status == 3)
{
//I_QQAutoReply()函数获取预先设置的自动回复消息内容,需自己实现
char* MText = I_QQAutoReply();
QQSendTextMessage(common->sender_uid,MText,0x01);
}
//在主界面中显示消息
//I_QQReceiveMessage((char *)MessageText,common->sender_uid);
}
int MyQQ::qq_normal_im_common_read(unsigned char * data, unsigned char ** cursor, int len, qq_recv_normal_im_common * common)
{
int bytes;
bytes = 0;
bytes += read_packet_w(data, cursor, len, &(common->sender_ver));
bytes += read_packet_dw(data, cursor, len, &(common->sender_uid));
bytes += read_packet_dw(data, cursor, len, &(common->receiver_uid));
common->session_md5 = (unsigned char *)malloc(QQ_KEY_LENGTH);
memcpy(common->session_md5,*cursor, QQ_KEY_LENGTH);
bytes += QQ_KEY_LENGTH;
*cursor += QQ_KEY_LENGTH;
bytes += read_packet_w(data, cursor, len, &(common->normal_im_type));
if (bytes != 28) {
return -1;
}
return bytes;
}
//请求获得在线好友列表
void MyQQ::qq_send_packet_get_buddies_online(unsigned char position)
{
unsigned char *raw_data, *cursor;
raw_data = (unsigned char*)malloc(5);
cursor = raw_data;
create_packet_b(raw_data, &cursor, QQ_GET_ONLINE_BUDDY_02);
// 001-001 seems it supports 255 online buddies at most
create_packet_b(raw_data, &cursor, position);
// 002-002
create_packet_b(raw_data, &cursor, 0x00);
// 003-004
create_packet_w(raw_data, &cursor, 0x0000);
qq_send_cmd(QQ_CMD_GET_FRIENDS_ONLINE, TRUE, 0, TRUE, raw_data, 5);
}
//处理在线好友列表消息
void MyQQ::qq_process_get_buddies_online_reply(unsigned char * buf, int buf_len)
{
int len, bytes;
unsigned char *data, *cursor, position;
qq_buddy *q_bud;
qq_friends_online_entry *fe;
QQFriend *p;
len = buf_len;
data = (unsigned char *)malloc(len);
cursor = data;
if (MCrypter.qq_crypt(DECRYPT, buf, buf_len, SessionKey, data, &len))
{
read_packet_b(data, &cursor, len, &position);
fe = (qq_friends_online_entry *)malloc(sizeof(qq_friends_online_entry));
qq_buddy_status * s = (qq_buddy_status *)malloc(sizeof(qq_buddy_status));
while (cursor < (data + len))
{
bytes = 0;
// 000-003: uid
bytes += read_packet_dw(data, &cursor, len, &s->uid);
// 004-004: 0x01
bytes += read_packet_b(data, &cursor, len, &s->unknown1);
// 005-008: ip
s->ip = (unsigned char*)malloc(4);
bytes += read_packet_data(data, &cursor, len, s->ip, 4);
// 009-010: port
bytes += read_packet_w(data, &cursor, len, &s->port);
// 011-011: 0x00
bytes += read_packet_b(data, &cursor, len, &s->unknown2);
// 012-012: status
bytes += read_packet_b(data, &cursor, len, &s->status);
// 013-014:
bytes += read_packet_w(data, &cursor, len, &s->unknown3);
// 015-030: unknown key
s->unknown_key = (unsigned char*)malloc(QQ_KEY_LENGTH);
bytes += read_packet_data(data, &cursor, len, s->unknown_key, QQ_KEY_LENGTH);
// 031-032: unknown4
bytes += read_packet_w(data, &cursor, len, &fe->unknown1);
// 033-033: flag1
bytes += read_packet_b(data, &cursor, len, &fe->flag1);
// 034-034: comm_flag
bytes += read_packet_b(data, &cursor, len, &fe->comm_flag);
// 035-036:
bytes += read_packet_w(data, &cursor, len, &fe->unknown2);
// 037-037:
bytes += read_packet_b(data, &cursor, len, &fe->ending); // 0x00
p = FriendListHead;
while(p != NULL)
{
if(p->Buddy->uid == s->uid)
{
p->Buddy->status = s->status;
break;
}
p = p->next;
}
} // while cursor
if(position != 0xFF)
{
//如果类表为接收完,继续发消息请求
qq_send_packet_get_buddies_online(position);
}
else
{
//更新好友的状态
p = FriendListHead;
while(p != NULL)
{
if(p->Buddy->status != QQ_BUDDY_ONLINE_OFFLINE)
{
//I_QQChangeBuddyStatus(p->Buddy->uid, p->Buddy->status);
}
p = p->next;
}
}
}
}
//请求获得好友列表
void MyQQ::qq_send_packet_get_buddies_list(short position)
{
unsigned char *raw_data, *cursor;
int data_len;
data_len = 3;
raw_data = (unsigned char*)malloc(data_len);
cursor = raw_data;
// 000-001 starting position, can manually specify
create_packet_w(raw_data, &cursor, position);
create_packet_b(raw_data, &cursor, 0x00);
qq_send_cmd(QQ_CMD_GET_FRIENDS_LIST, TRUE, 0, TRUE, raw_data, data_len);
}
//处理好友列表消息
void MyQQ::qq_process_get_buddies_list_reply(unsigned char * buf, int buf_len)
{
qq_buddy *q_bud;
int len, bytes, bytes_expected, i;
short position = 0, unknown;
unsigned char *data, *cursor, bar;//, pascal_len;
unsigned short pascal_len;
char *name;
len = buf_len;
data = (unsigned char *)malloc(len);
cursor = data;
if (MCrypter.qq_crypt(DECRYPT, buf, buf_len, SessionKey, data, &len)) {
read_packet_w(data, &cursor, len, &position);
i = 0;
while (cursor < (data + len)) {
q_bud = (qq_buddy *)malloc(sizeof(qq_buddy));
bytes = 0;
// 000-003: uid
bytes += read_packet_dw(data, &cursor, len, &q_bud->uid);
// 004-004: 0xff if buddy is self, 0x00 otherwise
bytes += read_packet_b(data, &cursor, len, &bar);
// 005-005: icon index (1-255)
bytes += read_packet_b(data, &cursor, len, &q_bud->icon);
// 006-006: age
bytes += read_packet_b(data, &cursor, len, &q_bud->age);
// 007-007: gender
bytes += read_packet_b(data, &cursor, len, &q_bud->gender);
//这里如果字符集不同还要进行转换
pascal_len = cursor[0];
q_bud->nickname = (unsigned char*)malloc(pascal_len+1);
memcpy(q_bud->nickname,cursor+1,pascal_len);
q_bud->nickname[pascal_len] = 0;
pascal_len++;
cursor += pascal_len;
bytes += pascal_len;
bytes += read_packet_w(data, &cursor, len, &unknown);
bytes += read_packet_b(data, &cursor, len, &q_bud->flag1);
bytes += read_packet_b(data, &cursor, len, &q_bud->comm_flag);
bytes_expected = 12 + pascal_len;
if (q_bud->uid == 0 || bytes != bytes_expected) {
continue;
} else
i++;
//这里应是将好友信息写入本地好友列表
AddBuddyToList(q_bud);
} // while cursor
if (position == 0xFFFFFFFF) {
//在主界面上显示好友列表
//I_QQUpdateBuddyList();
//若接收完毕,则请求在线好友列表
qq_send_packet_get_buddies_online(QQ_FRIENDS_ONLINE_POSITION_START);
} else //继续请求好友列表
qq_send_packet_get_buddies_list(position);
}
}
| 网游盗号木马实现手记 | 01-09 |
| 黑色技术蠕虫下载者[完整源码] | 11-01 |
| 利用BCB自己打造QQ炸弹 | 10-23 |
| 从内存中加载并启动一个exe(delp | 09-27 |
| 开启和关闭Windows xp 防火墙(de | 09-27 |
| 让你的程序通过XP防火墙(delphi编 | 09-27 |
| 如何让你的程序安全通过windows防 | 08-20 |
| 如何透过程序来控制 Windows (XP | 08-20 |
| 动易2005-2006算号器的源代码 | 08-11 |
| API对注册表进行操作(Delphi编程 | 07-30 |
| 一段隐藏注册表项的代码 | 07-26 |
| 了解VB编写病毒的大体方法 | 07-02 |