mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 20:45:24 +00:00
Use Rust for formatting
The fprintf implementation included in crt0 is too rudimental
This commit is contained in:
parent
0ccd6e7381
commit
be433fa667
@ -1,13 +1,26 @@
|
|||||||
|
#![feature(format_args_nl)]
|
||||||
|
|
||||||
use logging::setup_klog;
|
use logging::setup_klog;
|
||||||
|
use rootdir::inject_magisk_rc;
|
||||||
// Has to be pub so all symbols in that crate is included
|
// Has to be pub so all symbols in that crate is included
|
||||||
pub use magiskpolicy;
|
pub use magiskpolicy;
|
||||||
|
|
||||||
mod logging;
|
mod logging;
|
||||||
|
mod rootdir;
|
||||||
|
|
||||||
#[cxx::bridge]
|
#[cxx::bridge]
|
||||||
pub mod ffi {
|
pub mod ffi {
|
||||||
#[namespace = "rust"]
|
#[namespace = "rust"]
|
||||||
extern "Rust" {
|
extern "Rust" {
|
||||||
fn setup_klog();
|
fn setup_klog();
|
||||||
|
fn inject_magisk_rc(fd: i32, tmp_dir: Utf8CStrRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe extern "C++" {
|
||||||
|
include!("../base/include/base.hpp");
|
||||||
|
|
||||||
|
#[namespace = "rust"]
|
||||||
|
#[cxx_name = "Utf8CStr"]
|
||||||
|
type Utf8CStrRef<'a> = base::ffi::Utf8CStrRef<'a>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,24 +77,7 @@ static void patch_rc_scripts(const char *src_path, const char *tmp_path, bool wr
|
|||||||
rc_list.clear();
|
rc_list.clear();
|
||||||
|
|
||||||
// Inject Magisk rc scripts
|
// Inject Magisk rc scripts
|
||||||
LOGD("Inject magisk rc\n");
|
rust::inject_magisk_rc(fileno(dest.get()), tmp_path);
|
||||||
fprintf(dest.get(), R"EOF(
|
|
||||||
on post-fs-data
|
|
||||||
start logd
|
|
||||||
exec %2$s 0 0 -- %1$s/magisk --post-fs-data
|
|
||||||
|
|
||||||
on property:vold.decrypt=trigger_restart_framework
|
|
||||||
exec %2$s 0 0 -- %1$s/magisk --service
|
|
||||||
|
|
||||||
on nonencrypted
|
|
||||||
exec %2$s 0 0 -- %1$s/magisk --service
|
|
||||||
|
|
||||||
on property:sys.boot_completed=1
|
|
||||||
exec %2$s 0 0 -- %1$s/magisk --boot-complete
|
|
||||||
|
|
||||||
on property:init.svc.zygote=stopped
|
|
||||||
exec %2$s 0 0 -- %1$s/magisk --zygote-restart
|
|
||||||
)EOF", tmp_path, MAGISK_PROC_CON);
|
|
||||||
|
|
||||||
fclone_attr(fileno(src.get()), fileno(dest.get()));
|
fclone_attr(fileno(src.get()), fileno(dest.get()));
|
||||||
}
|
}
|
||||||
|
37
native/src/init/rootdir.rs
Normal file
37
native/src/init/rootdir.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::mem;
|
||||||
|
use std::os::fd::{FromRawFd, RawFd};
|
||||||
|
|
||||||
|
use base::{debug, Utf8CStr};
|
||||||
|
|
||||||
|
pub fn inject_magisk_rc(fd: RawFd, tmp_dir: &Utf8CStr) {
|
||||||
|
debug!("Injecting magisk rc");
|
||||||
|
|
||||||
|
let mut file = unsafe { File::from_raw_fd(fd) };
|
||||||
|
|
||||||
|
write!(
|
||||||
|
file,
|
||||||
|
r#"
|
||||||
|
on post-fs-data
|
||||||
|
start logd
|
||||||
|
exec {1} 0 0 -- {0}/magisk --post-fs-data
|
||||||
|
|
||||||
|
on property:vold.decrypt=trigger_restart_framework
|
||||||
|
exec {1} 0 0 -- {0}/magisk --service
|
||||||
|
|
||||||
|
on nonencrypted
|
||||||
|
exec {1} 0 0 -- {0}/magisk --service
|
||||||
|
|
||||||
|
on property:sys.boot_completed=1
|
||||||
|
exec {1} 0 0 -- {0}/magisk --boot-complete
|
||||||
|
|
||||||
|
on property:init.svc.zygote=stopped
|
||||||
|
exec {1} 0 0 -- {0}/magisk --zygote-restart
|
||||||
|
"#,
|
||||||
|
tmp_dir, "u:r:magisk:s0"
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
mem::forget(file)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user