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

SPLIT = Path(__file__).resolve().parent.parent / "extracted" / "native" / "split_config.arm64_v8a.apk"
if not SPLIT.exists():
    native_dir = SPLIT.parent
    candidates = list(native_dir.glob("split_config.arm64*.apk"))
    if not candidates:
        print("missing split APK at", SPLIT, file=sys.stderr)
        print("run: reverse/frida/pull_split_apk.ps1", file=sys.stderr)
        sys.exit(1)
    SPLIT = candidates[0]

OUT = SPLIT.parent
with zipfile.ZipFile(str(SPLIT)) as zf:
    for name in zf.namelist():
        if name.endswith(".so"):
            path = OUT / Path(name).name
            path.write_bytes(zf.read(name))
            print(path.name, path.stat().st_size)
