import sys
sys.stdout.reconfigure(encoding='utf-8')
import lief
DRV = r'E:\ios\work319\patch_src\Payload\Driver.app\Driver'
b = lief.parse(DRV)
print('dyld_info attrs:', [x for x in dir(b.dyld_info) if not x.startswith('_')])
print('dyld_info:', b.dyld_info)
bs = list(b.bindings)
print('bindings', len(bs))
hits = 0
for e in bs:
    a = getattr(e, 'address', None)
    sym = getattr(e, 'symbol', None)
    nm = getattr(sym, 'name', '') if sym else ''
    if a == 0x101ED0C28 or (a is not None and 0x101ED0C00 <= a <= 0x101ED0C50):
        print('ADDR MATCH', hex(a), nm, getattr(e, 'library', None))
        hits += 1
    if 'abort' in nm.lower():
        print('ABORT SYM', hex(a) if a else None, nm)
        hits += 1
print('hits', hits)
# print last 10 bindings
for e in bs[-10:]:
    print('last', hex(e.address), e.symbol.name if e.symbol else None)
# search symbols table
print('--- symbols containing abort ---')
for s in b.symbols:
    if 'abort' in s.name.lower():
        print(s)
