diff --git a/native/src/init/getinfo.cpp b/native/src/init/getinfo.cpp index d56d742c5..b0799c443 100644 --- a/native/src/init/getinfo.cpp +++ b/native/src/init/getinfo.cpp @@ -191,18 +191,3 @@ void BootConfig::init() noexcept { LOGD("Device config:\n"); print(); } - -bool MagiskInit::check_two_stage() const noexcept { - if (access("/first_stage_ramdisk", F_OK) == 0) - return true; - if (access("/second_stage_resources", F_OK) == 0) - return true; - if (access("/system/bin/init", F_OK) == 0) - return true; - // Use the apex folder to determine whether 2SI (Android 10+) - if (access("/apex", F_OK) == 0) - return true; - // If we still have no indication, parse the original init and see what's up - mmap_data init(backup_init()); - return init.contains("selinux_setup"); -} diff --git a/native/src/init/getinfo.rs b/native/src/init/getinfo.rs index 7c3030144..fc1f57052 100644 --- a/native/src/init/getinfo.rs +++ b/native/src/init/getinfo.rs @@ -1,6 +1,6 @@ +use crate::ffi::{BootConfig, MagiskInit}; +use base::{cstr, debug, BytesExt, FsPath, MappedFile, Utf8CStr}; use std::ffi::CStr; -use base::debug; -use crate::ffi::BootConfig; impl BootConfig { pub(crate) fn print(&self) { @@ -10,11 +10,29 @@ impl BootConfig { unsafe { debug!("slot=[{:?}]", CStr::from_ptr(self.slot.as_ptr())); debug!("dt_dir=[{:?}]", CStr::from_ptr(self.dt_dir.as_ptr())); - debug!("fstab_suffix=[{:?}]", CStr::from_ptr(self.fstab_suffix.as_ptr())); + debug!( + "fstab_suffix=[{:?}]", + CStr::from_ptr(self.fstab_suffix.as_ptr()) + ); debug!("hardware=[{:?}]", CStr::from_ptr(self.hardware.as_ptr())); - debug!("hardware.platform=[{:?}]", CStr::from_ptr(self.hardware_plat.as_ptr())); + debug!( + "hardware.platform=[{:?}]", + CStr::from_ptr(self.hardware_plat.as_ptr()) + ); } debug!("emulator=[{}]", self.emulator); debug!("partition_map=[{:?}]", self.partition_map); } -} \ No newline at end of file +} + +impl MagiskInit { + pub(crate) fn check_two_stage(&self) -> bool { + FsPath::from(cstr!("/first_stage_ramdisk")).exists() || + FsPath::from(cstr!("/second_stage_resources")).exists() || + FsPath::from(cstr!("/system/bin/init")).exists() || + // Use the apex folder to determine whether 2SI (Android 10+) + FsPath::from(cstr!("/apex")).exists() || + // If we still have no indication, parse the original init and see what's up + MappedFile::open(unsafe { Utf8CStr::from_ptr_unchecked(self.backup_init()) }).map(|map| map.contains(b"selinux_setup")).unwrap_or(false) + } +} diff --git a/native/src/init/lib.rs b/native/src/init/lib.rs index f6feb7c78..b801bc655 100644 --- a/native/src/init/lib.rs +++ b/native/src/init/lib.rs @@ -88,6 +88,5 @@ pub mod ffi { unsafe fn patch_sepolicy(self: &MagiskInit, in_: *const c_char, out: *const c_char); fn hijack_sepolicy(self: &mut MagiskInit) -> bool; fn backup_init(self: &MagiskInit) -> *const c_char; - fn check_two_stage(self: &MagiskInit) -> bool; } }