Driver Manager v2.0.0 - LSPosed-style rewrite

Complete rewrite with:
- Per-app driver scoping via mount namespace isolation (LSPosed-style)
- System-wide driver mode selection
- .ko kernel module manager with autoload and dependency tracking
- Driver integrity protection (monitor/enforce modes)
- Driver registry with auto-discovery and SHA256 hashing
- LSPosed-style dark WebUI with 6 tabs: Dashboard, Drivers, Apps, Modules, Protection, Logs
- RESTful API handler for WebUI communication
- Zygote process monitor for auto-applying scopes to new app launches

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
sssnake
2026-04-03 06:01:07 -07:00
parent 2c57618987
commit b88141a9c5
16 changed files with 2802 additions and 0 deletions

85
scripts/core.sh Normal file
View File

@@ -0,0 +1,85 @@
#!/system/bin/sh
# Driver Manager v2 - Core Utilities
# Shared functions for all scripts
MODDIR=${MODDIR:-/data/adb/modules/driver-manager}
CONFIGDIR="$MODDIR/config"
LOGDIR="$MODDIR/logs"
RUNDIR="$MODDIR/run"
# --- Logging ---
_LOGFILE=""
log_init() {
_LOGFILE="$1"
mkdir -p "$(dirname "$_LOGFILE")" 2>/dev/null
}
log() {
local msg="[$(date '+%H:%M:%S')] $1"
[ -n "$_LOGFILE" ] && echo "$msg" >> "$_LOGFILE"
}
log_error() { log "ERROR: $1"; }
# --- JSON helpers (minimal, no jq dependency) ---
# Read a string value from a JSON file
json_get() {
local file="$1" key="$2"
grep -o "\"$key\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" "$file" 2>/dev/null | \
head -1 | sed 's/.*:[[:space:]]*"\([^"]*\)"/\1/'
}
# Read a number/bool value from a JSON file
json_get_raw() {
local file="$1" key="$2"
grep -o "\"$key\"[[:space:]]*:[[:space:]]*[^,}]*" "$file" 2>/dev/null | \
head -1 | sed 's/.*:[[:space:]]*//' | tr -d ' '
}
# Set a string value in a JSON file
json_set() {
local file="$1" key="$2" value="$3"
if grep -q "\"$key\"" "$file" 2>/dev/null; then
sed -i "s|\"$key\"[[:space:]]*:[[:space:]]*\"[^\"]*\"|\"$key\": \"$value\"|" "$file"
fi
}
# --- File helpers ---
sha256() {
sha256sum "$1" 2>/dev/null | cut -d' ' -f1
}
get_selinux_context() {
ls -Z "$1" 2>/dev/null | awk '{print $1}'
}
file_size() {
stat -c%s "$1" 2>/dev/null || wc -c < "$1" 2>/dev/null
}
# --- Process helpers ---
pid_of() {
pidof "$1" 2>/dev/null || pgrep -f "$1" 2>/dev/null
}
is_running() {
[ -f "$RUNDIR/$1.pid" ] && kill -0 $(cat "$RUNDIR/$1.pid") 2>/dev/null
}
kill_by_pidfile() {
local pidfile="$RUNDIR/$1.pid"
if [ -f "$pidfile" ]; then
kill $(cat "$pidfile") 2>/dev/null
rm -f "$pidfile"
fi
}
# --- Settings helpers ---
get_setting() {
json_get "$CONFIGDIR/settings.json" "$1"
}
get_setting_raw() {
json_get_raw "$CONFIGDIR/settings.json" "$1"
}