📄 evaaddfriendex.cpp
字号:
/*************************************************************************** * Copyright (C) 2005 by casper * * tlmcasper@163.com * * * * Updated by yunfan, 15th, March, 2007 * * yunfan_zg@163.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "evaaddfriendex.h" #include "evautil.h" #include "evadefines.h"#ifdef _WIN32#include <winsock.h>#else#include <arpa/inet.h>#endif EvaAddFriendExPacket::EvaAddFriendExPacket() :OutPacket(), m_AddQQNum(0){}EvaAddFriendExPacket::EvaAddFriendExPacket(const unsigned int id) :OutPacket(QQ_CMD_ADD_FRIEND_EX, true), m_AddQQNum(id){}EvaAddFriendExPacket::EvaAddFriendExPacket(const EvaAddFriendExPacket &rhs) :OutPacket(rhs){ m_AddQQNum = rhs.getAddQQ();}EvaAddFriendExPacket &EvaAddFriendExPacket::operator=(const EvaAddFriendExPacket &rhs){ *((OutPacket *)this) = (OutPacket)rhs; m_AddQQNum = rhs.getAddQQ(); return *this;}int EvaAddFriendExPacket::putBody(unsigned char* buf){ if(m_AddQQNum==0) return 0; int pos = 0; pos += EvaUtil::write32(buf+pos, m_AddQQNum);//qq number of the added friend return pos;}/** ======================================================= */EvaAddFriendExReplyPacket::EvaAddFriendExReplyPacket(unsigned char* buf, int len) :InPacket(buf, len){}EvaAddFriendExReplyPacket::EvaAddFriendExReplyPacket(const EvaAddFriendExReplyPacket &rhs) :InPacket(rhs){ m_AddQQNum = rhs.getAddQQ(); m_AuthStatus = rhs.getAuthStatus(); m_ReplyCode = rhs.getReplyCode(); }EvaAddFriendExReplyPacket &EvaAddFriendExReplyPacket::operator=( const EvaAddFriendExReplyPacket &rhs){ *((InPacket *)this) = (InPacket)rhs; m_AddQQNum = rhs.getAddQQ(); m_AuthStatus = rhs.getAuthStatus(); m_ReplyCode = rhs.getReplyCode(); return *this;}void EvaAddFriendExReplyPacket::parseBody(){ int pos = 0; m_AddQQNum= EvaUtil::read32(decryptedBuf+pos); pos += 4; m_ReplyCode = decryptedBuf[pos++]; switch(m_ReplyCode){ case QQ_ADD_FRIEND_EX_ADDING_POSSIBLE://the user can be added to your buddy list m_AuthStatus = decryptedBuf[pos]; break; case QQ_ADD_FRIEND_EX_ALREADY_IN_LIST://the user is already in your buddy list break; default: break; } }/** ======================================================= */EvaAddFriendAuthExPacket::EvaAddFriendAuthExPacket() :OutPacket(QQ_CMD_ADD_FRIEND_AUTH_EX, true), m_AuthStatus(0x02), m_DestGroup(0), m_AllowAddReverse(true), m_AddQQNum(0), m_AuthCodeLen(0), m_AuthCode(0), m_QuestionCodeLen(0), m_QuestionCode(0), m_Message(""){}EvaAddFriendAuthExPacket::EvaAddFriendAuthExPacket(const unsigned int id, const unsigned char authStatus) :OutPacket(QQ_CMD_ADD_FRIEND_AUTH_EX, true), m_AuthStatus(authStatus), m_DestGroup(0), m_AllowAddReverse(true), m_AddQQNum(id), m_AuthCodeLen(0), m_AuthCode(0), m_QuestionCodeLen(0), m_QuestionCode(0), m_Message(""){}EvaAddFriendAuthExPacket::EvaAddFriendAuthExPacket( EvaAddFriendAuthExPacket& rhs) :OutPacket(rhs){ *this = rhs;}EvaAddFriendAuthExPacket::~EvaAddFriendAuthExPacket(){ if(m_AuthCodeLen && m_AuthCode){ delete []m_AuthCode; m_AuthCodeLen = 0; } if(m_QuestionCodeLen && m_QuestionCode){ delete []m_QuestionCode; m_QuestionCodeLen = 0; } }EvaAddFriendAuthExPacket &EvaAddFriendAuthExPacket::operator=(const EvaAddFriendAuthExPacket &rhs){ *((OutPacket *)this) = (OutPacket)rhs; m_AddQQNum = rhs.getAddQQ(); m_AuthStatus = rhs.getAuthStatus(); m_DestGroup = rhs.getDestGroup(); m_AllowAddReverse = rhs.getAllowAddReverse(); setAuthCode(rhs.getAuthCode(), rhs.getAuthCodeLength()); setQuestionCode( rhs.getQuestionCode(), rhs.getQuestionCodeLength()); return *this;}void EvaAddFriendAuthExPacket::setAuthCode( const unsigned char *code, const unsigned short len){ if(!code) return; m_AuthCodeLen = len; if(m_AuthCodeLen && code){ if(m_AuthCode) delete [] m_AuthCode; m_AuthCode = new unsigned char[m_AuthCodeLen]; memcpy(m_AuthCode, code, m_AuthCodeLen); }}void EvaAddFriendAuthExPacket::setQuestionCode( const unsigned char *code, const unsigned short len){ if(!code) return; m_QuestionCodeLen = len; if(m_QuestionCodeLen && code){ if(m_QuestionCode) delete [] m_QuestionCode; m_QuestionCode = new unsigned char[m_QuestionCodeLen]; memcpy(m_QuestionCode, code, m_QuestionCodeLen); }}int EvaAddFriendAuthExPacket::putBody( unsigned char * buf ){ int pos = 0; int len = 0; buf[pos++] = m_AuthStatus; pos += EvaUtil::write32(buf+pos, m_AddQQNum); // 2 bytes unknown, 0x0000 memset(buf + pos, 0, 2); pos += 2; if(m_AuthStatus == ADDING_AUTH_TYPE_ACCEPT) return pos; if(m_AuthStatus == ADDING_AUTH_TYPE_ACCEPT_ADD){ buf[pos++] = 0; return pos; } if( m_AuthStatus == ADDING_AUTH_TYPE_REJECT){ len = m_Message.length(); buf[pos++] = len & 0xff; if(len){ memcpy(buf+pos, m_Message.c_str(), len); pos += len; } return pos; } // 2 bytes, length of veri code *( (unsigned short *)(buf+pos)) = htons(m_AuthCodeLen); pos+=2; // veri code here memcpy(buf+pos, m_AuthCode, m_AuthCodeLen); pos+= m_AuthCodeLen; if( m_AuthStatus == ADDING_AUTH_TYPE_COMPOUND){ // 2 bytes, length of veri code *( (unsigned short *)(buf+pos)) = htons(m_QuestionCodeLen); pos+=2; // veri code here memcpy(buf+pos, m_QuestionCode, m_QuestionCodeLen); pos += m_QuestionCodeLen; } buf[pos++] = m_AllowAddReverse ? 0x01 : 0x02; buf[pos++] = m_DestGroup & 0xff; if( m_AuthStatus == ADDING_AUTH_TYPE_AUTH){ // only happen when auth is 0x02 len = m_Message.length(); buf[pos++] = len & 0xff; memcpy(buf+pos, m_Message.c_str(), len); pos += len; } return pos; }/* ======================================================= */EvaAddFriendAuthExReplyPacket::EvaAddFriendAuthExReplyPacket(unsigned char* buf, int len) :InPacket(buf, len){}EvaAddFriendAuthExReplyPacket::EvaAddFriendAuthExReplyPacket( const EvaAddFriendAuthExReplyPacket& rhs) :InPacket(rhs){ m_AddQQNum = rhs.getAddQQ(); m_AuthStatus = rhs.getAuthStatus(); m_ReplyCode = rhs.getReplyCode(); }EvaAddFriendAuthExReplyPacket &EvaAddFriendAuthExReplyPacket::operator=(const EvaAddFriendAuthExReplyPacket &rhs){ *((InPacket *)this) = (InPacket)rhs; m_AddQQNum = rhs.getAddQQ(); m_AuthStatus = rhs.getAuthStatus(); m_ReplyCode = rhs.getReplyCode(); return *this;}void EvaAddFriendAuthExReplyPacket::parseBody(){ int pos = 0; m_AuthStatus = decryptedBuf[pos++]; m_AddQQNum = EvaUtil::read32(decryptedBuf+pos); pos += 4; m_ReplyCode = decryptedBuf[pos++]; // 0x00: success}/** ======================================================= */EvaAddFriendGetAuthInfoPacket::EvaAddFriendGetAuthInfoPacket( ) :OutPacket(QQ_CMD_ADD_FRIEND_AUTH_INFO, true), m_IsQun(false), m_AddID(0), m_Cmd(AUTH_INFO_CMD_INFO){}EvaAddFriendGetAuthInfoPacket::EvaAddFriendGetAuthInfoPacket( const unsigned int id, const unsigned char cmd, const bool isQun ) :OutPacket(QQ_CMD_ADD_FRIEND_AUTH_INFO, true), m_IsQun(isQun), m_AddID(id), m_Cmd(cmd) {}EvaAddFriendGetAuthInfoPacket::EvaAddFriendGetAuthInfoPacket( const EvaAddFriendGetAuthInfoPacket & rhs ) : OutPacket(rhs){ *this = rhs;}EvaAddFriendGetAuthInfoPacket::~ EvaAddFriendGetAuthInfoPacket( ){}EvaAddFriendGetAuthInfoPacket & EvaAddFriendGetAuthInfoPacket::operator =( const EvaAddFriendGetAuthInfoPacket & rhs ){ *((OutPacket *)this) = (OutPacket)rhs; m_AddID = rhs.getAddID(); m_Cmd = rhs.getSubCommand(); m_Verification = rhs.getVerificationStr(); m_Session = rhs.getSessionStr(); m_IsQun = rhs.isQun(); return *this;}int EvaAddFriendGetAuthInfoPacket::putBody( unsigned char * buf ){ int pos = 0; buf[pos++] = m_Cmd; // unknown 2 bytes, always 0x00 0x01 buf[pos++] = 0x00; if(m_IsQun){ buf[pos++] = 0x02; } else { buf[pos++] = 0x01; } pos += EvaUtil::write32(buf+pos, m_AddID); if(m_Cmd == AUTH_INFO_CMD_INFO) return pos; // now, should be AUTH_INFO_CMD_CODE(0x02) // length of verification string *((unsigned short*)(buf+pos)) = htons(m_Verification.length());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -