def packet_handler_0x03_redirect(self, packet): address = packet.read(4) port = packet.read_uint16() packet.read_byte() # remaining seed = packet.read_byte() key = packet.read_string8() name = packet.read_string8() id = packet.read_uint32() self.crypto = Crypto(seed, key, name) address.reverse() address = ".".join([str(octet) for octet in address]) self.disconnect() self.connect(address, port) self.client_ordinal = 0 x10 = ClientPacket(0x10) x10.write_byte(seed) x10.write_string8(key) x10.write_string8(name) x10.write_uint32(id) x10.write_byte(0x00) self.send(x10) if self.server == LoginServer: self.connected_to_login()
def packet_handler_0x3B_ping_a(self, packet): hi_byte = packet.read_byte() lo_byte = packet.read_byte() x45 = ClientPacket(0x45) x45.write_byte(lo_byte) x45.write_byte(hi_byte) self.send(x45)
def log_in(self): print("Logging in as {0}... ".format(self.username)) key_1 = random.randint(0, 0xFF) key_2 = random.randint(0, 0xFF) client_id = random.randint(0, 0xFFFFFFFF) client_id_key = uint8(key_2 + 138) client_id_array = [ client_id & 0x0FF, (client_id >> 8) & 0x0FF, (client_id >> 16) & 0x0FF, (client_id >> 24) & 0x0FF ] hash = NexonCRC16.calculate(client_id_array, 0, 4) client_id_checksum = uint16(hash) client_id_checksum_key = uint8(key_2 + 0x5E) client_id_checksum ^= uint16(client_id_checksum_key | ((client_id_checksum_key + 1) << 8)) client_id ^= uint32(client_id_key | ((client_id_key + 1) << 8) | ((client_id_key + 2) << 16) | ((client_id_key + 3) << 24)) random_val = random.randint(0, 0xFFFF) random_val_key = uint8(key_2 + 115) random_val ^= uint32(random_val_key | ((random_val_key + 1) << 8) | ((random_val_key + 2) << 16) | ((random_val_key + 3) << 24)) x03 = ClientPacket(0x03) x03.write_string8(self.username) x03.write_string8(self.password) x03.write_byte(key_1) x03.write_byte(uint8(key_2 ^ (key_1 + 59))) x03.write_uint32(client_id) x03.write_uint16(client_id_checksum) x03.write_uint32(random_val) crc = NexonCRC16.calculate(x03.data, len(self.username) + len(self.password) + 2, 12) crc_key = uint8(key_2 + 165) crc ^= uint16(crc_key | (crc_key + 1) << 8) x03.write_uint16(crc) x03.write_uint16(0x0100) self.send(x03)
def log_in(self): print("Logging in as {0}... ".format(self.username)) key_1 = random.randint(0, 0xFF) key_2 = random.randint(0, 0xFF) client_id = random.randint(0, 0xFFFFFFFF) client_id_key = uint8(key_2 + 138) client_id_array = [ client_id & 0x0FF, (client_id >> 8) & 0x0FF, (client_id >> 16) & 0x0FF, (client_id >> 24) & 0x0FF] hash = NexonCRC16.calculate(client_id_array, 0, 4) client_id_checksum = uint16(hash) client_id_checksum_key = uint8(key_2 + 0x5E) client_id_checksum ^= uint16(client_id_checksum_key | ((client_id_checksum_key + 1) << 8)) client_id ^= uint32(client_id_key | ((client_id_key + 1) << 8) | ((client_id_key + 2) << 16) | ((client_id_key + 3) << 24)) random_val = random.randint(0, 0xFFFF) random_val_key = uint8(key_2 + 115) random_val ^= uint32(random_val_key | ((random_val_key + 1) << 8) | ((random_val_key + 2) << 16) | ((random_val_key + 3) << 24)) x03 = ClientPacket(0x03) x03.write_string8(self.username) x03.write_string8(self.password) x03.write_byte(key_1) x03.write_byte(uint8(key_2 ^ (key_1 + 59))) x03.write_uint32(client_id) x03.write_uint16(client_id_checksum) x03.write_uint32(random_val) crc = NexonCRC16.calculate(x03.data, len(self.username) + len(self.password) + 2, 12) crc_key = uint8(key_2 + 165) crc ^= uint16(crc_key | (crc_key + 1) << 8) x03.write_uint16(crc) x03.write_uint16(0x0100) self.send(x03)
def packet_handler_0x7E_welcome(self, packet): if self.sent_version: return x62 = ClientPacket(0x62) x62.write_byte(0x34) x62.write_byte(0x00) x62.write_byte(0x0A) x62.write_byte(0x88) x62.write_byte(0x6E) x62.write_byte(0x59) x62.write_byte(0x59) x62.write_byte(0x75) self.send(x62) x00 = ClientPacket(0x00) x00.write_int16(self.da_version) x00.write_byte(0x4C) x00.write_byte(0x4B) x00.write_byte(0x00) self.send(x00) self.sent_version = True