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

APK = Path(__file__).resolve().parent.parent / "apks" / "seabank_ph_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 needle in [b"riskToken", b"risk_token", b"deviceToken", b"secToken", b"shpsToken", b"mobileNo", b"phoneNo"]:
    print(needle.decode(), data.count(needle))
print("\n--- context riskToken ---")
idx = 0
while True:
    idx = data.find(b"riskToken", idx)
    if idx < 0:
        break
    ctx = data[max(0, idx - 60): idx + 120]
    for m in re.finditer(rb"[\x20-\x7e]{3,60}", ctx):
        s = m.group().decode("latin1")
        if any(k in s.lower() for k in ["risk", "token", "mobile", "phone", "register", "device"]):
            print(" ", s)
    idx += 1
    if idx > 5000000:
        break
