def encode_delete_message( seq: int, session_id: bytes, uin: int, d2key: bytes, items: List[PbDeleteMsgReq.MsgItem], ) -> Packet: """Build delete message packet. Called in ``com.tencent.mobileqq.app.MessageHandler.a``. command name: ``MessageSvc.PbDeleteMsg`` Note: Source: com.tencent.mobileqq.app.MessageHandler.a Args: seq (int): Packet sequence. session_id (bytes): Session ID. uin (int): User QQ number. d2key (bytes): Siginfo d2 key. items (List[PbDeleteMsgReq.MsgItem]): List of message items. Returns: Packet: PbDeleteMsg packet. """ COMMAND_NAME = "MessageSvc.PbDeleteMsg" payload = PbDeleteMsgReq(msg_items=items).SerializeToString() packet = UniPacket.build(uin, seq, COMMAND_NAME, session_id, 1, payload, d2key) return packet
def encode_get_message( seq: int, session_id: bytes, uin: int, d2key: bytes, request_type: int, sync_flag: Union[int, SyncFlag] = SyncFlag.START, sync_cookie: Optional[bytes] = None, online_sync_flag: int = 0, pubaccount_cookie: Optional[bytes] = None, server_buf: Optional[bytes] = None, ) -> Packet: """Build get message packet. Called in ``com.tencent.mobileqq.app.MessageHandler.a``. command name: ``MessageSvc.PbGetMsg`` Note: Source: com.tencent.mobileqq.app.MessageHandler.a Args: seq (int): Packet sequence. session_id (bytes): Session ID. uin (int): User QQ number. d2key (bytes): Siginfo d2 key. request_type (int): Request type. sync_flag (Union[int, SyncFlag], optional): Sync flag. Defaults to :obj:`SyncFlag.START`. sync_cookie (Optional[bytes], optional): Sync cookie. Defaults to None. online_sync_flag (int, optional): Online sync flag. Defaults to 0. pubaccount_cookie (Optional[bytes], optional): Pubaccount cookie. Defaults to None. server_buf (Optional[bytes], optional): Server buf from ``PushNotify``. Defaults to None. Returns: Packet: PbGetMsg packet. """ COMMAND_NAME = "MessageSvc.PbGetMsg" payload = PbGetMsgReq( sync_flag=sync_flag, sync_cookie=sync_cookie, ramble_flag=0, latest_ramble_number=20, other_ramble_number=3, online_sync_flag=online_sync_flag, context_flag=1, req_type=request_type, pubaccount_cookie=pubaccount_cookie, server_buf=server_buf, ).SerializeToString() packet = UniPacket.build(uin, seq, COMMAND_NAME, session_id, 1, payload, d2key) return packet
def encode_set_status( seq: int, session_id: bytes, uin: int, d2key: bytes, status: Union[int, OnlineStatus], battery_status: Optional[int] = None, is_power_connected: bool = False, ) -> Packet: """Build status service register packet. Called in ``com.tencent.mobileqq.msf.core.push.e.a``. command name: ``StatSvc.SetStatusFromClient`` Note: Source: com.tencent.mobileqq.msf.core.push.e.a Args: seq (int): Packet sequence. session_id (bytes): Session ID. uin (int): User QQ number. d2key (bytes): Siginfo d2 key. status (Union[int, OnlineStatus]): Online status. reg_push_reason (Union[str, RegPushReason]): Reg push reason. battery_status (Optional[int], optional): Battery capacity. Only works when status is :obj:`.OnlineStatus.Battery`. Defaults to None. is_power_connected (bool, optional): Is power connected to phone. Only works when status is :obj:`.OnlineStatus.Battery`. Defaults to False. Returns: Packet: Register packet. """ COMMAND_NAME = "StatSvc.SetStatusFromClient" SUB_APP_ID = APK_INFO.sub_app_id svc = _encode_svc_request( uin, status, RegPushReason.SetOnlineStatus, ((status == OnlineStatus.Battery) or None) and battery_status, (status == OnlineStatus.Battery) and is_power_connected, ) payload = SvcReqRegister.to_bytes(0, svc) req_packet = RequestPacketVersion3( servant_name="PushService", func_name="SvcReqRegister", data=types.MAP({types.STRING("SvcReqRegister"): types.BYTES(payload)}), ).encode() packet = UniPacket.build( uin, seq, COMMAND_NAME, session_id, 1, req_packet, d2key ) return packet
def encode_get_troop_member_list( seq: int, session_id: bytes, uin: int, d2key: bytes, group_uin: int, group_code: int, next_uin: int = 0, ) -> Packet: """Build get troop member list packet. Called in ``com.tencent.mobileqq.troop.handler.TroopMemberInfoHandler.a``. command name: ``friendlist.GetTroopMemberListReq`` Note: Source: com.tencent.mobileqq.service.troop.TroopSender.c Args: seq (int): Packet sequence. session_id (bytes): Session ID. uin (int): User QQ number. d2key (bytes): Siginfo d2 key. group_uin (int): Group uin number. group_code (int): Group code number. next_uin (int, optional): Next uin number. Defaults to 0. Returns: Packet: getTroopMemberList simplified packet. """ COMMAND_NAME = "friendlist.GetTroopMemberListReq" req = TroopMemberListReq( uin=uin, group_code=group_code, next_uin=next_uin, group_uin=group_uin, version=3, ) payload = TroopMemberListReq.to_bytes(0, req) req_packet = RequestPacketVersion3( servant_name="mqq.IMService.FriendListServiceServantObj", func_name="GetTroopMemberListReq", data=types.MAP({types.STRING("GTML"): types.BYTES(payload)}), ).encode() packet = UniPacket.build(uin, seq, COMMAND_NAME, session_id, 1, req_packet, d2key) return packet
def encode_get_troop_list( seq: int, session_id: bytes, uin: int, d2key: bytes, cookies: Optional[bytes] = None, ) -> Packet: """Build get troop list v2 simplified packet. Called in ``com.tencent.mobileqq.troop.handler.TroopListHandler.a``. command name: ``friendlist.GetTroopListReqV2`` Note: Source: com.tencent.mobileqq.service.troop.TroopSender.b Args: seq (int): Packet sequence. session_id (bytes): Session ID. uin (int): User QQ number. d2key (bytes): Siginfo d2 key. cookies (Optional[bytes], optional): Cookie vector. Defaults to None. Returns: Packet: GetTroopListReqV2 simplified packet. """ COMMAND_NAME = "friendlist.GetTroopListReqV2" req = TroopListReqV2Simplify( uin=uin, get_msf_msg_flag=False, cookies=cookies, group_flag_ext=bytes([1]), version=9, version_num=1, get_long_group_name=True, ) payload = TroopListReqV2Simplify.to_bytes(0, req) req_packet = RequestPacketVersion3( servant_name="mqq.IMService.FriendListServiceServantObj", func_name="GetTroopListReqV2Simplify", data=types.MAP( {types.STRING("GetTroopListReqV2Simplify"): types.BYTES(payload)}), ).encode() packet = UniPacket.build(uin, seq, COMMAND_NAME, session_id, 1, req_packet, d2key) return packet
def encode_config_push_response( uin: int, seq: int, session_id: bytes, d2key: bytes, type: int, jcebuf: bytes, large_seq: int, ) -> Packet: """Build config push response packet. command name: ``ConfigPushSvc.PushResp`` Note: Source: com.tencent.mobileqq.msf.core.a.c.b Args: uin (int): User QQ number. seq (int): Packet sequence. session_id (bytes): Session ID. d2key (bytes): Siginfo d2 key. type (int): ConfigPushSvc request type. jcebuf (bytes): ConfigPushSvc request jcebuf. large_seq (int): ConfigPushSvc request large_seq. """ COMMAND_NAME = "ConfigPushSvc.PushResp" resp = PushResp(type=type, jcebuf=jcebuf if type == 3 else None, large_seq=large_seq) payload = PushResp.to_bytes(0, resp) resp_packet = RequestPacketVersion3( servant_name="QQService.ConfigPushSvc.MainServant", func_name="PushResp", data=types.MAP({types.STRING("PushResp"): types.BYTES(payload)}), ).encode() packet = UniPacket.build(uin, seq, COMMAND_NAME, session_id, 1, resp_packet, d2key) return packet
def encode_get_friend_list( seq: int, session_id: bytes, uin: int, d2key: bytes, friend_index: int = 0, friend_count: int = 0, group_index: int = 0, group_count: int = 0, ) -> Packet: """Build get friend list packet. Called in ``com.tencent.mobileqq.service.friendlist.FriendListService.k``. command name: ``friendlist.GetFriendListReq`` Note: Source: com.tencent.mobileqq.service.friendlist.FriendListService.m Args: seq (int): Packet sequence. session_id (bytes): Session ID. uin (int): User QQ number. d2key (bytes): Siginfo d2 key. friend_index (int): Start index of friend list. friend_count (int): Number of friends to list. group_index (int): Start index of group list. group_count (int): Number of groups to list. Returns: Packet: GetFriendListReq packet. """ COMMAND_NAME = "friendlist.GetFriendListReq" req = FriendListReq( request_type=3, if_reflush=friend_index <= 0, uin=uin, start_index=friend_index, friend_count=friend_count, group_id=bytes(1), if_get_group_info=group_count > 0, group_start_index=group_index, group_count=group_count, if_get_msf_group=False, if_show_term_type=True, version=31, d50_req=ReqBody( appid=1002, req_music_switch=1, req_mutualmark_alienation=1, req_ksing_switch=1, req_mutualmark_lbsshare=1, req_aio_quick_app=1, ).SerializeToString(), sns_type_list=[13580, 13581, 13582], ) payload = FriendListReq.to_bytes(0, req) req_packet = RequestPacketVersion3( servant_name="mqq.IMService.FriendListServiceServantObj", func_name="GetFriendListReq", data=types.MAP({types.STRING("FL"): types.BYTES(payload)}), ).encode() packet = UniPacket.build(uin, seq, COMMAND_NAME, session_id, 1, req_packet, d2key) return packet
def encode_exchange_emp_15( seq: int, session_id: bytes, uin: int, g: bytes, dpwd: bytes, no_pic_sig: bytes, encrypted_a1: bytes, rand_seed: bytes, wt_session_ticket: bytes, wt_session_ticket_key: bytes, ) -> Packet: """Build exchange emp request packet. command id: ``0x810 = 2064`` sub command id: ``15`` command name: ``wtlogin.exchange_emp`` Note: Source: oicq.wlogin_sdk.request.aa Args: seq (int): Packet sequence. session_id (bytes): Session ID. ksid (bytes): KSID of client. uin (int): User QQ number. g (bytes): Siginfo g. dpwd (bytes): Siginfo dpwd. no_pic_sig (bytes): Siginfo no pic sig. encrypted_a1 (bytes): Siginfo Encrypted A1. rand_seed (bytes): Siginfo random seed. wt_session_ticket (bytes): Siginfo session ticket. wt_session_ticket_key (bytes): Siginfo session ticket key. Returns: Packet: Exchange emp packet. """ COMMAND_ID = 2064 SUB_COMMAND_ID = 15 COMMAND_NAME = "wtlogin.exchange_emp" APK_ID = APK_INFO.apk_id APK_VERSION = APK_INFO.version APK_SIGN = APK_INFO.apk_sign APK_BUILD_TIME = APK_INFO.build_time APP_ID = APK_INFO.app_id SUB_APP_ID = APK_INFO.sub_app_id APP_CLIENT_VERSION = 0 SDK_VERSION = APK_INFO.sdk_version SSO_VERSION = APK_INFO.sso_version BITMAP = APK_INFO.bitmap MAIN_SIGMAP = APK_INFO.main_sigmap SUB_SIGMAP = APK_INFO.sub_sigmap GUID = DEVICE.guid GUID_SRC = 1 GUID_CHANGE = 0 GUID_FLAG = 0 GUID_FLAG |= GUID_SRC << 24 & 0xFF000000 GUID_FLAG |= GUID_CHANGE << 8 & 0xFF00 LOCAL_ID = 2052 # oicq.wlogin_sdk.request.t.v IP_BYTES: bytes = ipaddress.ip_address(DEVICE.ip_address).packed NETWORK_TYPE = (DEVICE.apn == "wifi") + 1 data = Packet.build( struct.pack(">HH", SUB_COMMAND_ID, 24), TlvEncoder.t18(APP_ID, APP_CLIENT_VERSION, uin), TlvEncoder.t1(uin, int(time.time()), IP_BYTES), TlvEncoder._pack_tlv(0x106, encrypted_a1), TlvEncoder.t116(BITMAP, SUB_SIGMAP), TlvEncoder.t100(SSO_VERSION, APP_ID, SUB_APP_ID, APP_CLIENT_VERSION, MAIN_SIGMAP), TlvEncoder.t107(), # TlvEncoder.t108(KSID), # null when first time login TlvEncoder.t144( DEVICE.imei.encode(), DEVICE.bootloader, DEVICE.proc_version, DEVICE.version.codename, DEVICE.version.incremental, DEVICE.fingerprint, DEVICE.boot_id, DEVICE.android_id, DEVICE.baseband, DEVICE.version.incremental, DEVICE.os_type.encode(), DEVICE.version.release.encode(), NETWORK_TYPE, DEVICE.sim.encode(), DEVICE.apn.encode(), False, True, False, GUID_FLAG, DEVICE.model.encode(), DEVICE.guid, DEVICE.brand.encode(), DEVICE.tgtgt, ), TlvEncoder.t142(APK_ID), # TlvEncoder.t112(), TlvEncoder.t145(DEVICE.guid), # TlvEncoder.t166(1), TlvEncoder.t16a(no_pic_sig), TlvEncoder.t154(seq), TlvEncoder.t141(DEVICE.sim.encode(), NETWORK_TYPE, DEVICE.apn.encode()), TlvEncoder.t8(LOCAL_ID), TlvEncoder.t511([ "tenpay.com", "openmobile.qq.com", "docs.qq.com", "connect.qq.com", "qzone.qq.com", "vip.qq.com", "gamecenter.qq.com", "qun.qq.com", "game.qq.com", "qqweb.qq.com", "office.qq.com", "ti.qq.com", "mail.qq.com", "mma.qq.com", ]), # com.tencent.mobileqq.msf.core.auth.l TlvEncoder.t147(APP_ID, APK_VERSION.encode(), APK_SIGN), # TlvEncoder.t172(), TlvEncoder.t177(APK_BUILD_TIME, SDK_VERSION), TlvEncoder.t400(g, uin, GUID, dpwd, 1, APP_ID, rand_seed), TlvEncoder.t187(DEVICE.mac_address.encode()), TlvEncoder.t188(DEVICE.android_id.encode()), TlvEncoder.t194(DEVICE.imsi_md5) if DEVICE.imsi_md5 else b"", # TlvEncoder.t201(), TlvEncoder.t202(DEVICE.wifi_bssid.encode(), DEVICE.wifi_ssid.encode()), TlvEncoder.t516(), TlvEncoder.t521(), TlvEncoder.t525(TlvEncoder.t536([])), ) session = EncryptSession(wt_session_ticket) oicq_packet = OICQRequest.build_encoded( uin, COMMAND_ID, session.encrypt(data, wt_session_ticket_key), session.id, ) packet = UniPacket.build(uin, seq, COMMAND_NAME, session_id, 2, oicq_packet, key=bytes(16)) return packet