import struct, sys, re
sys.stdout.reconfigure(encoding='utf-8')
p = r'patch_src\Payload\Driver.app\Frameworks\build-info.framework\build-info'
d = open(p, 'rb').read()
n = struct.unpack_from('<I', d, 16)[0]
o = 32
symoff = nsyms = stroff = 0
exp = None
for _ in range(n):
    cmd, sz = struct.unpack_from('<II', d, o)
    if cmd == 0x2:
        symoff, nsyms, stroff = struct.unpack_from('<III', d, o + 8)
    if cmd == 0x80000022:
        info = struct.unpack_from('<10I', d, o + 8)
        exp = (info[8], info[9])
    o += sz


def nm(strx):
    e = d.find(b'\0', stroff + strx)
    return d[stroff + strx:e].decode('latin1', 'replace')


for k in range(nsyms):
    strx, typ, sect, desc, val = struct.unpack_from('<IBBHQ', d, symoff + k * 16)
    s = nm(strx)
    if 'ShieldData' in s or 'ShieldAPI' in s:
        print('%#x typ=%#x sect=%d val=%#x %s' % (symoff + k * 16, typ, sect, val, s))
print('export trie off/size', exp)
if exp:
    eo, es = exp
    seg = d[eo:eo + es]
    for m in re.finditer(rb'[\x20-\x7e]{6,80}', seg):
        s = m.group().decode('latin1')
        if 'Shield' in s:
            print('  trie:', s)
