Commit graph

6 commits

Author SHA1 Message Date
Danila Gornushko
1c3e0a88d1
Close audit findings in clean-device, release, changelog, update-json, codegen (#209)
* fix(scripts): close audit findings in clean-device, release, changelog, update-json

Five tooling fixes from the codebase audit.

- clean-device.sh wiped only three /data/adb dirs and the legacy uids file, so a
  "clean" test left the canonical config, the root-owned APatch superkey under
  /data/adb/vpnhide, and the KPM/ports state behind. Mirror the full
  FULL_RESET_FILES / FULL_RESET_DIRS list from FullReset.kt.
- release.py ran the irreversible changelog rotation (save_json + delete the
  fragment files) BEFORE patching the version-bearing source files, so a drifted
  module.prop / Cargo.toml / gradle format failed mid-release with the changelog
  already mutated and the duplicate-version guard then refusing a retry. Dry-run-
  validate every version-patch regex before the changelog step.
- changelog.py printed the new fragment path relative to cwd, raising ValueError
  when cwd is not an ancestor of changelog.d (e.g. run from scripts/), a spurious
  traceback after the fragment was written fine. Make it relative to REPO_ROOT.
- update-json.sh computed versionCode with bare $(( )), so a zero-padded version
  component (1.08.0) was read as octal and aborted on digit 8/9. Force base-10.
- codegen-hooks.py now uses write_if_changed and reports only what changed, like
  codegen-interfaces.py, instead of rewriting every file and bumping mtimes.

* refactor(scripts): extract scripts/codegen_lib.py shared by both generators

codegen-interfaces.py and codegen-hooks.py each re-derived the same scaffolding:
REPO_ROOT, the "AUTO-GENERATED … Regenerate with …" banner, the verbatim
11-segment path to the LSPosed app's generated Kotlin package, and the
write-if-changed + change-reporting tail of main(). That duplication had already
drifted. Move it into scripts/codegen_lib.py (REPO_ROOT, generated_header,
lsposed_generated_kt, write_if_changed, emit_outputs), imported by both — the
shared-lib pattern scripts/ already uses for changelog_lib.py.

Generated output is byte-identical (verified: re-running both codegen scripts
leaves no diff in any generated file). The escaping helpers stay per-script —
they legitimately differ (C/Rust/Kotlin) and consolidating them risks output
drift for no gain.

* style: ruff format codegen_lib + generators
2026-06-30 11:31:45 +03:00
okhsunrog
f77e8c4fb7 Add per-app native hook selection 2026-06-29 02:25:03 +03:00
okhsunrog
dd2a8038e9 feat(storage): add native config activators 2026-06-28 17:47:45 +03:00
okhsunrog
22d9f62ce0 kpm: speak the control/stats protocol over ctl0
Dispatch the KernelPatch ctl0 supercall on the §4 header kind:
- config  -> vpnhide_parse_config: per-uid hookmask + debug (replaces the
  uid-only target set; each hook now gated by its bit, enabling per-hook
  control). The decimal load-args path stays for headless QEMU bring-up and
  enables the full kernel mask.
- status  -> vpnhide_format_status: backend id, kver, installed-hook mask,
  dominant error (ok / partial_hooks), via out_msg + clamp_to_line.
- stats   -> format wired; per-(uid,hook) counters are a follow-up (TODO).

Add backend ids (kmod/kpm/zygisk/lsposed, protocol §4.3) to the registry so
the status emitter and the app share one source — codegen now renders them
to C/Rust/Kotlin alongside the hook ids and error codes.
2026-06-28 11:53:30 +03:00
okhsunrog
8f5197d2e7 codegen: don't emit the hook registry into lsposed/native
lsposed/native is the uniffi diagnostic-probe library, not a protocol
participant — it consumes iface_lists (VPN-name matching) but never the
hook registry / config masks. Drop it from the hook-ids codegen targets;
the registry goes only to the actual protocol parsers: kmod/KPM (C),
Zygisk (Rust), and the app + system_server hook (Kotlin) per §1.4.
2026-06-28 03:37:16 +03:00
okhsunrog
e85f7cb401 codegen: hook-id registry (protocol §5 single source of truth)
data/hooks.toml is the global hook id space + status error codes shared by
the control/stats protocol: bit N of a config mask == hook id N == the id in
a stats line. scripts/codegen-hooks.py renders the matching id enums,
per-backend 'own' masks, and error codes for every language that touches the
protocol (kmod/KPM C, zygisk Rust, lsposed-native Rust, app Kotlin), so the
numbering can never diverge between backends. Wired into the CI drift-check
beside the iface-list codegen.

The script runs under uv (PEP 723, '#!/usr/bin/env -S uv run' so plain
./scripts/codegen-hooks.py works), matching the repo's other tooling; no
external deps. Generated outputs are rustfmt- and ktlint-clean by
construction. Registry is append-only: ids are permanent so old stats keep
meaning and old readers skip unknown ids.
2026-06-28 02:21:28 +03:00