#!/usr/bin/env python3 """Offline check of TS3 3.6.2's authSign challenge derivation (requires unicorn). Run with the path to ts3client_linux_amd64. No account or network is used. Emulates the actual packet-key derivation up to its hash call, replacing only allocation, copying, freeing, and mutex functions. Addresses are version-specific. """ import hashlib import struct import sys from unicorn import Uc, UC_ARCH_X86, UC_MODE_64, UC_HOOK_CODE from unicorn.x86_const import ( UC_X86_REG_RAX, UC_X86_REG_RDI, UC_X86_REG_RSI, UC_X86_REG_RDX, UC_X86_REG_RCX, UC_X86_REG_R8, UC_X86_REG_R9, UC_X86_REG_RSP, UC_X86_REG_RIP, ) def main(path): with open(path, "rb") as binary: data = binary.read() assert data[:6] == b"\x7fELF\x02\x01", "Expected little-endian ELF64" phoff = struct.unpack_from("= 0x1ae0000: raise AssertionError(f"Unexpected external call: {address:x}") uc.hook_add(UC_HOOK_CODE, hook) uc.emu_start(0xff4770, 0x10000, count=100000) assert captured == [bytes.fromhex("300800000000") + shared_iv], captured print("Native hash input matches 30 08 00 00 00 00 || sharedIV") print("Synthetic C:", hashlib.sha256(captured[0]).hexdigest()) if __name__ == "__main__": main(sys.argv[1])