mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-22 04:38:29 +00:00
Move MagiskInit::check_two_stage to rust
This commit is contained in:
parent
823e31a91b
commit
2aa7f1c094
@ -191,18 +191,3 @@ void BootConfig::init() noexcept {
|
|||||||
LOGD("Device config:\n");
|
LOGD("Device config:\n");
|
||||||
print();
|
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");
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
use crate::ffi::{BootConfig, MagiskInit};
|
||||||
|
use base::{cstr, debug, BytesExt, FsPath, MappedFile, Utf8CStr};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use base::debug;
|
|
||||||
use crate::ffi::BootConfig;
|
|
||||||
|
|
||||||
impl BootConfig {
|
impl BootConfig {
|
||||||
pub(crate) fn print(&self) {
|
pub(crate) fn print(&self) {
|
||||||
@ -10,11 +10,29 @@ impl BootConfig {
|
|||||||
unsafe {
|
unsafe {
|
||||||
debug!("slot=[{:?}]", CStr::from_ptr(self.slot.as_ptr()));
|
debug!("slot=[{:?}]", CStr::from_ptr(self.slot.as_ptr()));
|
||||||
debug!("dt_dir=[{:?}]", CStr::from_ptr(self.dt_dir.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=[{:?}]", 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!("emulator=[{}]", self.emulator);
|
||||||
debug!("partition_map=[{:?}]", self.partition_map);
|
debug!("partition_map=[{:?}]", self.partition_map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -88,6 +88,5 @@ pub mod ffi {
|
|||||||
unsafe fn patch_sepolicy(self: &MagiskInit, in_: *const c_char, out: *const c_char);
|
unsafe fn patch_sepolicy(self: &MagiskInit, in_: *const c_char, out: *const c_char);
|
||||||
fn hijack_sepolicy(self: &mut MagiskInit) -> bool;
|
fn hijack_sepolicy(self: &mut MagiskInit) -> bool;
|
||||||
fn backup_init(self: &MagiskInit) -> *const c_char;
|
fn backup_init(self: &MagiskInit) -> *const c_char;
|
||||||
fn check_two_stage(self: &MagiskInit) -> bool;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user