# -*- coding: utf-8 -*-
import struct, os

for path in (r'E:\ios\zsign-windows-x64\vn.gsm.md_6473405044_3.15.0_DecryptIPA_by_TTJB\Payload\Driver.app\Driver',
             r'E:\ios\dump_tool\out\Payload\Driver.app\Driver'):
    with open(path, 'rb') as f:
        d = f.read(1 << 20)
    print(os.path.basename(os.path.dirname(path)), 'magic:', d[:4].hex())
    if d[:4] in (b'\xca\xfe\xba\xbe', b'\xbe\xba\xfe\xca'):
        big = d[:4] == b'\xca\xfe\xba\xbe'
        fmt = '>I' if big else '<I'
        n = struct.unpack_from(fmt + 'I', d, 4)[0]
        print('  FAT narch=%d' % n)
        for a in range(n):
            cpu, _sub, off, size, _align = struct.unpack_from(fmt + 'IIIII', d, 8 + a * 20)
            print('   arch cpu=0x%x off=%d size=%d' % (cpu, off, size))
        continue
    ncmds = struct.unpack_from('<I', d, 16)[0]
    pos = 32
    for _ in range(ncmds):
        cmd, sz = struct.unpack_from('<II', d, pos)
        if cmd in (0x2C, 0x8000002C):
            print('  LC_ENCRYPTION_INFO%s at %d:' % ('_64' if cmd == 0x8000002C else '', pos), struct.unpack_from('<III', d, pos + 8))
        pos += sz
        if pos > len(d):
            break
