# -*- 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:
    data = b"".join(zf.read(n) for n in zf.namelist() if n.endswith(".dex"))

for pat in [
    b"Does not support",
    b"Turn Off ADB",
    b"Wireless ADB",
    b"ADB/Wireless",
    b"support root",
    b"RISK_USB_ADB",
    b"RISK_WIFI_ADB",
    b"KEY_ALLOW_ADB",
    b"SafeModeRecover",
    b"sg.com.maribank",
]:
    print(pat.decode(), "->", data.count(pat))

print("\n--- UI strings ---")
for m in re.finditer(rb"[\x20-\x7e]{10,200}", data):
    s = m.group().decode("ascii", "ignore")
    sl = s.lower()
    if ("adb" in sl and ("detect" in sl or "turn" in sl or "wireless" in sl or "debug" in sl)) or "does not support root" in sl:
        print(s)

print("\n--- Application ---")
for m in re.finditer(rb"Lcom/shopee/bke/[\w$/]*Application[\w$/]*;", data):
    print(m.group().decode())

print("\n--- ADB risk classes ---")
for m in re.finditer(rb"L[\w$/]*(adb|Adb|ADB)[\w$/]*;", data):
    c = m.group().decode()
    if "shopee" in c.lower() or "bke" in c.lower() or "shps" in c.lower():
        print(c)
