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

APK = Path(__file__).resolve().parent.parent / "apks" / "maribank_sg_base.apk"
needles = [b"getDfp empty!", b"getDfp onError:", b"getDfpByMMKV:", b"The dfp is empty in register scene"]

with zipfile.ZipFile(str(APK)) as zf:
    data = b"".join(zf.read(n) for n in zf.namelist() if n.endswith(".dex"))

all_classes = [m.group().decode()[1:-1].replace("/", ".")
               for m in re.finditer(rb"Lcom/shopee/bke/[\w$/]{5,160};", data)]

for needle in needles:
    print("\n===", needle.decode(), "===")
    idx = data.find(needle)
    if idx < 0:
        print("not found")
        continue
    window = data[max(0, idx - 8000) : idx + 8000]
    nearby = sorted(set(m.group().decode()[1:-1].replace("/", ".")
                        for m in re.finditer(rb"Lcom/shopee/bke/[\w$/]{5,160};", window)))
    for c in nearby:
        if any(k in c.lower() for k in ("dfp", "finger", "device", "register", "user", "util", "manager", "helper", "repo", "data", "rn")):
            print(" ", c)

dfp_classes = sorted(set(c for c in all_classes if "dfp" in c.lower() or "fingerprint" in c.lower()))
print("\n=== dfp/fingerprint class names ===")
for c in dfp_classes:
    print(c)
