import struct, sys, capstone
sys.stdout.reconfigure(encoding='utf-8')

DRV = r'E:\ios\work319\patch_src\Payload\Driver.app\Driver'
BI  = r'E:\ios\work319\patch_src\Payload\Driver.app\Frameworks\build-info.framework\build-info'

d = open(BI, 'rb').read()
print('build-info bytes @0x4d41c:', d[0x4d41c:0x4d42c].hex())
print('build-info bytes @0x4d454:', d[0x4d454:0x4d45c].hex())

drv = open(DRV, 'rb').read()
ncmds = struct.unpack_from('<I', drv, 16)[0]
off = 32
entry = None
for _ in range(ncmds):
    cmd, sz = struct.unpack_from('<II', drv, off)
    if cmd == 0x80000028:
        entry = struct.unpack_from('<Q', drv, off + 8)[0]
    off += sz
print('LC_MAIN entryoff:', hex(entry) if entry is not None else None)
if entry is not None:
    print('LC_MAIN entry VA:', hex(0x100000000 + entry))

md = capstone.Cs(capstone.CS_ARCH_ARM64, capstone.CS_MODE_ARM)
print('\n=== Driver real main 0x80e0 ===')
for ins in md.disasm(drv[0x80e0:0x8220], 0x80e0):
    tgt = ''
    if ins.mnemonic in ('b', 'bl', 'cbz', 'cbnz', 'tbz', 'tbnz') and ins.op_str:
        try:
            t = int(ins.op_str.split(', ')[-1], 0)
            tgt = '  -> %#x' % (0x100000000 + t)
        except Exception:
            pass
    print('  %#010x  %-8s %-28s%s' % (0x100000000 + ins.address, ins.mnemonic, ins.op_str, tgt))
