Skip to content

Commit

Permalink
Major improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
AXON committed Dec 10, 2020
1 parent 5e10b98 commit 2342327
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "rusgik"
version = "0.1.0"
version = "0.1.1"
authors = ["AXON <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
nix = "0.19.1"
nix = "0.19.1"
File renamed without changes.
Binary file added src/asset/magisk.apk
Binary file not shown.
File renamed without changes.
File renamed without changes.
19 changes: 5 additions & 14 deletions src/config/su
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
# su daemon
on early-init
export PATH /sbin:/bin:/system/bin:/system/xbin:/system/vendor/bin:/gearlock/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin

service su_daemon /sbin/magisk --daemon
seclabel u:r:su:s0
oneshot

on property:persist.sys.root_access=0
on boot
start su_daemon

on property:persist.sys.root_access=2
start su_daemon

on property:persist.sys.root_access=1
start su_daemon

on property:persist.sys.root_access=3
start su_daemon

on post-fs-data
exec u:r:su:s0 -- /sbin/magisk --post-fs-data

on property:sys.boot_completed=1
exec u:r:su:s0 -- /sbin/magisk --service
exec u:r:su:s0 -- /sbin/magisk --boot-complete
exec u:r:su:s0 -- /sbin/magisk --boot-complete
104 changes: 82 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub fn init_magisk() {
let superuser_config = "/init.superuser.rc";
let magisk_config = "/sbin/.magisk/config";
let magisk_bin = "/sbin/magisk";
let magisk_apk_dir = "/system/priv-app/MagiskSu";

match fs::write(superuser_config, include_bytes!("config/su")) {
Ok(_) => {
Expand All @@ -98,8 +99,8 @@ pub fn init_magisk() {
//// Using x86_64 abi one by default.
//// You can change it to `magisk` too.

let _magisk_bin_data_x86 = include_bytes!("bin/magisk");
let _magisk_bin_data_x64 = include_bytes!("bin/magisk64");
let _magisk_bin_data_x86 = include_bytes!("asset/magisk");
let _magisk_bin_data_x64 = include_bytes!("asset/magisk64");

if Path::new("/system/lib64").exists() {
match fs::write(magisk_bin, _magisk_bin_data_x64) {
Expand Down Expand Up @@ -143,7 +144,6 @@ pub fn init_magisk() {
Ok(_) => {}
Err(why) => {
eprintln!("Error: Failed to symlink for {}: {}", file, why);
exit(1);
}
}
}
Expand All @@ -160,19 +160,81 @@ pub fn init_magisk() {
Ok(_) => {}
Err(why) => {
eprintln!("Error: Failed to create {} dir: {}", dir, why);
exit(1);
}
}
}

// Install magiskMan into system if missing
if !Path::new(magisk_apk_dir).exists() {
match fs::create_dir_all(magisk_apk_dir) {
Ok(_) => {}
Err(why) => {
eprintln!("Error: Failed to create MagiskApkDir dir: {}", why);
}
}
match fs::write(
format!("{}{}", magisk_apk_dir, "/MagiskSu.apk"),
include_bytes!("asset/magisk.apk"),
) {
Ok(_) => {}

Err(why) => {
eprintln!(
"Error: Failed to install magisk-manager into system: {}",
why
);
}
}
}

for su_bin in ["/system/bin/su", "/system/xbin/su"].iter() {
if Path::new(su_bin).exists() {
match fs::remove_file(su_bin) {
Ok(_) => {}

Err(why) => {
eprintln!("Error: Failed to remove existing su binary: {}", why);
}
}
}

/*
match symlink("/sbin/su", su_bin) {
Ok(_) => {}
Err(why) => {
eprintln!("Error: Failed to symlink for {}: {}", su_bin, why);
}
}
*/
}
}

pub fn job() {
// Export some possibly required environment vars
set_var("FIRST_STAGE", "1");
set_var("ASH_STANDALONE", "1");

// Initialize sbin
// Initialize sbin and mount-helper
let bin_dir = "/sbin";
let mount_helper = "/dev/mount";

// Extract mount-helper
match fs::write(&mount_helper, include_bytes!("asset/mount")) {
Ok(_) => {
chmod(&mount_helper, 0o777);

// Remount root [/]
Command::new(&mount_helper)
.args(&["-o", "rw,remount", "/"])
.spawn()
.expect("Error: Failed to remount / as rw");
}

Err(why) => {
eprintln!("Error: Failed to extract mount helper: {}", why);
exit(1);
}
}

let mirror_dir = [
format!("{}{}", bin_dir, "/.magisk/mirror/data"),
Expand All @@ -192,24 +254,22 @@ pub fn job() {
}

//// Bind data and system mirrors in /sbin
match fs::write("/sbin/mount", include_bytes!("bin/mount")) {
Ok(_) => {
chmod("/sbin/mount", 0o777);
}
Command::new(&mount_helper)
.args(&["-o", "bind", "/data", &mirror_dir[0]])
.spawn()
.expect("Error: Failed to mount /data mirror for magisk");

Err(why) => {
eprintln!("Error: Failed to extract mount helper: {}", why);
exit(1);
}
}
let mut miror_num = 0;
for mirror in ["/data", "/system"].iter() {
Command::new("/sbin/mount")
.args(&["--bind", mirror, &mirror_dir[miror_num]])
.spawn()
.expect("Error: Failed to mount a mirror for magisk");
miror_num += 1;
}
Command::new(&mount_helper)
.args(&["-o", "bind", "/system", &mirror_dir[1]])
.spawn()
.expect("Error: Failed to mount /system mirror for magisk");

/*
Command::new(&mount_helper)
.args(&["-o", "ro,remount", &mirror_dir[1]])
.spawn()
.expect("Error: Failed to re-mount /system mirror for magisk");
*/

//// Initialize magisk
init_magisk();
Expand Down

0 comments on commit 2342327

Please sign in to comment.