A high-performance Android storage analyzer that bypasses MTP using a native C++ daemon, a Rust TCP bridge, and a React Treemap UI.
Rust
Verify daemon symbols for all Android build ABIs (#146)
Vishnu Srivatsava681ba0dba4e3
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 63ef2ab..852c189 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -94,15 +94,23 @@ jobs:sudo -n env CXX=g++ python3 -m unittest discover -s tests -p test_root_scan.py -vsudo -n env CXX=g++ python3 -m unittest discover -s tests -p test_owned_session.py -v- - name: Cross-compile C++ daemon- run: ${{ runner.os == 'Windows' && 'python' || 'python3' }} engine/build_daemon.py --platform "${{ matrix.platform }}" --commit "${{ github.sha }}"+ - name: Cross-compile C++ daemons+ shell: python {0}+ run: |+ import subprocess+ import sys+ for abi in ("arm64-v8a", "armeabi-v7a", "x86", "x86_64"):+ subprocess.run([+ sys.executable, "engine/build_daemon.py", "--abi", abi,+ "--platform", "${{ matrix.platform }}", "--commit", "${{ github.sha }}",+ ], check=True)# Keep symbols outside Tauri resources. Each host build can use a# different NDK; the manifest identifies its exact stripped daemon.- name: Upload matching daemon symbolsuses: actions/upload-artifact@v4with:- name: daemon-symbols-${{ matrix.platform }}-aarch64-${{ github.sha }}-attempt-${{ github.run_attempt }}+ name: daemon-symbols-${{ matrix.platform }}-android-${{ github.sha }}-attempt-${{ github.run_attempt }}path: daemon-symbols/if-no-files-found: errorretention-days: 90diff --git a/docs/daemon-symbols.md b/docs/daemon-symbols.mdindex feaf3bf..3390374 100644--- a/docs/daemon-symbols.md+++ b/docs/daemon-symbols.md@@ -8,7 +8,7 @@ This addresses [#15](https://github.com/VishnuSrivatsava/SocketSweep/issues/15).Each macOS/Linux/Windows job uploads a separate workflow artifact:```text-daemon-symbols-<platform>-aarch64-<full-workflow-commit-SHA>-attempt-<N>+daemon-symbols-<platform>-android-<full-workflow-commit-SHA>-attempt-<N>socketsweep_daemonmetadata.json```@@ -73,3 +73,11 @@ These are host-side ELF checks: they neither run the Android daemon nor requirea crash, ADB, a connected phone, or the desktop app. Local `engine/build.sh`continues its existing stripped build behavior; its broader build/provisioningwork remains tracked in [#41](https://github.com/VishnuSrivatsava/SocketSweep/issues/41).+++The build entry point also accepts `--abi armeabi-v7a`, `--abi x86`, or+`--abi x86_64` with `--platform` and `--commit`. These experimental builds+write `engine/daemon-<abi>`, with debug files under `daemon-symbols/<abi>/`.+The checker validates the requested ELF class and machine as well as matching+build IDs, code bytes, and source lookup. Verification finishes before publishing+the stripped binary. CI cross-builds and verifies all four ABIs. Desktop installers currently bundle ARM64; the other binaries and their symbols are retained for cross-build validation.diff --git a/engine/build_daemon.py b/engine/build_daemon.pyindex 2ea7e50..d24b179 100644--- a/engine/build_daemon.py+++ b/engine/build_daemon.py@@ -76,8 +76,11 @@ def build(platform, commit, abi):if abi in ("armeabi-v7a", "x86"):args.append("-D_FILE_OFFSET_BITS=64")if platform:- symbols = REPO / "daemon-symbols/socketsweep_daemon"- symbols.parent.mkdir(exist_ok=True)+ symbols_dir = REPO / "daemon-symbols"+ if experimental:+ symbols_dir = symbols_dir / abi+ symbols = symbols_dir / "socketsweep_daemon"+ symbols.parent.mkdir(parents=True, exist_ok=True)subprocess.run([*args, "-g", "-Wl,--build-id=sha1", "-o", str(symbols),str(REPO / "engine/daemon.cpp"),@@ -91,12 +94,13 @@ def build(platform, commit, abi):local_copy = Path(local_stage) / "daemon"shutil.copy2(staged, local_copy)local_copy.replace(local)+ if platform:+ subprocess.run([+ sys.executable, str(REPO / "tests/check_daemon_symbols.py"),+ "--tools", str(compiler.parent), "--platform", platform, "--commit", commit,+ "--abi", abi, "--binary", str(staged), "--symbols", str(symbols),+ ], cwd=REPO, check=True)staged.replace(bundle)- if platform:- subprocess.run([- sys.executable, str(REPO / "tests/check_daemon_symbols.py"),- "--tools", str(compiler.parent), "--platform", platform, "--commit", commit,- ], cwd=REPO, check=True)print(f"[build] Updated {bundle}")@@ -108,8 +112,6 @@ def main():args = parser.parse_args()if bool(args.platform) != bool(args.commit):parser.error("--platform and --commit must be passed together")- if args.platform and args.abi != "arm64-v8a":- parser.error("CI packaging currently supports arm64-v8a only")try:build(args.platform, args.commit, args.abi)except (ValueError, OSError, subprocess.CalledProcessError) as error:diff --git a/tests/check_daemon_symbols.py b/tests/check_daemon_symbols.pyindex f2dfbe2..46683e0 100644--- a/tests/check_daemon_symbols.py+++ b/tests/check_daemon_symbols.py@@ -9,7 +9,15 @@ import reimport subprocess-def check(tools, binary, symbols, commit, platform):+TARGETS = {+ "arm64-v8a": ("ELF64", "AArch64", "aarch64-linux-android31"),+ "armeabi-v7a": ("ELF32", "ARM", "armv7a-linux-androideabi31"),+ "x86": ("ELF32", "Intel 80386", "i686-linux-android31"),+ "x86_64": ("ELF64", "Advanced Micro Devices X86-64", "x86_64-linux-android31"),+}+++def check(tools, binary, symbols, commit, platform, abi="arm64-v8a"):def run(tool, *args):executable = tools / (tool + (".exe" if os.name == "nt" else ""))return subprocess.check_output([str(executable), *map(str, args)],@@ -20,10 +28,13 @@ def check(tools, binary, symbols, commit, platform):raise ValueError(message)require(re.fullmatch(r"[0-9a-f]{40}", commit), "Expected a full commit SHA")+ elf_class, machine, target = TARGETS[abi]ids = []for path in (binary, symbols):header = run("llvm-readelf", "--file-header", path)- require("AArch64" in header and "ELF64" in header, "Expected Android ARM64 ELF")+ require(re.search(rf"^\s*Class:\s+{re.escape(elf_class)}\s*$", header, re.MULTILINE)+ and re.search(rf"^\s*Machine:\s+{re.escape(machine)}\s*$", header, re.MULTILINE),+ f"Expected Android {abi} ELF")match = re.search(r"Build ID: ([0-9a-f]+)", run("llvm-readelf", "--notes", path))require(match is not None, f"Missing build ID: {path}")ids.append(match.group(1))@@ -44,7 +55,7 @@ def check(tools, binary, symbols, commit, platform):location = run("llvm-symbolizer", "--no-inlines", f"--obj={symbols}", address)require("main" in location.splitlines() and re.search(r"daemon\.cpp:[1-9][0-9]*:", location),"Symbol lookup did not resolve main to daemon.cpp")- metadata = {"commit": commit, "platform": platform, "target": "aarch64-linux-android31",+ metadata = {"commit": commit, "platform": platform, "target": target,"workflow_run_id": os.environ.get("GITHUB_RUN_ID"),"workflow_run_attempt": os.environ.get("GITHUB_RUN_ATTEMPT"),"build_id": ids[0], "stripped_sha256": hashlib.sha256(binary.read_bytes()).hexdigest(),@@ -63,9 +74,10 @@ def main():parser.add_argument("--symbols", type=Path, default=Path("daemon-symbols/socketsweep_daemon"))parser.add_argument("--commit", required=True)parser.add_argument("--platform", choices=("linux", "macos", "windows"), required=True)+ parser.add_argument("--abi", choices=TARGETS, default="arm64-v8a")args = parser.parse_args()try:- check(args.tools, args.binary, args.symbols, args.commit, args.platform)+ check(args.tools, args.binary, args.symbols, args.commit, args.platform, args.abi)except (OSError, ValueError, subprocess.SubprocessError) as error:parser.exit(1, f"Daemon symbol verification failed: {error}\n")diff --git a/tests/test_daemon_symbols.py b/tests/test_daemon_symbols.pynew file mode 100644index 0000000..7a3a1ed--- /dev/null+++ b/tests/test_daemon_symbols.py@@ -0,0 +1,54 @@+"""Check ELF architecture validation independently of an installed NDK."""+import contextlib+import io+from pathlib import Path+import tempfile+import unittest+from unittest.mock import patch++import check_daemon_symbols as symbols+++class SymbolArchitectureTests(unittest.TestCase):+ def verify(self, abi, elf_class, machine):+ with tempfile.TemporaryDirectory() as directory:+ root = Path(directory)+ binary = root / "daemon"+ debug = root / "symbols"+ binary.write_bytes(b"stripped")+ debug.write_bytes(b"debug")++ def run(command, **_kwargs):+ tool = Path(command[0]).stem+ if tool == "llvm-nm":+ return "00001000 T main\n"+ if tool == "llvm-symbolizer":+ return "main\n/source/daemon.cpp:123:1\n"+ option = command[1]+ if option == "--file-header":+ return f" Class: {elf_class}\n Machine: {machine}\n"+ if option == "--notes":+ return "Build ID: abcdef\n"+ if option == "--sections":+ return ".debug_info .debug_line .symtab" if command[-1] == str(debug) else ".text"+ if option == "--hex-dump=.text":+ return "same code bytes"+ raise AssertionError(command)++ with patch("check_daemon_symbols.subprocess.check_output", side_effect=run), contextlib.redirect_stdout(io.StringIO()):+ return symbols.check(root, binary, debug, "a" * 40, "linux", abi)++ def test_all_abis_record_the_requested_target(self):+ for abi, (elf_class, machine, target) in symbols.TARGETS.items():+ with self.subTest(abi=abi):+ self.assertEqual(self.verify(abi, elf_class, machine)["target"], target)++ def test_wrong_machine_or_word_size_is_rejected(self):+ for elf_class, machine in [+ ("ELF32", "AArch64"),+ ("ELF64", "ARM"),+ ("ELF64", "AArch64 extra"),+ ]:+ with self.subTest(elf_class=elf_class, machine=machine):+ with self.assertRaisesRegex(ValueError, "Expected Android arm64-v8a ELF"):+ self.verify("arm64-v8a", elf_class, machine)