A high-performance Android storage analyzer that bypasses MTP using a native C++ daemon, a Rust TCP bridge, and a React Treemap UI.
Rust
Preserve matching daemon crash symbols in CI (#61)
Vishnu Srivatsavab866646208bf
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex ba193bf..e436806 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -94,6 +94,7 @@ jobs:NDK="${ANDROID_NDK_LATEST_HOME:-$ANDROID_NDK_HOME}"TOOLCHAIN=$(ls -d "$NDK/toolchains/llvm/prebuilt/"*/ | head -1)CC="${TOOLCHAIN}bin/aarch64-linux-android31-clang++"+ mkdir -p daemon-symbolsecho "NDK: $NDK"echo "Compiler: $CC"@@ -102,8 +103,14 @@ jobs:-std=c++17 -O2 -pthread -Wall -Wextra -Wpedantic \-fno-exceptions -fno-rtti -DNDEBUG \-static-libstdc++ \- -s \- -o src-tauri/bin/daemon engine/daemon.cpp+ -g -Wl,--build-id=sha1 \+ -o daemon-symbols/socketsweep_daemon engine/daemon.cpp++ "${TOOLCHAIN}bin/llvm-strip" --strip-all \+ -o src-tauri/bin/daemon daemon-symbols/socketsweep_daemon+ python3 tests/check_daemon_symbols.py \+ --tools "${TOOLCHAIN}bin" --platform "${{ matrix.platform }}" \+ --commit "$GITHUB_SHA"file src-tauri/bin/daemonecho "✓ C++ daemon cross-compiled for Android aarch64"@@ -115,6 +122,8 @@ jobs:$NDK = $env:ANDROID_NDK_LATEST_HOME$Prebuilt = Get-ChildItem "$NDK\toolchains\llvm\prebuilt" -Directory | Select-Object -First 1$CC = Join-Path $Prebuilt.FullName "bin\aarch64-linux-android31-clang++.cmd"+ $Strip = Join-Path $Prebuilt.FullName "bin\llvm-strip.exe"+ New-Item -ItemType Directory -Path daemon-symbols | Out-NullWrite-Host "NDK: $NDK"Write-Host "Compiler: $CC"@@ -123,11 +132,29 @@ jobs:-std=c++17 -O2 -pthread -Wall -Wextra -Wpedantic `-fno-exceptions -fno-rtti -DNDEBUG `-static-libstdc++ `- -s `- -o src-tauri/bin/daemon engine/daemon.cpp+ -g "-Wl,--build-id=sha1" `+ -o daemon-symbols/socketsweep_daemon engine/daemon.cpp+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }++ & $Strip --strip-all -o src-tauri/bin/daemon daemon-symbols/socketsweep_daemon+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }+ python tests/check_daemon_symbols.py `+ --tools (Join-Path $Prebuilt.FullName "bin") --platform "${{ matrix.platform }}" `+ --commit $env:GITHUB_SHA+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }Write-Host "✓ C++ daemon cross-compiled for Android aarch64"+ # Keep symbols outside Tauri resources. Each host build can use a+ # different NDK; the manifest identifies its exact stripped daemon.+ - name: Upload matching daemon symbols+ uses: actions/upload-artifact@v4+ with:+ name: daemon-symbols-${{ matrix.platform }}-aarch64-${{ github.sha }}-attempt-${{ github.run_attempt }}+ path: daemon-symbols/+ if-no-files-found: error+ retention-days: 90+# ── Download platform-specific ADB from Google ────────────────────────- name: Download ADB (Unix)if: runner.os != 'Windows'diff --git a/README.md b/README.mdindex f494d38..a51d1fb 100644--- a/README.md+++ b/README.md@@ -286,6 +286,9 @@ For the optional, manually run ADB/MTP copy experiment, see[the file-transfer baseline and export plan](docs/file-transfer.md). Regressiontests use offline fixtures and mocked ADB calls; they do not contact a phone.+CI also preserves [matching daemon crash symbols](docs/daemon-symbols.md)+separately from the stripped binary bundled with the app.+The line-based protocol preserves spaces in filenames. Paths containing anewline, carriage return, or null byte are rejected before sending, so theycannot cause a different file to be deleted. Scan responses containing invaliddiff --git a/docs/daemon-symbols.md b/docs/daemon-symbols.mdnew file mode 100644index 0000000..d84b225--- /dev/null+++ b/docs/daemon-symbols.md@@ -0,0 +1,74 @@+# Daemon crash symbols++CI builds an optimized Android ARM64 daemon with debug information, archives the+unstripped executable, and strips a separate copy for Tauri to bundle. Debug+files stay outside `src-tauri/bin`; they are not pushed to the phone by the app.+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>+ socketsweep_daemon+ metadata.json+```++`socketsweep_daemon` is the unstripped executable, named like the on-device+process. `metadata.json` records the workflow commit, host platform, Android+target, workflow run/attempt, shared ELF build ID, SHA-256 and size of both executables, and a real+symbol-lookup smoke check. Host jobs may use different NDK versions; their+symbols are not interchangeable just because their source commit matches.+For pull requests, the workflow commit can be GitHub's test merge commit rather+than the branch head. Use the actual run and manifest.+Reruns keep separate attempt artifacts rather than overwriting earlier symbols.++Artifacts are uploaded immediately after compilation and verification, before+desktop packaging. They are retained for 90 days, subject to repository policy+and run/artifact deletion. They are not attached to releases by this change.+Download and archive the matching artifact before it expires if long-term+support is required. Old binaries cannot acquire matching symbols retroactively+by rebuilding their source with another compiler.++## Match before symbolizing++1. Find the workflow run that produced the installed desktop build and download+ its platform's `daemon-symbols-...` artifact.+2. Match the tombstone's daemon `BuildId` to `metadata.json`'s `build_id`. When+ the exact bundled/collected stripped daemon is available, also compare its+ SHA-256 with `stripped_sha256` and inspect its build ID with the NDK tool:++ ```sh+ /path/to/ndk/toolchains/llvm/prebuilt/<host>/bin/llvm-readelf --notes /path/to/daemon+ ```++3. Use the module-relative hexadecimal `pc` from the daemon's tombstone frame:++ ```sh+ /path/to/ndk/toolchains/llvm/prebuilt/<host>/bin/llvm-symbolizer --obj=/path/to/socketsweep_daemon 0xFRAME_PC+ ```++Replace `FRAME_PC` with the hexadecimal value, not the frame number, an absolute+ASLR address, or a literal placeholder. Windows tools have `.exe` suffixes;+quote paths containing spaces. Repeat for relevant daemon frames. Symbols for+the daemon do not resolve addresses belonging to separate system libraries.++[LLVM documents address-to-source lookup](https://llvm.org/docs/CommandGuide/llvm-symbolizer.html).+Optimized/inlined code can map several frames to one source location or omit+some variables; debug data does not turn an optimized release into a debug build.+If the build ID does not match, report that symbols are unavailable rather than+interpreting output from a different build. Review tombstones for private paths+or other device details before sharing them publicly.++## What CI verifies++`tests/check_daemon_symbols.py` uses the NDK's LLVM tools to require ARM64 ELF+files, identical nonempty build IDs, debug/line/static symbol sections in the+archive, and their absence in the bundled binary. It compares the `.text` bytes+and virtual addresses before/after stripping, then resolves the actual `main`+address to `engine/daemon.cpp` with a nonzero source line. Only after those checks+does it write the artifact manifest. A missing tool or failed check fails CI.++These are host-side ELF checks: they neither run the Android daemon nor require+a crash, ADB, a connected phone, or the desktop app. Local `engine/build.sh`+continues its existing stripped build behavior; its broader build/provisioning+work remains tracked in [#41](https://github.com/VishnuSrivatsava/SocketSweep/issues/41).diff --git a/tests/check_daemon_symbols.py b/tests/check_daemon_symbols.pynew file mode 100644index 0000000..f2dfbe2--- /dev/null+++ b/tests/check_daemon_symbols.py@@ -0,0 +1,74 @@+#!/usr/bin/env python3+"""Verify the real Android ELF/symbol pair and record artifact provenance."""+import argparse+import hashlib+import json+import os+from pathlib import Path+import re+import subprocess+++def check(tools, binary, symbols, commit, platform):+ def run(tool, *args):+ executable = tools / (tool + (".exe" if os.name == "nt" else ""))+ return subprocess.check_output([str(executable), *map(str, args)],+ text=True, encoding="utf-8", errors="replace", timeout=30)++ def require(condition, message):+ if not condition:+ raise ValueError(message)++ require(re.fullmatch(r"[0-9a-f]{40}", commit), "Expected a full commit SHA")+ 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")+ 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))+ require(ids[0] == ids[1], "Stripped daemon and symbols have different build IDs")+ stripped_sections = run("llvm-readelf", "--sections", binary)+ debug_sections = run("llvm-readelf", "--sections", symbols)+ require(".debug_" not in stripped_sections and ".symtab" not in stripped_sections,+ "Bundled daemon still contains debug/static symbol sections")+ require(all(section in debug_sections for section in (".debug_info", ".debug_line", ".symtab")),+ "Archived daemon is missing debug information")+ # Stripping must preserve code bytes and their virtual addresses.+ require(run("llvm-readelf", "--hex-dump=.text", binary) ==+ run("llvm-readelf", "--hex-dump=.text", symbols), "Stripping changed .text")+ main = re.search(r"^([0-9a-fA-F]+) [Tt] main$",+ run("llvm-nm", "--defined-only", symbols), re.MULTILINE)+ require(main is not None, "Missing main symbol")+ address = "0x" + main.group(1)+ 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",+ "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(),+ "symbols_sha256": hashlib.sha256(symbols.read_bytes()).hexdigest(),+ "stripped_bytes": binary.stat().st_size, "symbols_bytes": symbols.stat().st_size,+ "smoke_address": address, "smoke_location": location.strip()}+ (symbols.parent / "metadata.json").write_text(json.dumps(metadata, indent=2) + "\n", encoding="utf-8")+ print(json.dumps(metadata, indent=2))+ return metadata+++def main():+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--tools", type=Path, required=True, help="NDK LLVM bin directory")+ parser.add_argument("--binary", type=Path, default=Path("src-tauri/bin/daemon"))+ 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)+ args = parser.parse_args()+ try:+ check(args.tools, args.binary, args.symbols, args.commit, args.platform)+ except (OSError, ValueError, subprocess.SubprocessError) as error:+ parser.exit(1, f"Daemon symbol verification failed: {error}\n")+++if __name__ == "__main__":+ main()