"""Find NativeLib method signatures / loadLibrary name via dex string proximity."""
import re
import zipfile
from pathlib import Path

apk = Path(r"C:\Users\Administrator\Desktop\notiMessage\reverse\apks\tng\base.apk")
with zipfile.ZipFile(apk) as z:
    for name in z.namelist():
        if not name.endswith(".dex"):
            continue
        data = z.read(name)
        if b"NativeLib" not in data and b"native-lib" not in data:
            continue
        print("===", name, "===")
        for pat in [b"NativeLib", b"native-lib", b"getApiSixSecretKeys", b"RetrieveFromNativeLibs", b"Lcom/tngd/networksdk"]:
            for m in re.finditer(pat, data):
                ctx = data[max(0, m.start()-60):m.end()+100]
                ctx = bytes(c if 32 <= c < 127 else 46 for c in ctx)
                print(pat.decode(), "@", m.start(), ":", ctx.decode())
