mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-12 12:03:37 +00:00
Add more functionality into Rust
This commit is contained in:
parent
0d31d356ef
commit
7098248c64
9
build.py
9
build.py
@ -219,8 +219,6 @@ def run_ndk_build(cmds: list):
|
|||||||
|
|
||||||
|
|
||||||
def build_cpp_src(targets: set):
|
def build_cpp_src(targets: set):
|
||||||
dump_flag_header()
|
|
||||||
|
|
||||||
cmds = []
|
cmds = []
|
||||||
clean = False
|
clean = False
|
||||||
|
|
||||||
@ -336,7 +334,11 @@ def dump_flag_header():
|
|||||||
flag_txt += f"#define MAGISK_DEBUG {0 if args.release else 1}\n"
|
flag_txt += f"#define MAGISK_DEBUG {0 if args.release else 1}\n"
|
||||||
|
|
||||||
native_gen_path.mkdir(mode=0o755, parents=True, exist_ok=True)
|
native_gen_path.mkdir(mode=0o755, parents=True, exist_ok=True)
|
||||||
write_if_diff(Path(native_gen_path, "flags.h"), flag_txt)
|
write_if_diff(native_gen_path / "flags.h", flag_txt)
|
||||||
|
|
||||||
|
rust_flag_txt = f'pub const MAGISK_VERSION: &str = "{config["version"]}";\n'
|
||||||
|
rust_flag_txt += f'pub const MAGISK_VER_CODE: i32 = {config["versionCode"]};\n'
|
||||||
|
write_if_diff(native_gen_path / "flags.rs", rust_flag_txt)
|
||||||
|
|
||||||
|
|
||||||
def build_native():
|
def build_native():
|
||||||
@ -363,6 +365,7 @@ def build_native():
|
|||||||
if ccache := shutil.which("ccache"):
|
if ccache := shutil.which("ccache"):
|
||||||
os.environ["NDK_CCACHE"] = ccache
|
os.environ["NDK_CCACHE"] = ccache
|
||||||
|
|
||||||
|
dump_flag_header()
|
||||||
build_rust_src(targets)
|
build_rust_src(targets)
|
||||||
build_cpp_src(targets)
|
build_cpp_src(targets)
|
||||||
|
|
||||||
|
@ -328,8 +328,7 @@ static void daemon_entry() {
|
|||||||
setcon(MAGISK_PROC_CON);
|
setcon(MAGISK_PROC_CON);
|
||||||
|
|
||||||
rust::daemon_entry();
|
rust::daemon_entry();
|
||||||
|
SDK_INT = MagiskD().sdk_int();
|
||||||
LOGI(NAME_WITH_VER(Magisk) " daemon started\n");
|
|
||||||
|
|
||||||
// Escape from cgroup
|
// Escape from cgroup
|
||||||
int pid = getpid();
|
int pid = getpid();
|
||||||
@ -343,23 +342,6 @@ static void daemon_entry() {
|
|||||||
// Get self stat
|
// Get self stat
|
||||||
xstat("/proc/self/exe", &self_st);
|
xstat("/proc/self/exe", &self_st);
|
||||||
|
|
||||||
// Get API level
|
|
||||||
parse_prop_file("/system/build.prop", [](auto key, auto val) -> bool {
|
|
||||||
if (key == "ro.build.version.sdk") {
|
|
||||||
SDK_INT = parse_int(val);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
if (SDK_INT < 0) {
|
|
||||||
// In case some devices do not store this info in build.prop, fallback to getprop
|
|
||||||
auto sdk = get_prop("ro.build.version.sdk");
|
|
||||||
if (!sdk.empty()) {
|
|
||||||
SDK_INT = parse_int(sdk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LOGI("* Device API level: %d\n", SDK_INT);
|
|
||||||
|
|
||||||
// Samsung workaround #7887
|
// Samsung workaround #7887
|
||||||
if (access("/system_ext/app/mediatek-res/mediatek-res.apk", F_OK) == 0) {
|
if (access("/system_ext/app/mediatek-res/mediatek-res.apk", F_OK) == 0) {
|
||||||
set_prop("ro.vendor.mtk_model", "0");
|
set_prop("ro.vendor.mtk_model", "0");
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
|
use crate::consts::{MAGISK_FULL_VER, MAIN_CONFIG};
|
||||||
|
use crate::db::Sqlite3;
|
||||||
|
use crate::ffi::{get_magisk_tmp, RequestCode};
|
||||||
|
use crate::get_prop;
|
||||||
|
use crate::logging::magisk_logging;
|
||||||
use base::libc::{O_CLOEXEC, O_RDONLY};
|
use base::libc::{O_CLOEXEC, O_RDONLY};
|
||||||
use base::{
|
use base::{
|
||||||
cstr, libc, open_fd, BufReadExt, Directory, FsPathBuf, ReadExt, ResultExt, Utf8CStr,
|
cstr, info, libc, open_fd, BufReadExt, Directory, FsPath, FsPathBuf, ReadExt, ResultExt,
|
||||||
Utf8CStrBuf, Utf8CStrBufArr, Utf8CStrBufRef, WalkResult,
|
Utf8CStr, Utf8CStrBuf, Utf8CStrBufArr, Utf8CStrBufRef, WalkResult,
|
||||||
};
|
};
|
||||||
use bytemuck::bytes_of;
|
use bytemuck::bytes_of;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
@ -9,12 +14,6 @@ use std::io;
|
|||||||
use std::io::{BufReader, Read, Write};
|
use std::io::{BufReader, Read, Write};
|
||||||
use std::sync::{Mutex, OnceLock};
|
use std::sync::{Mutex, OnceLock};
|
||||||
|
|
||||||
use crate::consts::MAIN_CONFIG;
|
|
||||||
use crate::db::Sqlite3;
|
|
||||||
use crate::ffi::{get_magisk_tmp, RequestCode};
|
|
||||||
use crate::get_prop;
|
|
||||||
use crate::logging::magisk_logging;
|
|
||||||
|
|
||||||
// Global magiskd singleton
|
// Global magiskd singleton
|
||||||
pub static MAGISKD: OnceLock<MagiskD> = OnceLock::new();
|
pub static MAGISKD: OnceLock<MagiskD> = OnceLock::new();
|
||||||
|
|
||||||
@ -45,19 +44,20 @@ pub struct MagiskD {
|
|||||||
pub logd: Mutex<Option<File>>,
|
pub logd: Mutex<Option<File>>,
|
||||||
pub sql_connection: Mutex<Option<Sqlite3>>,
|
pub sql_connection: Mutex<Option<Sqlite3>>,
|
||||||
boot_stage_lock: Mutex<BootStateFlags>,
|
boot_stage_lock: Mutex<BootStateFlags>,
|
||||||
is_emulator: bool,
|
sdk_int: i32,
|
||||||
|
pub is_emulator: bool,
|
||||||
is_recovery: bool,
|
is_recovery: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MagiskD {
|
impl MagiskD {
|
||||||
pub fn is_emulator(&self) -> bool {
|
|
||||||
self.is_emulator
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_recovery(&self) -> bool {
|
pub fn is_recovery(&self) -> bool {
|
||||||
self.is_recovery
|
self.is_recovery
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sdk_int(&self) -> i32 {
|
||||||
|
self.sdk_int
|
||||||
|
}
|
||||||
|
|
||||||
pub fn boot_stage_handler(&self, client: i32, code: i32) {
|
pub fn boot_stage_handler(&self, client: i32, code: i32) {
|
||||||
// Make sure boot stage execution is always serialized
|
// Make sure boot stage execution is always serialized
|
||||||
let mut state = self.boot_stage_lock.lock().unwrap();
|
let mut state = self.boot_stage_lock.lock().unwrap();
|
||||||
@ -117,7 +117,26 @@ pub fn daemon_entry() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut sdk_int = -1;
|
||||||
|
if let Ok(file) = FsPath::from(cstr!("/system/build.prop")).open(O_RDONLY | O_CLOEXEC) {
|
||||||
|
let mut file = BufReader::new(file);
|
||||||
|
file.foreach_props(|key, val| {
|
||||||
|
if key == "ro.build.version.sdk" {
|
||||||
|
sdk_int = val.parse::<i32>().unwrap_or(-1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if sdk_int < 0 {
|
||||||
|
// In case some devices do not store this info in build.prop, fallback to getprop
|
||||||
|
sdk_int = get_prop(cstr!("ro.build.version.sdk"), false)
|
||||||
|
.parse::<i32>()
|
||||||
|
.unwrap_or(-1);
|
||||||
|
}
|
||||||
|
|
||||||
let magiskd = MagiskD {
|
let magiskd = MagiskD {
|
||||||
|
sdk_int,
|
||||||
is_emulator,
|
is_emulator,
|
||||||
is_recovery,
|
is_recovery,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -125,6 +144,9 @@ pub fn daemon_entry() {
|
|||||||
magiskd.start_log_daemon();
|
magiskd.start_log_daemon();
|
||||||
MAGISKD.set(magiskd).ok();
|
MAGISKD.set(magiskd).ok();
|
||||||
magisk_logging();
|
magisk_logging();
|
||||||
|
|
||||||
|
info!("Magisk {} daemon started", MAGISK_FULL_VER);
|
||||||
|
info!("* Device API level: {}", sdk_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_data() -> bool {
|
fn check_data() -> bool {
|
||||||
|
@ -232,7 +232,7 @@ impl MagiskD {
|
|||||||
DbEntryKey::SuMultiuserMode => MultiuserMode::default().repr,
|
DbEntryKey::SuMultiuserMode => MultiuserMode::default().repr,
|
||||||
DbEntryKey::SuMntNs => MntNsMode::default().repr,
|
DbEntryKey::SuMntNs => MntNsMode::default().repr,
|
||||||
DbEntryKey::DenylistConfig => 0,
|
DbEntryKey::DenylistConfig => 0,
|
||||||
DbEntryKey::ZygiskConfig => self.is_emulator() as i32,
|
DbEntryKey::ZygiskConfig => self.is_emulator as i32,
|
||||||
DbEntryKey::BootloopCount => 0,
|
DbEntryKey::BootloopCount => 0,
|
||||||
_ => -1,
|
_ => -1,
|
||||||
};
|
};
|
||||||
@ -251,7 +251,7 @@ impl MagiskD {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_db_settings(&self, cfg: &mut DbSettings) -> SqliteResult {
|
pub fn get_db_settings(&self, cfg: &mut DbSettings) -> SqliteResult {
|
||||||
cfg.zygisk = self.is_emulator();
|
cfg.zygisk = self.is_emulator;
|
||||||
self.db_exec_with_rows("SELECT * FROM settings", &[], cfg)
|
self.db_exec_with_rows("SELECT * FROM settings", &[], cfg)
|
||||||
.sql_result()
|
.sql_result()
|
||||||
}
|
}
|
||||||
|
@ -182,6 +182,7 @@ pub mod ffi {
|
|||||||
type MagiskD;
|
type MagiskD;
|
||||||
fn setup_logfile(&self);
|
fn setup_logfile(&self);
|
||||||
fn is_recovery(&self) -> bool;
|
fn is_recovery(&self) -> bool;
|
||||||
|
fn sdk_int(&self) -> i32;
|
||||||
fn boot_stage_handler(&self, client: i32, code: i32);
|
fn boot_stage_handler(&self, client: i32, code: i32);
|
||||||
|
|
||||||
#[cxx_name = "get_db_settings"]
|
#[cxx_name = "get_db_settings"]
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
use base::const_format::concatcp;
|
use base::const_format::concatcp;
|
||||||
|
|
||||||
|
#[path = "../../out/generated/flags.rs"]
|
||||||
|
mod flags;
|
||||||
|
|
||||||
|
// versions
|
||||||
|
pub use flags::*;
|
||||||
|
pub const MAGISK_FULL_VER: &str = concatcp!(MAGISK_VERSION, "(", MAGISK_VER_CODE, ")");
|
||||||
|
|
||||||
pub const LOGFILE: &str = "/cache/magisk.log";
|
pub const LOGFILE: &str = "/cache/magisk.log";
|
||||||
|
|
||||||
// data paths
|
// data paths
|
||||||
|
Loading…
x
Reference in New Issue
Block a user