1# $Id: qq.py 48 2008-05-27 17:31:15Z yardley $ 2# -*- coding: utf-8 -*- 3from __future__ import absolute_import 4 5from .dpkt import Packet 6 7 8# header_type 9QQ_HEADER_BASIC_FAMILY = 0x02 10QQ_HEADER_P2P_FAMILY = 0x00 11QQ_HEADER_03_FAMILY = 0x03 12QQ_HEADER_04_FAMILY = 0x04 13QQ_HEADER_05_FAMILY = 0x05 14 15header_type_str = [ 16 "QQ_HEADER_P2P_FAMILY", 17 "Unknown Type", 18 "QQ_HEADER_03_FAMILY", 19 "QQ_HEADER_04_FAMILY", 20 "QQ_HEADER_05_FAMILY", 21] 22 23# command 24QQ_CMD_LOGOUT = 0x0001 25QQ_CMD_KEEP_ALIVE = 0x0002 26QQ_CMD_MODIFY_INFO = 0x0004 27QQ_CMD_SEARCH_USER = 0x0005 28QQ_CMD_GET_USER_INFO = 0x0006 29QQ_CMD_ADD_FRIEND = 0x0009 30QQ_CMD_DELETE_FRIEND = 0x000A 31QQ_CMD_ADD_FRIEND_AUTH = 0x000B 32QQ_CMD_CHANGE_STATUS = 0x000D 33QQ_CMD_ACK_SYS_MSG = 0x0012 34QQ_CMD_SEND_IM = 0x0016 35QQ_CMD_RECV_IM = 0x0017 36QQ_CMD_REMOVE_SELF = 0x001C 37QQ_CMD_REQUEST_KEY = 0x001D 38QQ_CMD_LOGIN = 0x0022 39QQ_CMD_GET_FRIEND_LIST = 0x0026 40QQ_CMD_GET_ONLINE_OP = 0x0027 41QQ_CMD_SEND_SMS = 0x002D 42QQ_CMD_CLUSTER_CMD = 0x0030 43QQ_CMD_TEST = 0x0031 44QQ_CMD_GROUP_DATA_OP = 0x003C 45QQ_CMD_UPLOAD_GROUP_FRIEND = 0x003D 46QQ_CMD_FRIEND_DATA_OP = 0x003E 47QQ_CMD_DOWNLOAD_GROUP_FRIEND = 0x0058 48QQ_CMD_FRIEND_LEVEL_OP = 0x005C 49QQ_CMD_PRIVACY_DATA_OP = 0x005E 50QQ_CMD_CLUSTER_DATA_OP = 0x005F 51QQ_CMD_ADVANCED_SEARCH = 0x0061 52QQ_CMD_REQUEST_LOGIN_TOKEN = 0x0062 53QQ_CMD_USER_PROPERTY_OP = 0x0065 54QQ_CMD_TEMP_SESSION_OP = 0x0066 55QQ_CMD_SIGNATURE_OP = 0x0067 56QQ_CMD_RECV_MSG_SYS = 0x0080 57QQ_CMD_RECV_MSG_FRIEND_CHANGE_STATUS = 0x0081 58QQ_CMD_WEATHER_OP = 0x00A6 59QQ_CMD_ADD_FRIEND_EX = 0x00A7 60QQ_CMD_AUTHORIZE = 0X00A8 61QQ_CMD_UNKNOWN = 0xFFFF 62QQ_SUB_CMD_SEARCH_ME_BY_QQ_ONLY = 0x03 63QQ_SUB_CMD_SHARE_GEOGRAPHY = 0x04 64QQ_SUB_CMD_GET_FRIEND_LEVEL = 0x02 65QQ_SUB_CMD_GET_CLUSTER_ONLINE_MEMBER = 0x01 66QQ_05_CMD_REQUEST_AGENT = 0x0021 67QQ_05_CMD_REQUEST_FACE = 0x0022 68QQ_05_CMD_TRANSFER = 0x0023 69QQ_05_CMD_REQUEST_BEGIN = 0x0026 70QQ_CLUSTER_CMD_CREATE_CLUSTER = 0x01 71QQ_CLUSTER_CMD_MODIFY_MEMBER = 0x02 72QQ_CLUSTER_CMD_MODIFY_CLUSTER_INFO = 0x03 73QQ_CLUSTER_CMD_GET_CLUSTER_INFO = 0x04 74QQ_CLUSTER_CMD_ACTIVATE_CLUSTER = 0x05 75QQ_CLUSTER_CMD_SEARCH_CLUSTER = 0x06 76QQ_CLUSTER_CMD_JOIN_CLUSTER = 0x07 77QQ_CLUSTER_CMD_JOIN_CLUSTER_AUTH = 0x08 78QQ_CLUSTER_CMD_EXIT_CLUSTER = 0x09 79QQ_CLUSTER_CMD_SEND_IM = 0x0A 80QQ_CLUSTER_CMD_GET_ONLINE_MEMBER = 0x0B 81QQ_CLUSTER_CMD_GET_MEMBER_INFO = 0x0C 82QQ_CLUSTER_CMD_MODIFY_CARD = 0x0E 83QQ_CLUSTER_CMD_GET_CARD_BATCH = 0x0F 84QQ_CLUSTER_CMD_GET_CARD = 0x10 85QQ_CLUSTER_CMD_COMMIT_ORGANIZATION = 0x11 86QQ_CLUSTER_CMD_UPDATE_ORGANIZATION = 0x12 87QQ_CLUSTER_CMD_COMMIT_MEMBER_ORGANIZATION = 0x13 88QQ_CLUSTER_CMD_GET_VERSION_ID = 0x19 89QQ_CLUSTER_CMD_SEND_IM_EX = 0x1A 90QQ_CLUSTER_CMD_SET_ROLE = 0x1B 91QQ_CLUSTER_CMD_TRANSFER_ROLE = 0x1C 92QQ_CLUSTER_CMD_CREATE_TEMP = 0x30 93QQ_CLUSTER_CMD_MODIFY_TEMP_MEMBER = 0x31 94QQ_CLUSTER_CMD_EXIT_TEMP = 0x32 95QQ_CLUSTER_CMD_GET_TEMP_INFO = 0x33 96QQ_CLUSTER_CMD_MODIFY_TEMP_INFO = 0x34 97QQ_CLUSTER_CMD_SEND_TEMP_IM = 0x35 98QQ_CLUSTER_CMD_SUB_CLUSTER_OP = 0x36 99QQ_CLUSTER_CMD_ACTIVATE_TEMP = 0x37 100 101QQ_CLUSTER_SUB_CMD_ADD_MEMBER = 0x01 102QQ_CLUSTER_SUB_CMD_REMOVE_MEMBER = 0x02 103QQ_CLUSTER_SUB_CMD_GET_SUBJECT_LIST = 0x02 104QQ_CLUSTER_SUB_CMD_GET_DIALOG_LIST = 0x01 105 106QQ_SUB_CMD_GET_ONLINE_FRIEND = 0x2 107QQ_SUB_CMD_GET_ONLINE_SERVICE = 0x3 108QQ_SUB_CMD_UPLOAD_GROUP_NAME = 0x2 109QQ_SUB_CMD_DOWNLOAD_GROUP_NAME = 0x1 110QQ_SUB_CMD_SEND_TEMP_SESSION_IM = 0x01 111QQ_SUB_CMD_BATCH_DOWNLOAD_FRIEND_REMARK = 0x0 112QQ_SUB_CMD_UPLOAD_FRIEND_REMARK = 0x1 113QQ_SUB_CMD_REMOVE_FRIEND_FROM_LIST = 0x2 114QQ_SUB_CMD_DOWNLOAD_FRIEND_REMARK = 0x3 115QQ_SUB_CMD_MODIFY_SIGNATURE = 0x01 116QQ_SUB_CMD_DELETE_SIGNATURE = 0x02 117QQ_SUB_CMD_GET_SIGNATURE = 0x03 118QQ_SUB_CMD_GET_USER_PROPERTY = 0x01 119QQ_SUB_CMD_GET_WEATHER = 0x01 120 121QQ_FILE_CMD_HEART_BEAT = 0x0001 122QQ_FILE_CMD_HEART_BEAT_ACK = 0x0002 123QQ_FILE_CMD_TRANSFER_FINISHED = 0x0003 124QQ_FILE_CMD_FILE_OP = 0x0007 125QQ_FILE_CMD_FILE_OP_ACK = 0x0008 126QQ_FILE_CMD_SENDER_SAY_HELLO = 0x0031 127QQ_FILE_CMD_SENDER_SAY_HELLO_ACK = 0x0032 128QQ_FILE_CMD_RECEIVER_SAY_HELLO = 0x0033 129QQ_FILE_CMD_RECEIVER_SAY_HELLO_ACK = 0x0034 130QQ_FILE_CMD_NOTIFY_IP_ACK = 0x003C 131QQ_FILE_CMD_PING = 0x003D 132QQ_FILE_CMD_PONG = 0x003E 133QQ_FILE_CMD_YES_I_AM_BEHIND_FIREWALL = 0x0040 134QQ_FILE_CMD_REQUEST_AGENT = 0x0001 135QQ_FILE_CMD_CHECK_IN = 0x0002 136QQ_FILE_CMD_FORWARD = 0x0003 137QQ_FILE_CMD_FORWARD_FINISHED = 0x0004 138QQ_FILE_CMD_IT_IS_TIME = 0x0005 139QQ_FILE_CMD_I_AM_READY = 0x0006 140 141command_str = { 142 0x0001: "QQ_CMD_LOGOUT", 143 0x0002: "QQ_CMD_KEEP_ALIVE", 144 0x0004: "QQ_CMD_MODIFY_INFO", 145 0x0005: "QQ_CMD_SEARCH_USER", 146 0x0006: "QQ_CMD_GET_USER_INFO", 147 0x0009: "QQ_CMD_ADD_FRIEND", 148 0x000A: "QQ_CMD_DELETE_FRIEND", 149 0x000B: "QQ_CMD_ADD_FRIEND_AUTH", 150 0x000D: "QQ_CMD_CHANGE_STATUS", 151 0x0012: "QQ_CMD_ACK_SYS_MSG", 152 0x0016: "QQ_CMD_SEND_IM", 153 0x0017: "QQ_CMD_RECV_IM", 154 0x001C: "QQ_CMD_REMOVE_SELF", 155 0x001D: "QQ_CMD_REQUEST_KEY", 156 0x0022: "QQ_CMD_LOGIN", 157 0x0026: "QQ_CMD_GET_FRIEND_LIST", 158 0x0027: "QQ_CMD_GET_ONLINE_OP", 159 0x002D: "QQ_CMD_SEND_SMS", 160 0x0030: "QQ_CMD_CLUSTER_CMD", 161 0x0031: "QQ_CMD_TEST", 162 0x003C: "QQ_CMD_GROUP_DATA_OP", 163 0x003D: "QQ_CMD_UPLOAD_GROUP_FRIEND", 164 0x003E: "QQ_CMD_FRIEND_DATA_OP", 165 0x0058: "QQ_CMD_DOWNLOAD_GROUP_FRIEND", 166 0x005C: "QQ_CMD_FRIEND_LEVEL_OP", 167 0x005E: "QQ_CMD_PRIVACY_DATA_OP", 168 0x005F: "QQ_CMD_CLUSTER_DATA_OP", 169 0x0061: "QQ_CMD_ADVANCED_SEARCH", 170 0x0062: "QQ_CMD_REQUEST_LOGIN_TOKEN", 171 0x0065: "QQ_CMD_USER_PROPERTY_OP", 172 0x0066: "QQ_CMD_TEMP_SESSION_OP", 173 0x0067: "QQ_CMD_SIGNATURE_OP", 174 0x0080: "QQ_CMD_RECV_MSG_SYS", 175 0x0081: "QQ_CMD_RECV_MSG_FRIEND_CHANGE_STATUS", 176 0x00A6: "QQ_CMD_WEATHER_OP", 177 0x00A7: "QQ_CMD_ADD_FRIEND_EX", 178 0x00A8: "QQ_CMD_AUTHORIZE", 179 0xFFFF: "QQ_CMD_UNKNOWN", 180 0x0021: "_CMD_REQUEST_AGENT", 181 # 0x0022: "_CMD_REQUEST_FACE", # FIXME - dup dict key 182 0x0023: "_CMD_TRANSFER", 183 # 0x0026: "_CMD_REQUEST_BEGIN", # FIXME - dup dict key 184} 185 186 187class QQBasicPacket(Packet): 188 __hdr__ = ( 189 ('header_type', 'B', 2), 190 ('source', 'H', 0), 191 ('command', 'H', 0), 192 ('sequence', 'H', 0), 193 ('qqNum', 'L', 0), 194 ) 195 196 197class QQ3Packet(Packet): 198 __hdr__ = ( 199 ('header_type', 'B', 3), 200 ('command', 'B', 0), 201 ('sequence', 'H', 0), 202 ('unknown1', 'L', 0), 203 ('unknown2', 'L', 0), 204 ('unknown3', 'L', 0), 205 ('unknown4', 'L', 0), 206 ('unknown5', 'L', 0), 207 ('unknown6', 'L', 0), 208 ('unknown7', 'L', 0), 209 ('unknown8', 'L', 0), 210 ('unknown9', 'L', 0), 211 ('unknown10', 'B', 1), 212 ('unknown11', 'B', 0), 213 ('unknown12', 'B', 0), 214 ('source', 'H', 0), 215 ('unknown13', 'B', 0), 216 ) 217 218 219class QQ5Packet(Packet): 220 __hdr__ = ( 221 ('header_type', 'B', 5), 222 ('source', 'H', 0), 223 ('unknown', 'H', 0), 224 ('command', 'H', 0), 225 ('sequence', 'H', 0), 226 ('qqNum', 'L', 0), 227 ) 228