Implement uid_on_allowlist for Magisk

This commit is contained in:
Nullptr
2023-02-28 20:48:32 +08:00
parent ff2658f2de
commit cce8e6686f

View File

@@ -24,8 +24,20 @@ pub fn get_magisk() -> Option<Version> {
}
pub fn uid_on_allowlist(uid: i32) -> bool {
// TODO: uid_on_allowlist
return false;
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)
})
}
pub fn uid_on_denylist(uid: i32) -> bool {