From 9a3e88ace0b207c54dae087f222da6dccf2cc1d2 Mon Sep 17 00:00:00 2001 From: ClozyA <133191303+ClozyA@users.noreply.github.com> Date: Mon, 30 Nov 2026 12:06:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20KernelSU=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=8A=B6=E6=80=81=E5=92=8C=E5=BD=BB=E5=BA=95=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E6=AE=8B=E7=95=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs ModAVD/ModAVD#322 Refs ModAVD/ModAVD#323 --- .../322-kernelsu-module-verification.fix.md | 2 + .../323-kernelsu-purge-metamodule.fix.md | 2 + internal/cli/kernelsu.go | 28 ++++- internal/components/kernelsu.go | 89 ++++++++++----- internal/components/kernelsu_download.go | 10 +- internal/components/kernelsu_test.go | 29 ++++- internal/emu/kernelsu.go | 102 ++++++++++++++++-- internal/emu/kernelsu_test.go | 10 +- internal/i18n/locales/en/cli.json | 9 +- internal/i18n/locales/en/components.json | 3 +- internal/i18n/locales/en/emu.json | 3 +- internal/i18n/locales/en/report.json | 3 +- internal/i18n/locales/en/web.json | 9 +- internal/report/collect.go | 5 + internal/report/report_test.go | 33 ++++++ internal/ui/API.en.md | 1 + internal/ui/API.md | 1 + internal/ui/web/js/actions.js | 4 +- internal/ui/web/js/diagnostics.js | 9 +- internal/ui/web/js/format.js | 7 +- scripts/test_kernelsu_ui.mjs | 11 ++ 21 files changed, 309 insertions(+), 61 deletions(-) create mode 100644 changelog.d/322-kernelsu-module-verification.fix.md create mode 100644 changelog.d/323-kernelsu-purge-metamodule.fix.md diff --git a/changelog.d/322-kernelsu-module-verification.fix.md b/changelog.d/322-kernelsu-module-verification.fix.md new file mode 100644 index 00000000..734d4218 --- /dev/null +++ b/changelog.d/322-kernelsu-module-verification.fix.md @@ -0,0 +1,2 @@ +KernelSU 组件状态现在会显示模块是否匹配正式发布的校验值 +KernelSU component status now shows whether the module matches the official release checksum. diff --git a/changelog.d/323-kernelsu-purge-metamodule.fix.md b/changelog.d/323-kernelsu-purge-metamodule.fix.md new file mode 100644 index 00000000..c6a383ba --- /dev/null +++ b/changelog.d/323-kernelsu-purge-metamodule.fix.md @@ -0,0 +1,2 @@ +彻底移除 KernelSU 时会清理 ModAVD 安装的 meta-overlayfs 残留 +Purging KernelSU now cleans up meta-overlayfs files installed by ModAVD. diff --git a/internal/cli/kernelsu.go b/internal/cli/kernelsu.go index 896eab79..9111b1fe 100644 --- a/internal/cli/kernelsu.go +++ b/internal/cli/kernelsu.go @@ -59,9 +59,21 @@ func kernelSUStateLine(s components.KernelSUStatus) string { line += " " + s.Version } if s.KernelVersion != "" { - line += "(内核 " + s.KernelVersion + ",可选,导入的)" + line += fmt.Sprintf("(内核 %s,可选)", s.KernelVersion) } else { - line += "(可选,导入的)" + line += "(可选)" + } + switch s.Source { + case components.KernelSUFromDownload: + line += ",下载的" + case components.KernelSUFromImport: + line += ",导入的" + } + switch s.LKMVerification { + case components.KernelSUVerifiedOfficial: + line += ",模块匹配正式发布的校验值" + case components.KernelSUVerifiedTrusted: + line += ",模块仅按本地记录的校验值核对" } return line } @@ -86,10 +98,18 @@ func kernelSUStateLine(s components.KernelSUStatus) string { func formatImportKernelSU(w io.Writer, r *components.KernelSUImportResult) { if r.Skipped { - fmt.Fprintln(w, "KernelSU 的五个文件已经齐全、校验无误,没有改动(给的文件也核对过了)") + if r.From == components.KernelSUFromDownload { + fmt.Fprintln(w, "KernelSU 的正式组件已齐全,无需下载") + } else { + fmt.Fprintln(w, "KernelSU 的五个文件已经齐全、校验无误,没有改动(给的文件也核对过了)") + } return } - fmt.Fprintf(w, "已导入 KernelSU 组件:%s\n", r.Status.Dir) + if r.From == components.KernelSUFromDownload { + fmt.Fprintf(w, "已下载并校验 KernelSU 组件:%s\n", r.Status.Dir) + } else { + fmt.Fprintf(w, "已导入 KernelSU 组件:%s\n", r.Status.Dir) + } if r.Status.LKMVerMagic != "" { fmt.Fprintf(w, " 内核模块 vermagic:%s\n", r.Status.LKMVerMagic) } diff --git a/internal/components/kernelsu.go b/internal/components/kernelsu.go index 378e7eb3..fe7c4cba 100644 --- a/internal/components/kernelsu.go +++ b/internal/components/kernelsu.go @@ -17,6 +17,14 @@ import ( "modavd/internal/root" ) +// Origin and verification describe independent attributes of the installed LKM. +const ( + KernelSUFromDownload = "download" + KernelSUFromImport = "import" + KernelSUVerifiedOfficial = "official" + KernelSUVerifiedTrusted = "trusted" +) + const ( kernelSUSourceKey = "ModAVD.Source" kernelSUKernelVersionKey = "ModAVD.KernelVersion" @@ -42,10 +50,12 @@ type KernelSUFile struct { type KernelSUStatus struct { Dir string `json:"dir"` Ready bool `json:"ready"` - Source string `json:"source"` + Source string `json:"source"` // kernel module acquisition, when recorded Version string `json:"version"` KernelVersion string `json:"kernel_version"` LKMVerMagic string `json:"lkm_vermagic,omitempty"` + LKMSHA256 string `json:"lkm_sha256,omitempty"` + LKMVerification string `json:"lkm_verification,omitempty"` Files []KernelSUFile `json:"files"` DownloadAvailable bool `json:"download_available"` InstallSupported bool `json:"install_supported"` @@ -54,6 +64,7 @@ type KernelSUStatus struct { // KernelSUImportResult is the result of ImportKernelSU (`components import-ksu`). type KernelSUImportResult struct { Root string `json:"root"` + From string `json:"from"` Used []string `json:"used"` Kept []string `json:"kept"` Skipped bool `json:"skipped"` @@ -64,22 +75,32 @@ type KernelSUImportResult struct { // ExpectedKernelVersion reads the system image's kernel-ranchu release release // from r's RuntimeSDK, falling back to the profile default when the system image is not present yet. func ExpectedKernelVersion(r *root.Root) string { - profile := kernelSUProfile() + fallback := kernelSUProfile().KernelRelease if r == nil { - return profile.KernelRelease + return fallback } - kernelPath := filepath.Join(r.RuntimeSDK(), root.SystemImageDir, "kernel-ranchu") + return kernelSUExpectedVersion(r.RuntimeSDK(), fallback) +} + +func kernelSUExpectedVersion(sdk, fallback string) string { + kernelPath := filepath.Join(sdk, root.SystemImageDir, "kernel-ranchu") if release, _, err := kernelsu.ReadKernelRelease(kernelPath); err == nil && release != "" { return release } - return profile.KernelRelease + return fallback } // KernelSUState reads r's KernelSU component files (in the SDK the instances run on). func KernelSUState(r *root.Root) KernelSUStatus { + return KernelSUStateForSDK(r.RuntimeSDK()) +} + +// KernelSUStateForSDK reads the optional component from the SDK selected for use. +func KernelSUStateForSDK(sdk string) KernelSUStatus { profile := kernelSUProfile() - dir := filepath.Join(r.RuntimeSDK(), root.KernelSUDir) - wantKernel := ExpectedKernelVersion(r) + dir := filepath.Join(sdk, root.KernelSUDir) + wantKernel := kernelSUExpectedVersion(sdk, profile.KernelRelease) + props := kernelSUProperties(dir) st := KernelSUStatus{ Dir: dir, KernelVersion: wantKernel, @@ -98,9 +119,18 @@ func KernelSUState(r *root.Root) KernelSUStatus { size = fi.Size() if fi.Size() <= maxKernelSULKMBytes { if data, rerr := os.ReadFile(p); rerr == nil { - if vm, verr := validateKernelSULKM(data, wantKernel, f, storedLKMDigest(dir)); verr == nil { + trusted := props[kernelSULKMSHA256Key] + if vm, verr := validateKernelSULKM(data, wantKernel, f, trusted); verr == nil { present = true st.LKMVerMagic = vm + if trusted == "" { + trusted = f.SHA256 + } + st.LKMSHA256 = strings.ToLower(trusted) + st.LKMVerification = KernelSUVerifiedTrusted + if int64(len(data)) == f.Size && strings.EqualFold(st.LKMSHA256, f.SHA256) { + st.LKMVerification = KernelSUVerifiedOfficial + } } } } @@ -127,12 +157,12 @@ func KernelSUState(r *root.Root) KernelSUStatus { }) } st.Version = root.Revision(dir) - if data, err := root.ReadFileShared(filepath.Join(dir, "source.properties")); err == nil { - _, values := root.ReadKeyValues(data, false) - st.Source = values[kernelSUSourceKey] - if st.LKMVerMagic == "" { - st.LKMVerMagic = values[kernelSULKMVerMagicKey] - } + switch source := props[kernelSUSourceKey]; source { + case KernelSUFromDownload, KernelSUFromImport: + st.Source = source + } + if st.LKMVerMagic == "" { + st.LKMVerMagic = props[kernelSULKMVerMagicKey] } st.Ready = st.InstallSupported && all && strings.EqualFold(st.Version, profile.Version) return st @@ -159,7 +189,7 @@ func KernelSUComplete(dir, wantKernel string) error { if err != nil { return fmt.Errorf("读不了 %s: %w", f.Name, err) } - if _, err := validateKernelSULKM(data, wantKernel, f, storedLKMDigest(dir)); err != nil { + if _, err := validateKernelSULKM(data, wantKernel, f, kernelSUProperties(dir)[kernelSULKMSHA256Key]); err != nil { return fmt.Errorf("%s 校验失败: %w", f.Name, err) } continue @@ -182,13 +212,13 @@ func KernelSUComplete(dir, wantKernel string) error { return nil } -func storedLKMDigest(dir string) string { +func kernelSUProperties(dir string) map[string]string { data, err := root.ReadFileShared(filepath.Join(dir, "source.properties")) if err != nil { - return "" + return nil } _, values := root.ReadKeyValues(data, false) - return values[kernelSULKMSHA256Key] + return values } func validateKernelSULKM(data []byte, release string, file kernelsu.File, trusted string) (string, error) { @@ -273,7 +303,11 @@ type ksuImportItem struct { // Pinned upstream binaries (ksuinit, ksud, KernelSU.apk, meta-overlayfs.zip) are verified by size and SHA-256; // kernelsu.ko is verified as an x86_64 KernelSU LKM matching the root's kernel-ranchu version. // Existing valid files in sdk\kernelsu are kept when omitted from this import. -func ImportKernelSU(ctx context.Context, r *root.Root, files []ImportFile, o Options) (res *KernelSUImportResult, err error) { +func ImportKernelSU(ctx context.Context, r *root.Root, files []ImportFile, o Options) (*KernelSUImportResult, error) { + return installKernelSUComponents(ctx, r, files, o, KernelSUFromImport) +} + +func installKernelSUComponents(ctx context.Context, r *root.Root, files []ImportFile, o Options, from string) (res *KernelSUImportResult, err error) { if fetchGOOS != "windows" { return nil, errs.New(errs.Unsupported, "当前系统不支持 KernelSU 组件导入").WithAdvice("目前仅支持 Windows x86_64 模拟器") } @@ -315,7 +349,11 @@ func ImportKernelSU(ctx context.Context, r *root.Root, files []ImportFile, o Opt f.note(fmt.Sprintf("退出码 %d", errs.ExitCode(err))) }() - f.say("ModAVD:导入 KernelSU 组件文件") + if from == KernelSUFromDownload { + f.say("ModAVD:安装下载的 KernelSU 组件文件") + } else { + f.say("ModAVD:导入 KernelSU 组件文件") + } f.say("文件夹:" + r.Dir) f.clearStaging() @@ -327,7 +365,7 @@ func ImportKernelSU(ctx context.Context, r *root.Root, files []ImportFile, o Opt if err != nil { return nil, err } - res = &KernelSUImportResult{Root: r.Dir, Used: []string{}, Kept: []string{}} + res = &KernelSUImportResult{Root: r.Dir, From: from, Used: []string{}, Kept: []string{}} need := int64(200 << 20) for _, it := range items { f.note(fmt.Sprintf(" 给的文件:%s(%d 字节)", it.name(), it.size)) @@ -346,6 +384,7 @@ func ImportKernelSU(ctx context.Context, r *root.Root, files []ImportFile, o Opt defer f.removeStaging(staging) have := make([]bool, len(profile.Files)) + source := from vermagic := "" var importedLKMHash string for _, it := range items { @@ -387,7 +426,7 @@ func ImportKernelSU(ctx context.Context, r *root.Root, files []ImportFile, o Opt target := filepath.Join(f.sdk, root.KernelSUDir) if KernelSUComplete(target, wantKernel) == nil { - sameLKM := true + sameLKM := importedLKMHash == "" if importedLKMHash != "" { if existing, rerr := os.ReadFile(filepath.Join(target, "kernelsu.ko")); rerr == nil { sum := sha256.Sum256(existing) @@ -403,6 +442,7 @@ func ImportKernelSU(ctx context.Context, r *root.Root, files []ImportFile, o Opt } var missing []string + existingProps := kernelSUProperties(target) for k, pf := range profile.Files { if have[k] { continue @@ -410,11 +450,12 @@ func ImportKernelSU(ctx context.Context, r *root.Root, files []ImportFile, o Opt existingPath := filepath.Join(target, pf.Name) if pf.IsLKM { if data, rerr := os.ReadFile(existingPath); rerr == nil && len(data) > 0 && len(data) <= maxKernelSULKMBytes { - if vm, verr := validateKernelSULKM(data, wantKernel, pf, storedLKMDigest(target)); verr == nil { + if vm, verr := validateKernelSULKM(data, wantKernel, pf, existingProps[kernelSULKMSHA256Key]); verr == nil { sum := sha256.Sum256(data) importedLKMHash = hex.EncodeToString(sum[:]) if werr := os.WriteFile(filepath.Join(out, pf.Name), data, 0o644); werr == nil { vermagic = vm + source = existingProps[kernelSUSourceKey] res.Kept = append(res.Kept, pf.Name) continue } @@ -442,7 +483,7 @@ func ImportKernelSU(ctx context.Context, r *root.Root, files []ImportFile, o Opt } props := fmt.Sprintf("Pkg.Desc=KernelSU LKM and tools for ModAVD.\nPkg.Revision=%s\n%s=%s\n%s=%s\n%s=%s\n%s=%s\n", - profile.Version, kernelSUSourceKey, PlayStoreFromImport, + profile.Version, kernelSUSourceKey, source, kernelSUKernelVersionKey, wantKernel, kernelSULKMVerMagicKey, vermagic, kernelSULKMSHA256Key, importedLKMHash) if err := os.WriteFile(filepath.Join(out, "source.properties"), []byte(props), 0o644); err != nil { return nil, errs.Wrap(errs.Internal, err, "写不了 source.properties:"+err.Error()) diff --git a/internal/components/kernelsu_download.go b/internal/components/kernelsu_download.go index 31c42189..4f9efbd6 100644 --- a/internal/components/kernelsu_download.go +++ b/internal/components/kernelsu_download.go @@ -51,12 +51,8 @@ func FetchKernelSU(ctx context.Context, r *root.Root, o Options) (*KernelSUImpor if want := ExpectedKernelVersion(r); want != profile.KernelRelease { return nil, importRejected(ImportReasonMismatch, "KernelSU 不支持完整版本为 %s 的内核", want) } - for _, file := range profile.Files { - if file.IsLKM && storedLKMDigest(filepath.Join(r.RuntimeSDK(), root.KernelSUDir)) == file.SHA256 { - if st := KernelSUState(r); st.Ready { - return &KernelSUImportResult{Root: r.Dir, Skipped: true, Used: []string{}, Kept: []string{}, Status: st}, nil - } - } + if st := KernelSUState(r); st.Ready && st.LKMVerification == KernelSUVerifiedOfficial { + return &KernelSUImportResult{Root: r.Dir, From: KernelSUFromDownload, Skipped: true, Used: []string{}, Kept: []string{}, Status: st}, nil } dir, err := os.MkdirTemp("", "modavd-kernelsu-download-") if err != nil { @@ -88,5 +84,5 @@ func FetchKernelSU(ctx context.Context, r *root.Root, o Options) (*KernelSUImpor files = append(files, ImportFile{Path: path}) } o.KernelSULKMSHA256 = "" - return ImportKernelSU(ctx, r, files, o) + return installKernelSUComponents(ctx, r, files, o, KernelSUFromDownload) } diff --git a/internal/components/kernelsu_test.go b/internal/components/kernelsu_test.go index ee4f7a01..84311884 100644 --- a/internal/components/kernelsu_test.go +++ b/internal/components/kernelsu_test.go @@ -101,7 +101,9 @@ func TestImportKernelSUAndState(t *testing.T) { if err != nil { t.Fatalf("ImportKernelSU: %v", err) } - if res.Skipped || !res.Status.Ready || res.Status.Source != PlayStoreFromImport || res.Status.Version != "3.3.1" { + if res.Skipped || !res.Status.Ready || res.From != KernelSUFromImport || res.Status.Source != KernelSUFromImport || + res.Status.LKMVerification != KernelSUVerifiedOfficial || res.Status.LKMSHA256 != ksuTestHash(string(data["kernelsu.ko"])) || + res.Status.Version != "3.3.1" { t.Fatalf("unexpected import result: %+v", res) } if !strings.HasPrefix(res.Status.LKMVerMagic, "6.1.23-") { @@ -126,6 +128,25 @@ func TestImportKernelSUAndState(t *testing.T) { if errs.CodeOf(err) != errs.ComponentsRejected { t.Fatalf("expected ComponentsRejected for wrong vermagic, got %v", err) } + + custom := append(append([]byte(nil), data["kernelsu.ko"]...), 1) + customPath := filepath.Join(t.TempDir(), "kernelsu.ko") + if err := os.WriteFile(customPath, custom, 0o644); err != nil { + t.Fatal(err) + } + customSHA := ksuTestHash(string(custom)) + res, err = ImportKernelSU(context.Background(), r, []ImportFile{{Path: customPath}}, Options{KernelSULKMSHA256: customSHA}) + if err != nil || !res.Status.Ready || res.Status.Source != KernelSUFromImport || + res.Status.LKMVerification != KernelSUVerifiedTrusted || res.Status.LKMSHA256 != customSHA { + t.Fatalf("expected a trusted custom module: %+v, %v", res, err) + } + + if err := os.WriteFile(filepath.Join(res.Status.Dir, "kernelsu.ko"), data["kernelsu.ko"], 0o644); err != nil { + t.Fatal(err) + } + if st := KernelSUState(r); st.Ready || st.LKMVerification != "" || st.LKMSHA256 != "" { + t.Fatalf("module with a mismatched recorded digest appeared verified: %+v", st) + } } // TestKernelSULKMAdvice: a refused kernelsu.ko from the command line names --lkm-sha256; from the manager's page, @@ -315,11 +336,13 @@ func TestFetchKernelSURequiresMatchingDownloads(t *testing.T) { } tamper = false got, err := FetchKernelSU(ctx, r, Options{}) - if err != nil || !got.Status.Ready || !got.Status.DownloadAvailable || calls != 6 { + if err != nil || !got.Status.Ready || !got.Status.DownloadAvailable || calls != 6 || + got.From != KernelSUFromDownload || got.Status.Source != KernelSUFromDownload || + got.Status.LKMVerification != KernelSUVerifiedOfficial { t.Fatalf("fetch: %+v, %v, downloads %d", got, err, calls) } got, err = FetchKernelSU(ctx, r, Options{}) - if err != nil || !got.Skipped || calls != 6 { + if err != nil || !got.Skipped || calls != 6 || got.From != KernelSUFromDownload || got.Status.Source != KernelSUFromDownload { t.Fatalf("second fetch: %+v, %v, downloads %d", got, err, calls) } } diff --git a/internal/emu/kernelsu.go b/internal/emu/kernelsu.go index f6e6a866..72157e1a 100644 --- a/internal/emu/kernelsu.go +++ b/internal/emu/kernelsu.go @@ -500,7 +500,10 @@ func (m *Manager) KernelSU(ctx context.Context, i int, action string, purge bool res.Restarted = wasRunning } if purge { - purgeErr := ksuGuestPurge(m, ctx, i) + retained, purgeErr := ksuGuestPurge(m, ctx, i) + if retained { + res.Warnings = append(res.Warnings, "保留 meta-overlayfs:其他模块可能仍需要它,或无法确认文件归属。") + } if purgeErr == nil { purgeErr = m.markKernelSUData(i, false) } @@ -861,23 +864,102 @@ func (m *Manager) runKernelSUKernelProbe(ctx context.Context, i int) (string, er return ver, nil } -func (m *Manager) runKernelSUGuestPurge(ctx context.Context, i int) error { - sh := func(cmd string, timeout time.Duration) adb.Result { return m.shell(ctx, i, cmd, timeout) } - // These are KernelSU-specific paths. Other root managers also use modules and modules_update. - apk := sh("su 0 pm uninstall "+kernelSUAppPackage, kernelSUCmdTimeout) - res := sh("su 0 rm -rf /data/adb/ksu /data/adb/ksud && su 0 sync", kernelSUCmdTimeout) +func (m *Manager) runKernelSUGuestPurge(ctx context.Context, i int) (bool, error) { + // The caller has checked the instance ownership record and booted the stock ramdisk. + res := m.su(ctx, i, kernelSUGuestPurgeScript, kernelSUCmdTimeout) if res.Code != 0 { - return errs.Newf(errs.LaunchFailed, "清理 KernelSU 客体数据失败:%s", tail(res.Out, 200)) + return false, errs.Newf(errs.LaunchFailed, "清理 KernelSU 客体数据失败:%s", tail(res.Out, 200)) } + retained := slices.Contains(strings.Fields(res.Out), "meta-overlayfs-retained") + apk := m.shell(ctx, i, "su 0 pm uninstall "+kernelSUAppPackage, kernelSUCmdTimeout) if apk.Code != 0 { - left := sh("su 0 pm path "+kernelSUAppPackage, kernelSUCmdTimeout) + left := m.shell(ctx, i, "su 0 pm path "+kernelSUAppPackage, kernelSUCmdTimeout) if left.Code == 0 || strings.Contains(left.Out, "package:") { - return errs.Newf(errs.LaunchFailed, "卸载 KernelSU Manager 失败:%s", tail(apk.Out, 200)) + return retained, errs.Newf(errs.LaunchFailed, "卸载 KernelSU Manager 失败:%s", tail(apk.Out, 200)) } } - return nil + return retained, nil +} + +// Verify the unchanged property file and installed x86_64 binary from the bundled +// meta-overlayfs 1.3.1 archive so existing instances can be cleaned without the +// SDK cache. Its modules.img may contain other modules' overlays. +const kernelSUGuestPurgeScript = ` +adb=/data/adb +active=$adb/modules/meta-overlayfs +pending=$adb/modules_update/meta-overlayfs +link=$adb/metamodule + +exists() { [ -e "$1" ] || [ -L "$1" ]; } + +bundled_meta() { + [ -d "$1" ] && [ ! -L "$1" ] && + [ -f "$1/module.prop" ] && [ ! -L "$1/module.prop" ] && + [ -f "$1/meta-overlayfs" ] && [ ! -L "$1/meta-overlayfs" ] || return 1 + prop=$(sha256sum "$1/module.prop") && binary=$(sha256sum "$1/meta-overlayfs") || return 1 + [ "${prop%% *}" = 9c24bd27e1efd6d8568ab795b1787141185f9951794317d8338fbe8f38ee46d3 ] && + [ "${binary%% *}" = 4ff9a64aaff1095ee172bd16189b8ffb37cacf522523edebadd191547ef125b6 ] } +clean_meta() { + for parent in "$adb/modules" "$adb/modules_update"; do + if exists "$parent"; then + [ -d "$parent" ] && [ ! -L "$parent" ] || return 2 + fi + done + + target= + if [ -L "$link" ]; then + target=$(readlink "$link") || return 2 + fi + if ! exists "$active" && ! exists "$pending" && [ "$target" != "$active" ]; then + return 0 + fi + + for dir in "$active" "$pending"; do + if exists "$dir"; then + bundled_meta "$dir" || return 2 + fi + done + for parent in "$adb/modules" "$adb/modules_update"; do + for entry in "$parent"/* "$parent"/.[!.]* "$parent"/..?*; do + if exists "$entry" && [ "$entry" != "$parent/meta-overlayfs" ]; then + return 2 + fi + done + done + + # Do not traverse another filesystem even if the module files match. + if grep -Eq " /data/adb/(modules|modules_update)/meta-overlayfs(/[^ ]*)? " /proc/self/mountinfo; then + return 2 + elif [ "$?" -ne 1 ]; then + return 1 + fi + if [ "$target" = "$active" ]; then + rm "$link" || return 1 + fi + rm -rf "$active" "$pending" +} + +if [ -L "$adb" ] || { exists "$adb" && [ ! -d "$adb" ]; }; then + exit 1 +fi +clean_meta +case $? in + 0) + for parent in "$adb/modules" "$adb/modules_update"; do + if [ -d "$parent" ] && [ ! -L "$parent" ]; then + # A shared parent is only removed while empty. + rmdir "$parent" 2>/dev/null || : + fi + done + ;; + 2) echo meta-overlayfs-retained ;; + *) exit 1 ;; +esac +rm -rf "$adb/ksu" "$adb/ksud" && sync +` + func (m *Manager) runKernelSUGuestModuleInstall(ctx context.Context, i int, localZip string) error { serial := m.Root.Ports().Serial(i) sh := func(cmd string, timeout time.Duration) adb.Result { return m.shell(ctx, i, cmd, timeout) } diff --git a/internal/emu/kernelsu_test.go b/internal/emu/kernelsu_test.go index 69aceeaa..a4f7e6a0 100644 --- a/internal/emu/kernelsu_test.go +++ b/internal/emu/kernelsu_test.go @@ -12,6 +12,7 @@ import ( "os" "path/filepath" "slices" + "strings" "testing" "modavd/internal/avd" @@ -29,6 +30,7 @@ type ksuTestHooks struct { statusMods []KernelSUModule statusErr error installErr error + retainMeta bool patchErr error } @@ -81,9 +83,9 @@ func (h *ksuTestHooks) install(t *testing.T) { } return "32680", h.statusMods, nil } - ksuGuestPurge = func(_ *Manager, _ context.Context, _ int) error { + ksuGuestPurge = func(_ *Manager, _ context.Context, _ int) (bool, error) { h.calls = append(h.calls, "guest-purge") - return nil + return h.retainMeta, nil } ksuGuestModInst = func(_ *Manager, _ context.Context, _ int, localZip string) error { h.calls = append(h.calls, "mod-install:"+filepath.Base(localZip)) @@ -317,10 +319,14 @@ func TestKernelSUPurgeRequiresOwnershipAndBootsStock(t *testing.T) { return &StartResult{}, nil } h.calls = nil + h.retainMeta = true out, err := m.KernelSU(ctx, i, "uninstall", true) if err != nil || !out.Stopped || kernelSUOwnsData(m.Root.InstanceMeta(i)) || !slices.Equal(h.calls, []string{"stock-start", "guest-purge", "stop"}) { t.Fatalf("purge: %+v, %v, calls %v", out, err, h.calls) } + if len(out.Warnings) != 1 || !strings.Contains(out.Warnings[0], "meta-overlayfs") { + t.Fatalf("missing retention warning: %+v", out.Warnings) + } } func TestKernelSUKernelProbeNeedsLiveVersion(t *testing.T) { diff --git a/internal/i18n/locales/en/cli.json b/internal/i18n/locales/en/cli.json index c7f81c84..4605e5a4 100644 --- a/internal/i18n/locales/en/cli.json +++ b/internal/i18n/locales/en/cli.json @@ -519,11 +519,9 @@ "问题包输出目录(默认桌面)": "Output folder of the problem report (default desktop)", "首次初始化": "Initial setup", "默认无头启动,--window 带窗口。运行中不能换:实例已经在运行(或正被另一次 start 开着)时,带了 --window 或 --headless 而它不是这种方式,就报错(busy),不接管也不重启,要换先 stop 再 start;两个都不带就照它现在的方式接管。第一次开机还会做首次初始化。按 Ctrl+C 或 --timeout 到点都只是不再等:模拟器不会被结束,会接着开机。之后再运行一次 start 会接管它,把这次开机还没做完的设置补完(包括首次初始化和客体库补丁)。实例已经在运行、设置也都做完时,只重做每次开机都做的设置。返回前确认 /sdcard 能写进文件(一般这时早已就绪,不多花时间;最多再等 60 秒,到点只警告)。实例还没有 arm64 执行桥时,设置做完后自动装上(中间关机再开机一两次);--no-bridge 这次不装,用 bridge uninstall 卸过或新建时带 --no-bridge 的实例不装,接管已经在运行的实例时也不装。--launch 包名[/Activity] 在上面都做完以后打开这个应用(桌面快捷方式、脚本里「开机并直接进游戏」用):只给包名就打开它的桌面启动入口,给了 Activity(.Main 或完整类名)就直接打开那个;打开后等它到前台,最多 30 秒。包名和 Activity 开机前先检查,格式不对(只许字母、数字、下划线和点)就报错、不开机。没装这个应用不算开机失败:实例照常开着,结果的 app 里 ok 是 false、code 是 app_not_installed,退出码 3;打不开(没有启动入口、am start 报错)是 app_launch_failed,退出码 7;30 秒没到前台是 timeout,退出码 6。--json 的 data.app 是 {package, component, ok, seconds, code, message, advice}。": "Starts headless by default; --window starts with a window. The mode cannot be switched while running: if the instance is already running (or being started by another start) and --window or --headless was given but it is not running that way, it reports an error (busy) and neither takes it over nor restarts it; stop it and start again to switch; with neither option, it takes it over the way it is now. The first start also does the initial setup. Ctrl+C or --timeout only stop waiting: the emulator is not ended and keeps booting. Running start again afterwards takes it over and completes the setup of this start that was not finished (including the initial setup and guest library patches). If the instance is already running and all setup is done, only the setup done on every start is redone. Before returning it confirms that /sdcard can be written to (normally it is long ready by then and costs no time; it waits up to 60 more seconds, and at the deadline only warns). If the instance does not have the arm64 execution bridge yet, it is installed automatically after the setup (one or two shutdown and start rounds in between); --no-bridge skips it this time, and it is not installed for instances where bridge uninstall was used or that were created with --no-bridge, nor when taking over an already running instance. --launch PACKAGE[/ACTIVITY] opens that app once all of the above is done (for desktop shortcuts and scripts that should boot and go straight into a game): with only a package name it opens the app's launcher entry, with an Activity (.Main or a full class name) it opens that one; after opening it waits until the app is in front, up to 30 seconds. The package name and Activity are checked before booting; a malformed one (only letters, digits, underscores and dots are allowed) is an error and nothing is booted. An app that is not installed is not a failed start: the instance stays up, app.ok in the result is false, app.code is app_not_installed and the exit code is 3; an app that cannot be opened (no launcher entry, am start reports an error) is app_launch_failed with exit code 7; not in front after 30 seconds is timeout with exit code 6. data.app of --json is {package, component, ok, seconds, code, message, advice}.", - "(内核 %v,可选,导入的)": " (kernel %v, optional, imported)", "(包名 %v)": " (package %v)", "(只提醒)": " (warning only)", "(可选)": " (optional)", - "(可选,导入的)": " (optional, imported)", "(已就绪)": " (ready)", "(拦截)": " (blocking)", "(未就绪)": " (not ready)", @@ -545,5 +543,10 @@ "KernelSU 仅支持 Windows x86_64 实例": "KernelSU is available only for Windows x86_64 instances", "[status] | source [auto|googledownloads_cn|tencent|google] | fetch [--kernelsu] [--accept-license] [--mirror ID] [--mirror-url URL] [--keep-downloads] [--play-store] | import-playstore <文件或文件夹>… | import-ksu <文件或文件夹>… [--lkm-sha256 SHA256]": "[status] | source [auto|googledownloads_cn|tencent|google] | fetch [--kernelsu] [--accept-license] [--mirror ID] [--mirror-url URL] [--keep-downloads] [--play-store] | import-playstore … | import-ksu … [--lkm-sha256 SHA256]", "从正式发布下载并校验 KernelSU 组件": "Download KernelSU components from official releases and verify them", - "--kernelsu 单独下载,不能与其他 fetch 选项一起使用": "--kernelsu downloads separately and cannot be combined with other fetch options" + "--kernelsu 单独下载,不能与其他 fetch 选项一起使用": "--kernelsu downloads separately and cannot be combined with other fetch options", + "KernelSU 的正式组件已齐全,无需下载": "All official KernelSU components are present. No download needed.", + "已下载并校验 KernelSU 组件:%s\n": "Downloaded and verified KernelSU components: %s\n", + "(内核 %s,可选)": " (kernel %s, optional)", + ",模块仅按本地记录的校验值核对": ", module verified against the local checksum", + ",模块匹配正式发布的校验值": ", module matches the official release checksum" } diff --git a/internal/i18n/locales/en/components.json b/internal/i18n/locales/en/components.json index 24b51ce6..ea9b8d3e 100644 --- a/internal/i18n/locales/en/components.json +++ b/internal/i18n/locales/en/components.json @@ -259,5 +259,6 @@ "自己编的模块请在命令行导入:modavd components import-ksu <文件> --lkm-sha256 <它的 SHA-256>": "Import a module you built yourself on the command line: modavd components import-ksu --lkm-sha256 ", "使用本地 SDK 时不能下载 KernelSU 组件": "KernelSU components cannot be downloaded with a local SDK override", "下载 KernelSU 文件失败:%v": "Failed to download KernelSU file: %v", - "下载的 KernelSU 文件大小或 SHA-256 不匹配:%s": "Downloaded KernelSU file has a mismatched size or SHA-256: %s" + "下载的 KernelSU 文件大小或 SHA-256 不匹配:%s": "Downloaded KernelSU file has a mismatched size or SHA-256: %s", + "ModAVD:安装下载的 KernelSU 组件文件": "ModAVD: install downloaded KernelSU component files" } diff --git a/internal/i18n/locales/en/emu.json b/internal/i18n/locales/en/emu.json index 1130eea9..1f801de5 100644 --- a/internal/i18n/locales/en/emu.json +++ b/internal/i18n/locales/en/emu.json @@ -1074,5 +1074,6 @@ "实例 %d 已有未受管理的 KernelSU 数据或应用": "Instance %d already has unmanaged KernelSU data or an app", "ModAVD 实例 %d 启动失败:Windows 拒绝了创建虚拟机(WHPX 返回拒绝访问,hr=80070005),多半是电脑上开着带内核级反作弊的游戏,或者安全软件在阻止(emulator.exe 退出码 %s):%s": "ModAVD instance %d failed to start: Windows refused to create the virtual machine (WHPX returned access denied, hr=80070005), most likely because a game with kernel-level anti-cheat is running or security software is blocking it (emulator.exe exit code %s): %s", "ModAVD 实例 %d 启动超时(%.0f 秒内安卓没有启动完成):模拟器日志里 Windows 拒绝了创建虚拟机(WHPX 返回拒绝访问,hr=80070005),多半是电脑上开着带内核级反作弊的游戏,或者安全软件在阻止;日志见 %s": "ModAVD instance %d timed out starting (Android did not finish booting within %.0f s): the emulator log says Windows refused to create the virtual machine (WHPX returned access denied, hr=80070005), most likely because a game with kernel-level anti-cheat is running or security software is blocking it. See log %s", - "先退出带反作弊的游戏(比如用 EA AntiCheat 的),它的反作弊后台服务还在的话也关掉,再开机,不用重启电脑;没开这类游戏的话,看看安全软件有没有拦着虚拟化": "Quit the game with anti-cheat first (such as one using EA AntiCheat), and close its anti-cheat background service too if it is still running, then start again; no need to restart the computer. If no such game is running, check whether security software is blocking virtualization" + "先退出带反作弊的游戏(比如用 EA AntiCheat 的),它的反作弊后台服务还在的话也关掉,再开机,不用重启电脑;没开这类游戏的话,看看安全软件有没有拦着虚拟化": "Quit the game with anti-cheat first (such as one using EA AntiCheat), and close its anti-cheat background service too if it is still running, then start again; no need to restart the computer. If no such game is running, check whether security software is blocking virtualization", + "保留 meta-overlayfs:其他模块可能仍需要它,或无法确认文件归属。": "Kept meta-overlayfs because other modules may still use it or ModAVD could not verify ownership." } diff --git a/internal/i18n/locales/en/report.json b/internal/i18n/locales/en/report.json index 2f699436..6a84b9ac 100644 --- a/internal/i18n/locales/en/report.json +++ b/internal/i18n/locales/en/report.json @@ -392,5 +392,6 @@ ",放在 %s: 盘(剩余 %s GB": null, ";模拟器检查未完成": null, ";模拟器检查超时": null, - ";模拟器检查退出码 %d:%s": null + ";模拟器检查退出码 %d:%s": null, + "KernelSU SDK 模块:source=%s verification=%s sha256=%s": null } diff --git a/internal/i18n/locales/en/web.json b/internal/i18n/locales/en/web.json index 2eff404e..70059f47 100644 --- a/internal/i18n/locales/en/web.json +++ b/internal/i18n/locales/en/web.json @@ -770,5 +770,12 @@ "正式模块尚未发布": "The official module has not been released", "游戏和应用可能检测到 root,有的游戏会因此拒绝运行或处罚账号;导入的模块在客体内以 root 运行。启用后开不了机时,先关机,再在实例的「更多操作」里点「移除 KernelSU…」,或运行 modavd ksu <编号> uninstall,恢复原版启动。": "Games and apps may detect root, and some games refuse to run or penalize the account; imported modules run as root in the guest. If the instance no longer starts after enabling, shut it down, then choose \"Remove KernelSU…\" in the instance's More actions menu, or run modavd ksu uninstall, to restore stock boot.", "已知问题:启用 KernelSU 的实例每次关机会多等几秒,下次开机会多做一遍磁盘检查;原因还在查,见 {issue}。": "Known issue: an instance with KernelSU enabled takes a few extra seconds to shut down each time and runs an extra disk check on its next start. The cause is still being investigated; see {issue}.", - "已知问题:启用 KernelSU 后系统调用会变慢,这台实例的性能会比不启用时低一些,见 {issue}。": "Known issue: with KernelSU enabled, system calls are slower, so the instance performs somewhat worse than without it; see {issue}." + "已知问题:启用 KernelSU 后系统调用会变慢,这台实例的性能会比不启用时低一些,见 {issue}。": "Known issue: with KernelSU enabled, system calls are slower, so the instance performs somewhat worse than without it; see {issue}.", + "内核模块仅按本地记录的校验值核对。": "The kernel module was verified against the local checksum.", + "内核模块匹配正式发布的校验值。": "The kernel module matches the official release checksum.", + "内核模块通过下载取得。": "The kernel module was downloaded.", + "内核模块通过导入取得。": "The kernel module was imported.", + "KernelSU 的正式组件已齐全,无需下载。": "All official KernelSU components are present. No download needed.", + "KernelSU 组件已下载并校验。": "KernelSU components were downloaded and verified.", + "正在准备 KernelSU 组件:{progress}": "Preparing KernelSU components: {progress}" } diff --git a/internal/report/collect.go b/internal/report/collect.go index ab370436..185e1663 100644 --- a/internal/report/collect.go +++ b/internal/report/collect.go @@ -25,6 +25,7 @@ import ( "modavd/internal/appproxy" "modavd/internal/buildinfo" + "modavd/internal/components" "modavd/internal/diagnostics" "modavd/internal/errs" "modavd/internal/jsonord" @@ -414,6 +415,10 @@ func (c *collector) rootAndVersions() error { } } + if ksu := components.KernelSUStateForSDK(c.sdk()); ksu.LKMVerification != "" { + c.L(fmt.Sprintf("KernelSU SDK 模块:source=%s verification=%s sha256=%s", orDash(ksu.Source), ksu.LKMVerification, ksu.LKMSHA256)) + } + c.section("模拟器版本") emu, err := readProps(filepath.Join(c.sdk(), "emulator", "source.properties")) if err != nil { diff --git a/internal/report/report_test.go b/internal/report/report_test.go index 7aa06d80..680e69e9 100644 --- a/internal/report/report_test.go +++ b/internal/report/report_test.go @@ -3,6 +3,7 @@ package report import ( "archive/zip" "context" + "crypto/sha256" "fmt" "io" "os" @@ -13,10 +14,42 @@ import ( "time" "modavd/internal/jsonord" + "modavd/internal/kernelsu" "modavd/internal/root" "modavd/internal/testutil" ) +func TestKernelSUModuleProvenanceInSummary(t *testing.T) { + dir := testutil.TempDir(t) + profile := kernelsu.CurrentProfile() + data := testutil.KernelSUTestModule("kernelsu", profile.KernelRelease+" SMP preempt mod_unload modversions", false) + digest := sha256.Sum256(data) + sdk := filepath.Join(dir, root.SDKDir) + for name, contents := range map[string][]byte{ + filepath.Join("emulator", "source.properties"): []byte("Pkg.Revision=37.2.10\n"), + filepath.Join("platform-tools", "source.properties"): []byte("Pkg.Revision=35\n"), + filepath.Join(root.KernelSUDir, "kernelsu.ko"): data, + filepath.Join(root.KernelSUDir, "source.properties"): fmt.Appendf(nil, + "Pkg.Revision=%s\nModAVD.Source=import\nModAVD.LKMSHA256=%x\n", profile.Version, digest), + } { + file := filepath.Join(sdk, name) + if err := os.MkdirAll(filepath.Dir(file), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(file, contents, 0o644); err != nil { + t.Fatal(err) + } + } + c := &collector{root: dir, h: &fakeHost{sc: &scenario{}}} + if err := c.rootAndVersions(); err != nil { + t.Fatal(err) + } + want := fmt.Sprintf("KernelSU SDK 模块:source=import verification=trusted sha256=%x", digest) + if !strings.Contains(strings.Join(c.lines, "\n"), want) { + t.Fatalf("missing verified KernelSU evidence: %v", c.lines) + } +} + func TestFormatN(t *testing.T) { // '{0:N}' -f v on Windows PowerShell 5.1 for _, c := range []struct { diff --git a/internal/ui/API.en.md b/internal/ui/API.en.md index 249e97f8..11558504 100644 --- a/internal/ui/API.en.md +++ b/internal/ui/API.en.md @@ -252,6 +252,7 @@ Tap coordinates on the screen are converted and validated against the size of th ### KernelSU (experimental) +- `GET /api/components` and `components status --json` return `kernelsu`. Its `source` is `download`, `import`, or an empty string when unknown. `lkm_verification` is `official` for a match with the current release pin or `trusted` for a match with the local checksum. `lkm_verification` and `lkm_sha256` are present only after the module passes verification. The download and import jobs identify the operation in `from`. - `POST /api/components/fetch-ksu` returns a root job that downloads and verifies all components from the official releases. - `POST /api/components/import-ksu` takes multipart `file` parts and returns a root job. Browser imports require a module digest pinned by Manager. - `POST /api/instances/{i}/ksu-install` takes `{}` and `POST /api/instances/{i}/ksu-uninstall` takes `{"purge":false}`. Both return an instance job with `state`, `installed`, `ramdisk_patched`, and `warnings` in the result. diff --git a/internal/ui/API.md b/internal/ui/API.md index 70864395..c5533cbd 100644 --- a/internal/ui/API.md +++ b/internal/ui/API.md @@ -252,6 +252,7 @@ ModAVD/ModAVD#101,只有 Windows。 ### KernelSU(实验) +- `kernelsu` 字段随 `GET /api/components` 和 `components status --json` 返回。`source` 记录模块是下载(`download`)、导入(`import`)还是未知(空字符串)。`lkm_verification` 为 `official` 时匹配当前发布钉值,为 `trusted` 时仅匹配本地记录的校验值。文件校验通过后才返回 `lkm_verification` 和 `lkm_sha256`。下载和导入作业通过结果的 `from` 标明操作。 - `POST /api/components/fetch-ksu` 返回根目录作业,从正式 Release 下载和校验全部组件。 - `POST /api/components/import-ksu` 接收 multipart 的 `file` 字段,返回根目录作业。网页导入只接受管理器固定哈希的模块。 - `POST /api/instances/{i}/ksu-install` 接收 `{}`,`POST /api/instances/{i}/ksu-uninstall` 接收 `{"purge":false}`。返回实例作业,结果有 `state`、`installed`、`ramdisk_patched` 和 `warnings`。 diff --git a/internal/ui/web/js/actions.js b/internal/ui/web/js/actions.js index 2cffc8aa..5783f2e7 100644 --- a/internal/ui/web/js/actions.js +++ b/internal/ui/web/js/actions.js @@ -97,7 +97,9 @@ function notify(job) { } else if (job.kind === 'ksu-install') { toast({ tone: r.installed ? 'ok' : 'warn', title: r.installed ? t('{who}已启用 KernelSU', { who }) : t('{who}的 KernelSU 未完全生效', { who }), text: ksuText(job.kind, r), timeout: 9000 }); } else if (job.kind === 'ksu-uninstall') { - toast({ tone: r.state === 'absent' ? 'ok' : 'warn', title: t('{who}已移除 KernelSU', { who }), text: ksuText(job.kind, r), timeout: 6000 }); + const warned = (r.warnings || []).length > 0; + toast({ tone: r.state === 'absent' && !warned ? 'ok' : 'warn', title: t('{who}已移除 KernelSU', { who }), + text: ksuText(job.kind, r), timeout: warned ? 12000 : 6000 }); } else if (job.kind === 'ksu-module-install') { toast({ title: t('{who}已导入 KernelSU 模块', { who }), text: ksuText(job.kind, r), timeout: 9000 }); } else if (job.kind === 'ksu-module-remove') { diff --git a/internal/ui/web/js/diagnostics.js b/internal/ui/web/js/diagnostics.js index 3f952f57..e655aaeb 100644 --- a/internal/ui/web/js/diagnostics.js +++ b/internal/ui/web/js/diagnostics.js @@ -195,13 +195,18 @@ export function fillKSUBox(b) { attr(b.own, 'aria-disabled', imp || upload ? true : null); b.state.hidden = !ready; if (ready) { - setText(b.state, t('KernelSU {ver} 组件已就绪,可在实例的「更多操作」里启用并导入模块。', { ver: st.version || '3.3.1' })); + const bits = [t('KernelSU {ver} 组件已就绪,可在实例的「更多操作」里启用并导入模块。', { ver: st.version || '3.3.1' })]; + if (st.lkm_verification === 'official') bits.push(t('内核模块匹配正式发布的校验值。')); + if (st.lkm_verification === 'trusted') bits.push(t('内核模块仅按本地记录的校验值核对。')); + if (st.source === 'download') bits.push(t('内核模块通过下载取得。')); + if (st.source === 'import') bits.push(t('内核模块通过导入取得。')); + setText(b.state, bits.join(' ')); } b.running.hidden = !(imp || upload); b.cancel.hidden = !imp; if (imp) { b.id = imp.id; - setText(b.text, t('正在导入:{progress}', { progress: progressText(imp) })); + setText(b.text, t('正在准备 KernelSU 组件:{progress}', { progress: progressText(imp) })); } else if (upload) setText(b.text, t('正在把 {n} 个文件交给后台(共 {bytes})…', { n: upload.n, bytes: fmtBytes(upload.bytes) })); const sig = failed && !ready && !imp && !upload ? `${failed.message}|${failed.advice}` : ''; if (b.sig !== sig) { diff --git a/internal/ui/web/js/format.js b/internal/ui/web/js/format.js index ca67c8ae..d0f762bc 100644 --- a/internal/ui/web/js/format.js +++ b/internal/ui/web/js/format.js @@ -123,6 +123,9 @@ export function playStoreText(kind, r) { export function ksuText(kind, r) { if (!r) return ''; if (kind === 'ksu-import') { + if (r.from === 'download') { + return r.skipped ? t('KernelSU 的正式组件已齐全,无需下载。') : t('KernelSU 组件已下载并校验。'); + } if (r.skipped) return t('五个文件本来就齐全,给的文件也核对无误,没有改动。'); const n = (r.used || []).length; const kept = (r.kept || []).length; @@ -134,7 +137,9 @@ export function ksuText(kind, r) { else if (kind === 'ksu-uninstall') base = t('已恢复原版 ramdisk 启动'); else if (kind === 'ksu-module-install') base = t('已刷入 {n} 个模块', { n: (r.installed || []).length }); else if (kind === 'ksu-module-remove') base = t('已卸载模块 {id}', { id: r.id || '' }); - return how ? base + comma() + how + stop() : base + stop(); + const text = how ? base + comma() + how + stop() : base + stop(); + const warnings = kind === 'ksu-uninstall' ? r.warnings || [] : []; + return warnings.length ? text + gap() + warnings.join(gap()) : text; } // The GLES 3.2 jobs (API.md "报告 GLES 3.2"): GLES32Result of an instance's on / off (stopped: it was off and is off diff --git a/scripts/test_kernelsu_ui.mjs b/scripts/test_kernelsu_ui.mjs index 80dfb411..37fc47e0 100644 --- a/scripts/test_kernelsu_ui.mjs +++ b/scripts/test_kernelsu_ui.mjs @@ -226,6 +226,17 @@ async function ksuBlock(ksu) { return { ...r, b: m.mod.ksuBox(), D: m.mod }; } +test('KernelSU component status shows the acquisition source and the LKM verification independently', async () => { + const official = await ksuBlock({ ...KSU.ready, source: 'download', lkm_verification: 'official' }); + assert.match(official.b.state.textContent, /正式发布的校验值/); + assert.match(official.b.state.textContent, /通过下载取得/); + + const local = await ksuBlock({ ...KSU.ready, source: 'import', lkm_verification: 'trusted' }); + assert.match(local.b.state.textContent, /仅按本地记录的校验值/); + assert.match(local.b.state.textContent, /通过导入取得/); + assert.doesNotMatch(local.b.state.textContent, /正式发布的校验值/); +}); + test('the block says what enabling risks and the way back, and names no module', async () => { const { b, D } = await ksuBlock(KSU.download); const text = b.el.textContent;