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

APK = Path(__file__).resolve().parent.parent / "apks" / "maribank_sg_base.apk"
with zipfile.ZipFile(str(APK)) as zf:
    d = b"".join(zf.read(n) for n in zf.namelist() if n.endswith(".dex"))

for needle in [b"CharacterCryptoManager", b"CharacterCryptoManagerWrapper", b"NativeEncryptUtilsWrapper"]:
    print("\n===", needle.decode(), "===")
    for m in re.finditer(re.escape(needle) + rb"[\w$]{0,30}", d):
        name = m.group().decode()
        if "$" in name or name.endswith("Wrapper") or name.endswith("Manager"):
            pass
    for m in re.finditer(rb"Lcom/[^;]{0,200}" + re.escape(needle) + rb"[^;]{0,20};", d):
        print(m.group().decode()[1:-1].replace("/", "."))

# also search for class ending with .d
for m in re.finditer(rb"Lcom/shopee/bke/lib/jni/utils/[a-z];", d):
    print("short utils:", m.group().decode()[1:-1].replace("/", "."))
