Magisk/native/src/init/getinfo.rs

51 lines
1.8 KiB
Rust
Raw Normal View History

2025-02-14 23:52:56 -08:00
use crate::ffi::{backup_init, BootConfig, MagiskInit};
2025-03-03 02:15:06 -08:00
use base::{path, BytesExt, MappedFile};
2025-01-30 21:59:42 +08:00
impl BootConfig {
2025-03-03 02:15:06 -08:00
#[allow(unused_imports, unused_unsafe)]
2025-01-30 21:59:42 +08:00
pub(crate) fn print(&self) {
2025-03-03 02:15:06 -08:00
use base::{debug, Utf8CStr};
2025-01-30 21:59:42 +08:00
debug!("skip_initramfs=[{}]", self.skip_initramfs);
debug!("force_normal_boot=[{}]", self.force_normal_boot);
debug!("rootwait=[{}]", self.rootwait);
unsafe {
debug!(
2025-03-03 02:15:06 -08:00
"slot=[{}]",
Utf8CStr::from_ptr_unchecked(self.slot.as_ptr())
);
debug!(
2025-03-03 02:15:06 -08:00
"dt_dir=[{}]",
Utf8CStr::from_ptr_unchecked(self.dt_dir.as_ptr())
);
debug!(
"fstab_suffix=[{}]",
Utf8CStr::from_ptr_unchecked(self.fstab_suffix.as_ptr())
);
debug!(
"hardware=[{}]",
Utf8CStr::from_ptr_unchecked(self.hardware.as_ptr())
);
debug!(
"hardware.platform=[{}]",
Utf8CStr::from_ptr_unchecked(self.hardware_plat.as_ptr())
);
2025-01-30 21:59:42 +08:00
}
debug!("emulator=[{}]", self.emulator);
debug!("partition_map=[{:?}]", self.partition_map);
}
}
impl MagiskInit {
pub(crate) fn check_two_stage(&self) -> bool {
2025-02-17 01:46:19 -08:00
path!("/first_stage_ramdisk").exists() ||
path!("/second_stage_resources").exists() ||
path!("/system/bin/init").exists() ||
// Use the apex folder to determine whether 2SI (Android 10+)
2025-02-17 01:46:19 -08:00
path!("/apex").exists() ||
// If we still have no indication, parse the original init and see what's up
2025-02-14 23:52:56 -08:00
MappedFile::open(backup_init())
.map(|data| data.contains(b"selinux_setup"))
.unwrap_or(false)
}
}