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

APK = Path(__file__).resolve().parent.parent / "apks" / "maribank_sg_base.apk"
needle = b"The dfp is empty in register scene"
with zipfile.ZipFile(str(APK)) as zf:
    data = b"".join(zf.read(n) for n in zf.namelist() if n.endswith(".dex"))

idx = data.find(needle)
ctx = data[max(0, idx - 2000) : idx + 2000]
classes = sorted(set(m.group().decode()[1:-1].replace("/", ".")
                     for m in re.finditer(rb"Lcom/[^;\x00]{5,200};", ctx)))
print("classes near register dfp empty:")
for c in classes:
    print(c)

print("\nstrings:")
for m in re.finditer(rb"[\x20-\x7e]{6,100}", ctx):
    s = m.group().decode()
    if any(k in s.lower() for k in ("dfp", "register", "fingerprint", "empty", "scene", "monitor", "iv_")):
        print(s)
