From e39be55db8970098fbbe8e7c840252285892a8a7 Mon Sep 17 00:00:00 2001 From: weishu Date: Sat, 16 Mar 2024 10:07:24 +0800 Subject: [PATCH] ksud: Fix magisk detect --- userspace/ksud/src/boot_patch.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/userspace/ksud/src/boot_patch.rs b/userspace/ksud/src/boot_patch.rs index 66e859b2..302e442f 100644 --- a/userspace/ksud/src/boot_patch.rs +++ b/userspace/ksud/src/boot_patch.rs @@ -61,6 +61,18 @@ fn do_cpio_cmd(magiskboot: &Path, workding_dir: &Path, cmd: &str) -> Result<()> Ok(()) } +fn is_magisk_patched(magiskboot: &Path, workding_dir: &Path) -> Result { + let status = Command::new(magiskboot) + .current_dir(workding_dir) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .args(["cpio", "ramdisk.cpio", "test"]) + .status()?; + + // 0: stock, 1: magisk + Ok(status.code() == Some(1)) +} + fn dd, Q: AsRef>(ifile: P, ofile: Q) -> Result<()> { let status = Command::new("dd") .stdout(Stdio::null()) @@ -225,9 +237,9 @@ fn do_patch( ensure!(status.success(), "magiskboot unpack failed"); let no_ramdisk = !workding_dir.path().join("ramdisk.cpio").exists(); - let not_magisk = do_cpio_cmd(&magiskboot, workding_dir.path(), "test").is_ok(); + let is_magisk_patched = is_magisk_patched(&magiskboot, workding_dir.path())?; ensure!( - no_ramdisk || not_magisk, + no_ramdisk || !is_magisk_patched, "Cannot work with Magisk patched image" );