From 839fc0534e202468782651a85542ddfcdf799b4f Mon Sep 17 00:00:00 2001 From: fsxitutu Date: Wed, 1 May 2024 09:48:59 +0800 Subject: [PATCH] Add magiskboot to kernelsu working directory (#1684) Add the magiskboot binary to the /data/adb/ksu/bin directory so that scripts/programs can call magiskboot to patch the boot/init_boot image. --------- Co-authored-by: weishu --- .../app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt | 3 ++- userspace/ksud/src/cli.rs | 7 +++++-- userspace/ksud/src/defs.rs | 1 + userspace/ksud/src/utils.rs | 7 ++++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt index d150fcd6..a4e1066b 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt @@ -84,7 +84,8 @@ fun execKsud(args: String, newShell: Boolean = false): Boolean { fun install() { val start = SystemClock.elapsedRealtime() - val result = execKsud("install", true) + val magiskboot = File(ksuApp.applicationInfo.nativeLibraryDir, "libmagiskboot.so").absolutePath + val result = execKsud("install --magiskboot $magiskboot", true) Log.w(TAG, "install result: $result, cost: ${SystemClock.elapsedRealtime() - start}ms") } diff --git a/userspace/ksud/src/cli.rs b/userspace/ksud/src/cli.rs index 3bc620c1..cd96a360 100644 --- a/userspace/ksud/src/cli.rs +++ b/userspace/ksud/src/cli.rs @@ -35,7 +35,10 @@ enum Commands { BootCompleted, /// Install KernelSU userspace component to system - Install, + Install { + #[arg(long, default_value = None)] + magiskboot: Option, + }, /// Uninstall KernelSU modules and itself(LKM Only) Uninstall { @@ -307,7 +310,7 @@ pub fn run() -> Result<()> { Module::Shrink => module::shrink_ksu_images(), } } - Commands::Install => utils::install(), + Commands::Install { magiskboot } => utils::install(magiskboot), Commands::Uninstall { magiskboot } => utils::uninstall(magiskboot), Commands::Sepolicy { command } => match command { Sepolicy::Patch { sepolicy } => crate::sepolicy::live_patch(&sepolicy), diff --git a/userspace/ksud/src/defs.rs b/userspace/ksud/src/defs.rs index 717a74fd..c4b9fc3f 100644 --- a/userspace/ksud/src/defs.rs +++ b/userspace/ksud/src/defs.rs @@ -12,6 +12,7 @@ pub const PROFILE_TEMPLATE_DIR: &str = concatcp!(PROFILE_DIR, "templates/"); pub const KSURC_PATH: &str = concatcp!(WORKING_DIR, ".ksurc"); pub const KSU_OVERLAY_SOURCE: &str = "KSU"; pub const DAEMON_PATH: &str = concatcp!(ADB_DIR, "ksud"); +pub const MAGISKBOOT_PATH: &str = concatcp!(BINARY_DIR, "magiskboot"); #[cfg(target_os = "android")] pub const DAEMON_LINK_PATH: &str = concatcp!(BINARY_DIR, "ksud"); diff --git a/userspace/ksud/src/utils.rs b/userspace/ksud/src/utils.rs index 9da92588..5abd6a4b 100644 --- a/userspace/ksud/src/utils.rs +++ b/userspace/ksud/src/utils.rs @@ -208,7 +208,7 @@ fn link_ksud_to_bin() -> Result<()> { Ok(()) } -pub fn install() -> Result<()> { +pub fn install(magiskboot: Option) -> Result<()> { ensure_dir_exists(defs::ADB_DIR)?; std::fs::copy("/proc/self/exe", defs::DAEMON_PATH)?; restorecon::lsetfilecon(defs::DAEMON_PATH, restorecon::ADB_CON)?; @@ -218,6 +218,11 @@ pub fn install() -> Result<()> { #[cfg(target_os = "android")] link_ksud_to_bin()?; + if let Some(magiskboot) = magiskboot { + ensure_dir_exists(defs::BINARY_DIR)?; + let _ = std::fs::copy(magiskboot, defs::MAGISKBOOT_PATH); + } + Ok(()) }