#!/usr/bin/env python3
"""bundle_scan.py - stream-scan an IPA for byte keywords across all entries."""
import zipfile, sys

IPA = r'E:\ios\CC71167C-32C1-4D99-9F03-A8A22769970E-Driver_3.19.0.ipa'
KW = [
    b'simulatelocation', b'com.apple.dt', b'CoreLocation', b'isSimulatingLocation',
    b'setLocation', b'LocationSimulat', b'locationServicesEnabled', b'isFromMockProvider',
    b'mockLocation', b'fakeLocation', b'virtualLocation', b'GPX', b'idevicesetlocation',
    b'isSimulator', b'DeveloperMode', b'developer_mode', b'getDetectFlags',
    b'high_risk', b'repack', b'tamper', b'ptrace', b'P_TRACED',
]

def main():
    z = zipfile.ZipFile(IPA)
    for n in z.namelist():
        if n.endswith('/'):
            continue
        try:
            info = z.getinfo(n)
            if info.file_size > 200 * 1024 * 1024:
                continue
            data = z.read(n)
        except Exception:
            continue
        hits = []
        for kw in KW:
            c = data.count(kw)
            if c:
                hits.append('%s x%d' % (kw.decode('utf-8', 'replace'), c))
        if hits:
            print(n, '|', ', '.join(hits))

if __name__ == '__main__':
    main()
