#!/usr/bin/env python3 import os import subprocess import sys import zipfile BASE_DIR = "/mnt/16aebe95-f920-450d-b96c-c06bb50ba672/sloproot" APKSIGNER = os.path.join(BASE_DIR, "android-sdk/build-tools/35.0.0/apksigner") AAPT2 = os.path.join(BASE_DIR, "android-sdk/build-tools/35.0.0/aapt2") SLOPROOT_APK = os.path.join(BASE_DIR, "app/build/sloproot.apk") SUMANAGER_APK = os.path.join(BASE_DIR, "sumanager/build/sumanager.apk") def verify_apk(apk_path, min_sdk=8): print(f"Checking {os.path.basename(apk_path)}...") assert os.path.isfile(apk_path), f"APK does not exist: {apk_path}" # Verify signature cmd = [APKSIGNER, "verify", "--verbose", apk_path] res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) assert res.returncode == 0, f"apksigner verify failed:\n{res.stderr}\n{res.stdout}" assert "Verified using v1 scheme (JAR signing): true" in res.stdout assert "Verified using v2 scheme (APK Signature Scheme v2): true" in res.stdout assert "Verified using v3 scheme (APK Signature Scheme v3): true" in res.stdout print(f" PASS: {os.path.basename(apk_path)} verifies with v1, v2, v3") # Check zip contents with zipfile.ZipFile(apk_path, "r") as z: names = z.namelist() assert "AndroidManifest.xml" in names, "Missing AndroidManifest.xml" assert "classes.dex" in names, "Missing classes.dex" assert any(n.endswith("icon.png") for n in names), "Missing icon.png" # Check for proprietary SuperSU remnants for name in names: lower = name.lower() assert "supersu" not in lower, f"Proprietary SuperSU asset found: {name}" assert "libsupol" not in lower, f"Proprietary libsupol asset found: {name}" assert "supolicy" not in lower, f"Proprietary supolicy asset found: {name}" size_kb = os.path.getsize(apk_path) / 1024 print(f" PASS: Size {size_kb:.1f} KB (optimized)") def test_sloproot_assets(): with zipfile.ZipFile(SLOPROOT_APK, "r") as z: names = z.namelist() required_assets = [ "assets/common/sumanager.apk", "assets/common/install.sh", "assets/arm/dirtycow", "assets/arm/payload", "assets/arm/su", "assets/armv6/dirtycow", "assets/armv6/payload", "assets/armv6/su", "assets/armv5/dirtycow", "assets/armv5/payload", "assets/armv5/su", "assets/x86/dirtycow", "assets/x86/payload", "assets/x86/su", "assets/arm64/su", "assets/x86_64/su", ] for asset in required_assets: assert asset in names, f"Required asset missing in sloproot.apk: {asset}" print(" PASS: All required open source assets across ARMv7, ARMv6, ARMv5, x86, ARM64, and x86_64 present in sloproot.apk") def test_sumanager_densities(): with zipfile.ZipFile(SUMANAGER_APK, "r") as z: names = z.namelist() densities = ["ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi"] for d in densities: found = any(f"drawable-{d}" in n and "icon.png" in n for n in names) assert found, f"Density {d} icon missing in sumanager.apk" print(" PASS: All density icon assets present in sumanager.apk") def test_native_su(): ndk_bin = os.path.join(BASE_DIR, "android-sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/linux-x86_64/bin") objdump = os.path.join(ndk_bin, "llvm-objdump") readobj = os.path.join(ndk_bin, "llvm-readobj") architectures = ["arm", "armv6", "armv5", "x86", "arm64", "x86_64"] legacy_dynamic_arches = {"armv5", "armv6"} for arch in architectures: su_bin = os.path.join(BASE_DIR, f"app/assets/{arch}/su") assert os.path.isfile(su_bin), f"su binary missing: {su_bin}" size_kb = os.path.getsize(su_bin) / 1024 assert size_kb < 350, f"su binary too large: {size_kb:.1f} KB" # Check file type res = subprocess.run(["file", su_bin], stdout=subprocess.PIPE, text=True) assert "ELF" in res.stdout, f"Unexpected file output: {res.stdout}" assert "stripped" in res.stdout, f"su is not stripped: {res.stdout}" if arch in legacy_dynamic_arches: # Legacy ARMv5/ARMv6 link dynamically against device bionic to avoid # ARMv7 movw instructions embedded in the NDK static libc. assert "dynamically linked" in res.stdout, f"legacy {arch}/su must link device libc: {res.stdout}" assert "/system/bin/linker" in res.stdout, f"legacy {arch}/su missing Android linker: {res.stdout}" if os.path.isfile(objdump): dis = subprocess.run([objdump, "-d", su_bin], stdout=subprocess.PIPE, text=True, check=True) for bad_insn in ("\tmovw\t", "\tmovt\t", "\tcbz\t", "\tcbnz\t"): assert bad_insn not in dis.stdout, f"ARMv7 instruction {bad_insn.strip()} found in {arch}/su" if os.path.isfile(readobj): syms = subprocess.run([readobj, "--dyn-syms", su_bin], stdout=subprocess.PIPE, text=True, check=True) for bad_sym in ("__FD_SET_chk", "__FD_ISSET_chk", "__aeabi_memclr8@LIBC"): assert bad_sym not in syms.stdout, f"Incompatible bionic symbol {bad_sym} imported in {arch}/su" print(f" PASS: {arch}/su is legacy ARM dynamic ELF ({size_kb:.1f} KB, no ARMv7/fortify)") else: assert "statically linked" in res.stdout, f"su is not statically linked: {res.stdout}" print(f" PASS: {arch}/su is static ELF ({size_kb:.1f} KB)") def test_native_payload(): for arch in ["arm", "armv6", "armv5", "x86"]: payload = os.path.join(BASE_DIR, f"app/assets/{arch}/payload") assert os.path.isfile(payload), f"payload missing: {payload}" size = os.path.getsize(payload) assert size < 32 * 1024, f"{arch}/payload too large for daemon targets: {size}" data = open(payload, "rb").read() assert b"/data/data/org.sloproot/files/trigger.sh" in data, f"{arch}/payload lacks private trigger path" assert b"/sdcard/sloproot/trigger.sh" in data, f"{arch}/payload lacks shared trigger path" # The setuid-helper path still passes -c, so keep that dispatch intact. assert b"-c" in data, f"{arch}/payload lacks -c dispatch" print(f" PASS: {arch}/payload is {size} bytes and has both daemon trigger paths") def test_no_adb_bootstrap_ui(): strings = open(os.path.join(BASE_DIR, "app/res/values/strings.xml"), encoding="utf-8").read() assert "ADB Bootstrap" not in strings, "ADB bootstrap dialog still present" assert "bootstrap" not in strings.lower(), "bootstrap string still present" print(" PASS: No ADB bootstrap UI strings remain") if __name__ == "__main__": verify_apk(SUMANAGER_APK) test_sumanager_densities() verify_apk(SLOPROOT_APK) test_sloproot_assets() test_native_su() test_native_payload() test_no_adb_bootstrap_ui() print("\nAll APK and binary validation tests passed successfully.")