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_0x00_encryption(self, packet): code = packet.read_byte() if code == 1: self.da_version -= 1 print("Invalid DA version, possibly too high. " "Trying again with {0}.".format(self.da_version)) self.reconnect() return elif code == 2: version = packet.read_int16() packet.read_byte() packet.read_string8() # patch url self.da_version = version print("Your DA version is too low. " "Setting DA version to {0}.".format(version)) self.reconnect() return packet.read_uint32() # server table crc seed = packet.read_byte() key = packet.read_string8() self.crypto = Crypto(seed, key) x57 = ClientPacket(0x57) x57.write_uint32(0) self.send(x57)
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)