#!/usr/bin/env python3
"""Build 44 patch step (on top of build 43 state): NOP the addObject: call at
build-info 0x2910fc so the detectFlags array is born EMPTY (codes blinded at aggregation)."""
import sys

sys.stdout.reconfigure(encoding='utf-8')

BI = r'E:\ios\work319\patch_src\Payload\Driver.app\Frameworks\build-info.framework\build-info'
OFF = 0x2910fc
ORIG = bytes.fromhex('313c1394')   # bl #0x7601c0  ([flagsArray addObject: codeNumber])
NOP = bytes.fromhex('1f2003d5')

b = bytearray(open(BI, 'rb').read())
cur = bytes(b[OFF:OFF + 4])
if cur == NOP:
    print('0x%x already NOP' % OFF)
elif cur != ORIG:
    sys.exit('unexpected bytes at 0x%x: %s' % (OFF, cur.hex()))
else:
    b[OFF:OFF + 4] = NOP
    open(BI, 'wb').write(bytes(b))
    print('0x%x bl addObject: -> NOP' % OFF)

d = open(BI, 'rb').read()
assert d[OFF:OFF + 4] == NOP, 'verify failed'
print('VERIFIED')
