You've already forked ReZygisk
mirror of
https://github.com/PerformanC/ReZygisk.git
synced 2025-09-06 06:37:01 +00:00
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use std::process::{Command, Stdio};
|
|
use crate::constants::MIN_MAGISK_VERSION;
|
|
|
|
pub enum Version {
|
|
Supported,
|
|
TooOld,
|
|
}
|
|
|
|
pub fn get_magisk() -> Option<Version> {
|
|
let version: Option<i32> = Command::new("magisk")
|
|
.arg("-V")
|
|
.stdout(Stdio::piped())
|
|
.spawn().ok()
|
|
.and_then(|child| child.wait_with_output().ok())
|
|
.and_then(|output| String::from_utf8(output.stdout).ok())
|
|
.and_then(|output| output.trim().parse().ok());
|
|
version.map(|version| {
|
|
if version >= MIN_MAGISK_VERSION {
|
|
Version::Supported
|
|
} else {
|
|
Version::TooOld
|
|
}
|
|
})
|
|
}
|
|
|
|
#[inline(never)]
|
|
pub fn uid_on_allowlist(uid: i32) -> bool {
|
|
let output: Option<String> = Command::new("magisk")
|
|
.arg("--sqlite")
|
|
.arg("select uid from policies where policy=2")
|
|
.stdout(Stdio::piped())
|
|
.spawn().ok()
|
|
.and_then(|child| child.wait_with_output().ok())
|
|
.and_then(|output| String::from_utf8(output.stdout).ok());
|
|
let lines = match &output {
|
|
Some(output) => output.lines(),
|
|
None => return false,
|
|
};
|
|
lines.into_iter().any(|line| {
|
|
line.trim().strip_prefix("uid=").and_then(|uid| uid.parse().ok()) == Some(uid)
|
|
})
|
|
}
|
|
|
|
#[inline(never)]
|
|
pub fn uid_on_denylist(uid: i32) -> bool {
|
|
// TODO: uid_on_denylist
|
|
return false;
|
|
}
|