Skip to content

Commit

Permalink
refactor: bind-mount pre-existing su bins instead of wiping them out …
Browse files Browse the repository at this point in the history
…completely
  • Loading branch information
AXON committed Jan 20, 2021
1 parent b3ca6d6 commit 2820158
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
20 changes: 16 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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" {
Expand Down
22 changes: 0 additions & 22 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions vendorsetup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Incomplete

# Define vars
aosp_root="$(pwd)"
project_root="${aosp_root}/vendor/rusty-magisk"

# Patch files

0 comments on commit 2820158

Please # to comment.