"""Build an unsigned, logging-only diagnostic APK for the exact Quest Unity binary. Preserves certificate decisions. Adds Android log probes after native X509 verification and after the Unity verification callback. Never edits the input. Run zipalign and sign with the installed test application's key afterward. """ import argparse import hashlib import struct import zipfile from pathlib import Path EXPECTED = 'd68dd33530dc9c6f963da17cad03d56fbaF51ac4bef297d05bf56684a44ee607'.lower() CAVE = 0x125AE00 LIMIT = 0x125B100 LOG_PRINT = 0xBA9F0 def word(v): return struct.pack('> 2) & 0x3FFFFFF)) def adr(pc, target, reg): delta = target - pc assert -(1 << 20) <= delta < (1 << 20) return word(0x10000000 | ((delta & 3) << 29) | (((delta >> 2) & 0x7FFFF) << 5) | reg) def mov(dst, src, wide=True): return word((0xAA0003E0 if wide else 0x2A0003E0) | (src << 16) | dst) def pair(a, b, offset, load=False): return word((0xA9400000 if load else 0xA9000000) | ((offset // 8) << 15) | (b << 10) | (31 << 5) | a) def patch(binary, radicade_system_trust=False): assert hashlib.sha256(binary).hexdigest() == EXPECTED, 'Unknown Unity binary' out = bytearray(binary) assert not any(out[CAVE:LIMIT]), 'Diagnostic space is occupied' # Existing RX PT_LOAD ends before alignment padding; extend only into that # verified empty padding, staying before the following RW PT_LOAD file range. ph = struct.unpack_from('