from lib.packet import Packet import random class EnumQuery: LEAD = 0x00 COMMAND = 0x02 NO_APPLICATION_GUID = 0x02 HAS_APPLICATION_GUID = 0x01 def __init__(self): self.Lead = EnumQuery.LEAD self.Command = EnumQuery.COMMAND self.Payload = random.getrandbits(16) self.Type = None self.ApplicationGUID = None self.ApplicationPayload = None @classmethod def parse(cls, packet: Packet): enumquery = cls() packet.seek(0) enumquery.Lead = packet.get_byte() enumquery.Command = packet.get_byte() enumquery.Payload = packet.get_short() enumquery.Type = packet.get_byte() if enumquery.Type == EnumQuery.HAS_APPLICATION_GUID: enumquery.ApplicationGUID = packet.get_bytes(16) enumquery.ApplicationPayload = packet.read() elif enumquery.Type == EnumQuery.NO_APPLICATION_GUID: enumquery.ApplicationPayload = packet.read() return enumquery def to_packet(self): packet = Packet() packet.put_byte(EnumQuery.LEAD) packet.put_byte(EnumQuery.COMMAND) packet.put_short(self.Payload) if self.ApplicationGUID: packet.put_byte(EnumQuery.HAS_APPLICATION_GUID) packet.put_bytes(self.ApplicationGUID) else: packet.put_byte(EnumQuery.NO_APPLICATION_GUID) if self.ApplicationPayload: packet.put_bytes(self.ApplicationPayload) return packet