#!/usr/bin/env python3
import os, sys
sys.stdout.reconfigure(encoding='utf-8')

ROOT = r'E:\ios\work319\patch_src\Payload\Driver.app'
NEEDLES = [
    'Thiết bị của bạn đang gặp các vấn đề sau',
    'Bạn không thể chạy ứng dụng đã bị đóng gói lại',
    'Thiết bị hiện đang ở chế độ nhà phát triển',
]
# ASCII-ish symbols
SYMS = ['getDetectFlags', 'ShieldData', 'ShieldAPI', 'getShieldCode', 'BannedViewController']

def variants(s):
    return [s.encode('utf-8'), s.encode('utf-16-le')]

hits = {}
for dirpath, dirnames, filenames in os.walk(ROOT):
    for fn in filenames:
        p = os.path.join(dirpath, fn)
        try:
            if os.path.getsize(p) > 400 * 1024 * 1024:
                continue
            data = open(p, 'rb').read()
        except Exception:
            continue
        for s in NEEDLES:
            for enc, blob in zip(('utf8', 'utf16'), variants(s)):
                if blob in data:
                    hits.setdefault(s, []).append((p, enc))
        for s in SYMS:
            if s.encode() in data:
                hits.setdefault(s, []).append((p, 'ascii'))

for s in NEEDLES + SYMS:
    print('==', s)
    for p, enc in hits.get(s, [])[:8]:
        print('   ', enc, p.replace(ROOT, '.'))
