ksud: Fix magisk detect
This commit is contained in:
@@ -61,6 +61,18 @@ fn do_cpio_cmd(magiskboot: &Path, workding_dir: &Path, cmd: &str) -> Result<()>
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_magisk_patched(magiskboot: &Path, workding_dir: &Path) -> Result<bool> {
|
||||||
|
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<P: AsRef<Path>, Q: AsRef<Path>>(ifile: P, ofile: Q) -> Result<()> {
|
fn dd<P: AsRef<Path>, Q: AsRef<Path>>(ifile: P, ofile: Q) -> Result<()> {
|
||||||
let status = Command::new("dd")
|
let status = Command::new("dd")
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
@@ -225,9 +237,9 @@ fn do_patch(
|
|||||||
ensure!(status.success(), "magiskboot unpack failed");
|
ensure!(status.success(), "magiskboot unpack failed");
|
||||||
|
|
||||||
let no_ramdisk = !workding_dir.path().join("ramdisk.cpio").exists();
|
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!(
|
ensure!(
|
||||||
no_ramdisk || not_magisk,
|
no_ramdisk || !is_magisk_patched,
|
||||||
"Cannot work with Magisk patched image"
|
"Cannot work with Magisk patched image"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user