mirror of
https://github.com/topjohnwu/Magisk.git
synced 2026-01-17 07:12:32 -08:00
Migration to Edition 2024
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::gen::gen_cxx_binding;
|
||||
use crate::codegen::gen_cxx_binding;
|
||||
|
||||
#[path = "../include/gen.rs"]
|
||||
mod gen;
|
||||
#[path = "../include/codegen.rs"]
|
||||
mod codegen;
|
||||
|
||||
fn main() {
|
||||
gen_cxx_binding("init-rs");
|
||||
|
||||
@@ -132,23 +132,25 @@ impl MagiskInit {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn main(
|
||||
argc: i32,
|
||||
argv: *mut *mut c_char,
|
||||
_envp: *const *const c_char,
|
||||
) -> i32 {
|
||||
umask(0);
|
||||
unsafe {
|
||||
umask(0);
|
||||
|
||||
let name = basename(*argv);
|
||||
let name = basename(*argv);
|
||||
|
||||
if CStr::from_ptr(name) == c"magisk" {
|
||||
return magisk_proxy_main(argc, argv);
|
||||
if CStr::from_ptr(name) == c"magisk" {
|
||||
return magisk_proxy_main(argc, argv);
|
||||
}
|
||||
|
||||
if getpid() == 1 {
|
||||
MagiskInit::new(argv).start().log_ok();
|
||||
}
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
if getpid() == 1 {
|
||||
MagiskInit::new(argv).start().log_ok();
|
||||
}
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use std::{
|
||||
ptr::null as nullptr,
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
unsafe extern "C" {
|
||||
static environ: *const *mut libc::c_char;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,31 @@ impl MagiskInit {
|
||||
self.restore_ramdisk_init();
|
||||
|
||||
// fallback to hexpatch if /sdcard exists
|
||||
if let Ok(mut map) = MappedFile::open_rw(cstr!("/init")) {
|
||||
match MappedFile::open_rw(cstr!("/init")) {
|
||||
Ok(mut map) => {
|
||||
let from = "/system/bin/init";
|
||||
let to = "/data/magiskinit";
|
||||
|
||||
// Redirect original init to magiskinit
|
||||
let v = map.patch(from.as_bytes(), to.as_bytes());
|
||||
#[allow(unused_variables)]
|
||||
for off in &v {
|
||||
debug!("Patch @ {:#010X} [{}] -> [{}]", off, from, to);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
error!("Failed to open /init for hexpatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn redirect_second_stage(&self) {
|
||||
let src = path!("/init");
|
||||
let dest = path!("/data/init");
|
||||
// Patch init binary
|
||||
match MappedFile::open(src) {
|
||||
Ok(mut map) => {
|
||||
let from = "/system/bin/init";
|
||||
let to = "/data/magiskinit";
|
||||
|
||||
@@ -85,33 +109,18 @@ impl MagiskInit {
|
||||
for off in &v {
|
||||
debug!("Patch @ {:#010X} [{}] -> [{}]", off, from, to);
|
||||
}
|
||||
} else {
|
||||
error!("Failed to open /init for hexpatch");
|
||||
match dest.create(O_CREAT | O_WRONLY, 0) {
|
||||
Ok(mut dest) => {
|
||||
dest.write_all(map.as_ref()).log_ok();
|
||||
}
|
||||
_ => {
|
||||
error!("Failed to create {}", dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn redirect_second_stage(&self) {
|
||||
let src = path!("/init");
|
||||
let dest = path!("/data/init");
|
||||
// Patch init binary
|
||||
if let Ok(mut map) = MappedFile::open(src) {
|
||||
let from = "/system/bin/init";
|
||||
let to = "/data/magiskinit";
|
||||
|
||||
// Redirect original init to magiskinit
|
||||
let v = map.patch(from.as_bytes(), to.as_bytes());
|
||||
#[allow(unused_variables)]
|
||||
for off in &v {
|
||||
debug!("Patch @ {:#010X} [{}] -> [{}]", off, from, to);
|
||||
_ => {
|
||||
error!("Failed to open {} for hexpatch", src);
|
||||
}
|
||||
if let Ok(mut dest) = dest.create(O_CREAT | O_WRONLY, 0) {
|
||||
dest.write_all(map.as_ref()).log_ok();
|
||||
} else {
|
||||
error!("Failed to create {}", dest);
|
||||
}
|
||||
} else {
|
||||
error!("Failed to open {} for hexpatch", src);
|
||||
}
|
||||
clone_attr(src, dest).log_ok();
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user