#!/usr/bin/env python3
# grep_bundle.py - quet toan bo bundle tim manh URL trang chan
import os, sys

ROOT = r"vn.gsm.md_6473405044_3.15.0_DecryptIPA_by_TTJB\Payload"
NEEDLES = [b"b.xanhsm", b"xanhsm.com", b"app_type", b"deviceId", b"code=1", b"?code", b"b-cdn", b"blocked", b"BLOCK"]

hits = {}
for dirpath, _, files in os.walk(ROOT):
    for fn in files:
        p = os.path.join(dirpath, fn)
        try:
            if os.path.getsize(p) > 300 * 1024 * 1024:
                continue
            data = open(p, "rb").read()
        except Exception:
            continue
        for nd in NEEDLES:
            start = 0
            cnt = 0
            while cnt < 6:
                i = data.find(nd, start)
                if i < 0:
                    break
                cnt += 1
                start = i + 1
                key = (os.path.relpath(p, ROOT), nd.decode())
                lo, hi = max(0, i - 60), min(len(data), i + 100)
                ctx = "".join(chr(c) if 32 <= c < 127 else "." for c in data[lo:hi])
                hits.setdefault(key, []).append((i, ctx))

for (rel, nd), lst in sorted(hits.items()):
    print(f"\n[{rel}] '{nd}' x{len(lst)}")
    for off, ctx in lst[:4]:
        print(f"   {off:#010x} | {ctx}")
