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

APK = Path(__file__).resolve().parent.parent / "apks" / "maribank_sg_base.apk"
if len(sys.argv) > 1:
    APK = Path(sys.argv[1])

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

for pkg in ("shpssdkbank", "shpssdk"):
    pat = re.compile(rf"Lcom/shopee/{pkg}/[\w$]+;".encode())
    classes = sorted(set(m.group().decode()[1:-1].replace("/", ".") for m in pat.finditer(data)))
    print(f"\n=== {pkg} ({len(classes)} classes) ===")
    short = [c for c in classes if len(c.split(".")[-1]) <= 12 and "shpssdk" in c]
    for c in short[:40]:
        print(" ", c)
