# -*- coding: utf-8 -*-
import zipfile
from pathlib import Path

APK = Path(__file__).resolve().parent.parent / "apks" / "seabank_ph_base.apk"
needles = [b"IV_Monitor", b"register scene", b"dfp is empty", b"CharacterCrypto"]
with zipfile.ZipFile(str(APK)) as zf:
    data = b"".join(zf.read(n) for n in zf.namelist() if n.endswith(".dex"))
    for n in needles:
        print(n.decode(), data.count(n))
        idx = data.find(n)
        if idx >= 0:
            ctx = data[max(0, idx - 80): idx + 120]
            import re
            for m in re.finditer(rb"Lcom/[^;\x00]{5,120};", ctx):
                print("  class", m.group().decode()[1:-1].replace("/", "."))
