# -*- coding: utf-8 -*-
import re
import zipfile

APK = "reverse/apks/tng/base.apk"
KEYS = [
    b"36616543382169", b"support.tngdigital", b"Rooting", b"How to keep device safe",
    b"showJailBroken", b"openUrl", b"openBrowser", b"launchUrl", b"ACTION_VIEW",
    b"RootI18n", b"SecurityError", b"startChrome", b"IntentDispatcher",
]


def main():
    with zipfile.ZipFile(APK) as zf:
        data = b"".join(zf.read(n) for n in zf.namelist() if n.endswith(".dex"))
    for k in KEYS:
        idx = 0
        while True:
            idx = data.find(k, idx)
            if idx < 0:
                break
            s = max(0, idx - 80)
            e = min(len(data), idx + len(k) + 120)
            chunk = re.sub(rb"[^\x20-\x7e]+", b" ", data[s:e]).decode("ascii", "ignore")
            print(f"[{k.decode()}] {chunk.strip()}")
            idx += 1
    print("\n=== classes with Root/security ===")
    classes = set(re.findall(rb"Lmy/com/tngdigital/common/security[^;]+;", data))
    for c in sorted(classes):
        s = c.decode()[1:-1].replace("/", ".")
        if any(x in s.lower() for x in ["root", "error", "jail", "shield", "promon"]):
            print(s)


if __name__ == "__main__":
    main()
