122 lines
3.3 KiB
Rust
Raw Normal View History

#![feature(format_args_nl)]
#![feature(try_blocks)]
2024-07-16 22:58:11 +08:00
#![feature(let_chains)]
2023-05-30 22:23:11 -07:00
#![allow(clippy::missing_safety_doc)]
2023-06-12 05:59:50 -07:00
use base::Utf8CStr;
2023-06-22 02:23:27 -07:00
use cert::read_certificate;
use daemon::{daemon_entry, find_apk_path, get_magiskd, MagiskD};
2023-11-04 23:59:11 -07:00
use logging::{
android_logging, magisk_logging, zygisk_close_logd, zygisk_get_logd, zygisk_logging,
};
2024-08-14 21:36:15 +08:00
use mount::{find_preinit_device, revert_unmount, setup_mounts, clean_mounts};
2023-09-06 15:52:14 -07:00
use resetprop::{persist_delete_prop, persist_get_prop, persist_get_props, persist_set_prop};
2022-07-05 21:13:09 -07:00
mod cert;
2023-05-23 21:30:30 -07:00
#[path = "../include/consts.rs"]
mod consts;
2023-05-09 18:54:38 -07:00
mod daemon;
2022-07-05 21:13:09 -07:00
mod logging;
mod mount;
mod resetprop;
2022-07-01 04:53:41 -07:00
#[cxx::bridge]
pub mod ffi {
2023-11-17 13:35:50 -08:00
#[repr(i32)]
enum RequestCode {
START_DAEMON,
CHECK_VERSION,
CHECK_VERSION_CODE,
STOP_DAEMON,
_SYNC_BARRIER_,
SUPERUSER,
ZYGOTE_RESTART,
DENYLIST,
SQLITE_CMD,
REMOVE_MODULES,
ZYGISK,
_STAGE_BARRIER_,
POST_FS_DATA,
LATE_START,
BOOT_COMPLETE,
END,
}
2023-05-21 23:51:30 -07:00
extern "C++" {
2023-11-08 01:46:02 -08:00
include!("include/resetprop.hpp");
2023-09-06 15:52:14 -07:00
#[cxx_name = "prop_cb"]
type PropCb;
unsafe fn get_prop_rs(name: *const c_char, persist: bool) -> String;
unsafe fn prop_cb_exec(
cb: Pin<&mut PropCb>,
name: *const c_char,
value: *const c_char,
serial: u32,
);
2023-05-21 23:51:30 -07:00
}
2023-11-17 13:35:50 -08:00
unsafe extern "C++" {
2023-12-26 23:08:06 +08:00
#[namespace = "rust"]
#[cxx_name = "Utf8CStr"]
type Utf8CStrRef<'a> = base::ffi::Utf8CStrRef<'a>;
2023-12-03 19:32:58 +08:00
include!("include/daemon.hpp");
2023-12-26 23:08:06 +08:00
#[cxx_name = "get_magisk_tmp_rs"]
fn get_magisk_tmp() -> Utf8CStrRef<'static>;
#[cxx_name = "resolve_preinit_dir_rs"]
fn resolve_preinit_dir(base_dir: Utf8CStrRef) -> String;
2023-11-17 13:35:50 -08:00
fn switch_mnt_ns(pid: i32) -> i32;
2023-11-17 13:35:50 -08:00
#[cxx_name = "MagiskD"]
type CxxMagiskD;
2023-11-27 17:40:58 +08:00
fn post_fs_data(self: &CxxMagiskD) -> bool;
2023-11-17 13:35:50 -08:00
fn late_start(self: &CxxMagiskD);
fn boot_complete(self: &CxxMagiskD);
}
2022-07-01 04:53:41 -07:00
extern "Rust" {
fn rust_test_entry();
2022-07-05 21:13:09 -07:00
fn android_logging();
fn magisk_logging();
fn zygisk_logging();
2023-11-04 23:59:11 -07:00
fn zygisk_close_logd();
fn zygisk_get_logd() -> i32;
2023-12-26 23:08:06 +08:00
fn find_apk_path(pkg: Utf8CStrRef, data: &mut [u8]) -> usize;
2023-06-16 02:33:01 -07:00
fn read_certificate(fd: i32, version: i32) -> Vec<u8>;
fn setup_mounts();
2024-08-14 21:36:15 +08:00
fn clean_mounts();
fn find_preinit_device() -> String;
fn revert_unmount(pid: i32);
2023-12-26 23:08:06 +08:00
unsafe fn persist_get_prop(name: Utf8CStrRef, prop_cb: Pin<&mut PropCb>);
2023-09-06 15:52:14 -07:00
unsafe fn persist_get_props(prop_cb: Pin<&mut PropCb>);
2023-12-26 23:08:06 +08:00
unsafe fn persist_delete_prop(name: Utf8CStrRef) -> bool;
unsafe fn persist_set_prop(name: Utf8CStrRef, value: Utf8CStrRef) -> bool;
2022-07-05 21:13:09 -07:00
}
2023-05-16 02:09:05 -07:00
#[namespace = "rust"]
2023-05-09 18:54:38 -07:00
extern "Rust" {
fn daemon_entry();
type MagiskD;
fn get_magiskd() -> &'static MagiskD;
fn setup_logfile(self: &MagiskD);
fn is_emulator(self: &MagiskD) -> bool;
2023-11-15 15:44:43 -08:00
fn is_recovery(self: &MagiskD) -> bool;
2023-11-17 13:35:50 -08:00
fn boot_stage_handler(self: &MagiskD, client: i32, code: i32);
2023-05-09 18:54:38 -07:00
}
}
2022-07-01 04:53:41 -07:00
fn rust_test_entry() {}
2023-05-21 23:51:30 -07:00
2023-06-12 05:59:50 -07:00
pub fn get_prop(name: &Utf8CStr, persist: bool) -> String {
2023-05-21 23:51:30 -07:00
unsafe { ffi::get_prop_rs(name.as_ptr(), persist) }
}