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

APK = Path(__file__).resolve().parent.parent / "apks" / "maribank_sg_base.apk"
needles = [
    b"system is currently unavailable",
    b"currently unavailable",
    b"Unexpected error occurred",
    b"Please try again later",
    b"3100012",
    b"deviceFingerprint",
    b"preCheck",
    b"preRegister",
    b"getDfp",
    b"dfp is empty",
    b"dfpReady",
    b"isDfpReady",
    b"IV_Monitor",
    b"register scene",
    b"GlobalAuthError",
    b"ErrorFlowHelper",
]
with zipfile.ZipFile(str(APK)) as zf:
    data = b"".join(
        zf.read(n)
        for n in zf.namelist()
        if n.endswith((".dex", ".jsbundle", ".json"))
    )
    for n in needles:
        print(n.decode(), data.count(n))
    idx = data.find(b"currently unavailable")
    if idx >= 0:
        print("\ncontext:", data[max(0, idx - 100) : idx + 150])
