You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
ksud: test vendor_boot patching for some newer devices
This commit is contained in:
@@ -167,6 +167,21 @@ fn do_cpio_cmd(magiskboot: &Path, workdir: &Path, cmd: &str) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn do_vendor_cpio_cmd(magiskboot: &Path, workdir: &Path, cmd: &str) -> Result<()> {
|
||||||
|
let vendor_ramdisk_cpio = workdir.join("vendor_ramdisk").join("init_boot.cpio");
|
||||||
|
let status = Command::new(magiskboot)
|
||||||
|
.current_dir(workdir)
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.stderr(Stdio::null())
|
||||||
|
.arg("cpio")
|
||||||
|
.arg(vendor_ramdisk_cpio)
|
||||||
|
.arg(cmd)
|
||||||
|
.status()?;
|
||||||
|
|
||||||
|
ensure!(status.success(), "magiskboot cpio {} failed", cmd);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn is_magisk_patched(magiskboot: &Path, workdir: &Path) -> Result<bool> {
|
fn is_magisk_patched(magiskboot: &Path, workdir: &Path) -> Result<bool> {
|
||||||
let status = Command::new(magiskboot)
|
let status = Command::new(magiskboot)
|
||||||
.current_dir(workdir)
|
.current_dir(workdir)
|
||||||
@@ -441,11 +456,6 @@ fn do_patch(
|
|||||||
assets::copy_assets_to_file("ksuinit", init_file).context("copy ksuinit failed")?;
|
assets::copy_assets_to_file("ksuinit", init_file).context("copy ksuinit failed")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// magiskboot unpack boot.img
|
|
||||||
// magiskboot cpio ramdisk.cpio 'cp init init.real'
|
|
||||||
// magiskboot cpio ramdisk.cpio 'add 0755 ksuinit init'
|
|
||||||
// magiskboot cpio ramdisk.cpio 'add 0755 <kmod> kernelsu.ko'
|
|
||||||
|
|
||||||
println!("- Unpacking boot image");
|
println!("- Unpacking boot image");
|
||||||
let status = Command::new(&magiskboot)
|
let status = Command::new(&magiskboot)
|
||||||
.current_dir(workdir)
|
.current_dir(workdir)
|
||||||
@@ -468,17 +478,29 @@ fn do_patch(
|
|||||||
|
|
||||||
let mut need_backup = false;
|
let mut need_backup = false;
|
||||||
if !is_kernelsu_patched {
|
if !is_kernelsu_patched {
|
||||||
// kernelsu.ko is not exist, backup init if necessary
|
if no_ramdisk {
|
||||||
let status = do_cpio_cmd(&magiskboot, workdir, "exists init");
|
// vendor ramdisk patching
|
||||||
if status.is_ok() {
|
let status = do_vendor_cpio_cmd(&magiskboot, workdir, "exists init");
|
||||||
do_cpio_cmd(&magiskboot, workdir, "mv init init.real")?;
|
if status.is_ok() {
|
||||||
|
do_vendor_cpio_cmd(&magiskboot, workdir, "mv init init.real")?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// kernelsu.ko is not exist, backup init if necessary
|
||||||
|
let status = do_cpio_cmd(&magiskboot, workdir, "exists init");
|
||||||
|
if status.is_ok() {
|
||||||
|
do_cpio_cmd(&magiskboot, workdir, "mv init init.real")?;
|
||||||
|
}
|
||||||
|
need_backup = flash;
|
||||||
}
|
}
|
||||||
|
|
||||||
need_backup = flash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do_cpio_cmd(&magiskboot, workdir, "add 0755 init init")?;
|
if no_ramdisk {
|
||||||
do_cpio_cmd(&magiskboot, workdir, "add 0755 kernelsu.ko kernelsu.ko")?;
|
do_vendor_cpio_cmd(&magiskboot, workdir, "add 0755 init init")?;
|
||||||
|
do_vendor_cpio_cmd(&magiskboot, workdir, "add 0755 kernelsu.ko kernelsu.ko")?;
|
||||||
|
} else {
|
||||||
|
do_cpio_cmd(&magiskboot, workdir, "add 0755 init init")?;
|
||||||
|
do_cpio_cmd(&magiskboot, workdir, "add 0755 kernelsu.ko kernelsu.ko")?;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
if need_backup {
|
if need_backup {
|
||||||
|
|||||||
@@ -167,6 +167,21 @@ fn do_cpio_cmd(magiskboot: &Path, workdir: &Path, cmd: &str) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn do_vendor_cpio_cmd(magiskboot: &Path, workdir: &Path, cmd: &str) -> Result<()> {
|
||||||
|
let vendor_ramdisk_cpio = workdir.join("vendor_ramdisk").join("init_boot.cpio");
|
||||||
|
let status = Command::new(magiskboot)
|
||||||
|
.current_dir(workdir)
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.stderr(Stdio::null())
|
||||||
|
.arg("cpio")
|
||||||
|
.arg(vendor_ramdisk_cpio)
|
||||||
|
.arg(cmd)
|
||||||
|
.status()?;
|
||||||
|
|
||||||
|
ensure!(status.success(), "magiskboot cpio {} failed", cmd);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn is_magisk_patched(magiskboot: &Path, workdir: &Path) -> Result<bool> {
|
fn is_magisk_patched(magiskboot: &Path, workdir: &Path) -> Result<bool> {
|
||||||
let status = Command::new(magiskboot)
|
let status = Command::new(magiskboot)
|
||||||
.current_dir(workdir)
|
.current_dir(workdir)
|
||||||
@@ -301,7 +316,7 @@ pub fn restore(
|
|||||||
let output_dir = std::env::current_dir()?;
|
let output_dir = std::env::current_dir()?;
|
||||||
let now = chrono::Utc::now();
|
let now = chrono::Utc::now();
|
||||||
let output_image = output_dir.join(format!(
|
let output_image = output_dir.join(format!(
|
||||||
"kernelsu_restore_{}.img",
|
"kernelsu_next_restore_{}.img",
|
||||||
now.format("%Y%m%d_%H%M%S")
|
now.format("%Y%m%d_%H%M%S")
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -441,11 +456,6 @@ fn do_patch(
|
|||||||
assets::copy_assets_to_file("ksuinit", init_file).context("copy ksuinit failed")?;
|
assets::copy_assets_to_file("ksuinit", init_file).context("copy ksuinit failed")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// magiskboot unpack boot.img
|
|
||||||
// magiskboot cpio ramdisk.cpio 'cp init init.real'
|
|
||||||
// magiskboot cpio ramdisk.cpio 'add 0755 ksuinit init'
|
|
||||||
// magiskboot cpio ramdisk.cpio 'add 0755 <kmod> kernelsu.ko'
|
|
||||||
|
|
||||||
println!("- Unpacking boot image");
|
println!("- Unpacking boot image");
|
||||||
let status = Command::new(&magiskboot)
|
let status = Command::new(&magiskboot)
|
||||||
.current_dir(workdir)
|
.current_dir(workdir)
|
||||||
@@ -468,17 +478,29 @@ fn do_patch(
|
|||||||
|
|
||||||
let mut need_backup = false;
|
let mut need_backup = false;
|
||||||
if !is_kernelsu_patched {
|
if !is_kernelsu_patched {
|
||||||
// kernelsu.ko is not exist, backup init if necessary
|
if no_ramdisk {
|
||||||
let status = do_cpio_cmd(&magiskboot, workdir, "exists init");
|
// vendor ramdisk patching
|
||||||
if status.is_ok() {
|
let status = do_vendor_cpio_cmd(&magiskboot, workdir, "exists init");
|
||||||
do_cpio_cmd(&magiskboot, workdir, "mv init init.real")?;
|
if status.is_ok() {
|
||||||
|
do_vendor_cpio_cmd(&magiskboot, workdir, "mv init init.real")?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// kernelsu.ko is not exist, backup init if necessary
|
||||||
|
let status = do_cpio_cmd(&magiskboot, workdir, "exists init");
|
||||||
|
if status.is_ok() {
|
||||||
|
do_cpio_cmd(&magiskboot, workdir, "mv init init.real")?;
|
||||||
|
}
|
||||||
|
need_backup = flash;
|
||||||
}
|
}
|
||||||
|
|
||||||
need_backup = flash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do_cpio_cmd(&magiskboot, workdir, "add 0755 init init")?;
|
if no_ramdisk {
|
||||||
do_cpio_cmd(&magiskboot, workdir, "add 0755 kernelsu.ko kernelsu.ko")?;
|
do_vendor_cpio_cmd(&magiskboot, workdir, "add 0755 init init")?;
|
||||||
|
do_vendor_cpio_cmd(&magiskboot, workdir, "add 0755 kernelsu.ko kernelsu.ko")?;
|
||||||
|
} else {
|
||||||
|
do_cpio_cmd(&magiskboot, workdir, "add 0755 init init")?;
|
||||||
|
do_cpio_cmd(&magiskboot, workdir, "add 0755 kernelsu.ko kernelsu.ko")?;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
if need_backup {
|
if need_backup {
|
||||||
|
|||||||
Reference in New Issue
Block a user