From 2820158534e96b0a26890a408a9e27c33be55daa Mon Sep 17 00:00:00 2001 From: AXON Date: Thu, 21 Jan 2021 01:21:13 +0600 Subject: [PATCH] refactor: bind-mount pre-existing su bins instead of wiping them out completely --- src/main.rs | 20 ++++++++++++++++---- src/utils.rs | 22 ---------------------- vendorsetup.sh | 7 +++++++ 3 files changed, 23 insertions(+), 26 deletions(-) create mode 100644 vendorsetup.sh diff --git a/src/main.rs b/src/main.rs index 4d397f0..c6a8921 100755 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::{env, fs, os::unix::fs::symlink, path::Path, process::Command}; use sys_mount::{Mount, MountFlags}; use utils::{ chmod, clone_perms, dir_is_empty, early_mode, extract_file, load_modfile, remount_root, - switch_init, wipe_old_su, KernelFsMount, + switch_init, KernelFsMount, }; pub fn job() { @@ -119,7 +119,6 @@ pub fn job() { .mount() { Ok(_) => { - wipe_old_su(); extract_file("/dev/chmod", include_bytes!("asset/chmod"), 777); for dir in ["/system/bin"].iter() { match Command::new("/dev/chmod").args(&["755", dir]).status() { @@ -304,8 +303,21 @@ pub fn job() { } } - // Wipe old su binaries - wipe_old_su(); + // Own pre-existing su binaries + if bin_dir == "/sbin" { + for su_bin in ["/system/bin/su", "/system/xbin/su"].iter() { + if Path::new(su_bin).exists() { + if let Err(why) = + libmount::BindMount::new(format!("{}/{}", bin_dir, "su"), su_bin).mount() + { + println!( + "rusty-magisk: Failed to bind mount {} into {}: {}", + bin_dir, su_bin, why + ); + } + } + } + } // Ensure /sbin is accessible globally if bin_dir == "/sbin" { diff --git a/src/utils.rs b/src/utils.rs index 02e626c..749457c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -124,28 +124,6 @@ pub fn clone_perms(source: &str, target: &str) -> std::io::Result<()> { Ok(()) } -pub fn wipe_old_su() { - for su_bin in ["/system/bin/su", "/system/xbin/su"].iter() { - if Path::new(su_bin).exists() { - if let Err(why) = fs::remove_file(su_bin) { - println!( - "rusty-magisk: Failed to remove existing {} binary: {}", - su_bin, why - ); - } - } - - /* - match symlink("/sbin/su", su_bin) { - Ok(_) => {} - Err(why) => { - println!("rusty-magisk: Failed to symlink for {}: {}", su_bin, why); - } - } - */ - } -} - pub fn early_mode() -> bool { if env::var("ANDROID_BOOTLOGO").is_err() || !Path::new("/etc").exists() { true diff --git a/vendorsetup.sh b/vendorsetup.sh new file mode 100644 index 0000000..1e612ad --- /dev/null +++ b/vendorsetup.sh @@ -0,0 +1,7 @@ +### Incomplete + +# Define vars +aosp_root="$(pwd)" +project_root="${aosp_root}/vendor/rusty-magisk" + +# Patch files