From cce8e6686f6337de53eb88ec5a1906cffe0ffdae Mon Sep 17 00:00:00 2001 From: Nullptr Date: Tue, 28 Feb 2023 20:48:32 +0800 Subject: [PATCH] Implement uid_on_allowlist for Magisk --- zygiskd/src/root_impl/magisk.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/zygiskd/src/root_impl/magisk.rs b/zygiskd/src/root_impl/magisk.rs index c802d5ed..7d51f77d 100644 --- a/zygiskd/src/root_impl/magisk.rs +++ b/zygiskd/src/root_impl/magisk.rs @@ -24,8 +24,20 @@ pub fn get_magisk() -> Option { } pub fn uid_on_allowlist(uid: i32) -> bool { - // TODO: uid_on_allowlist - return false; + let output: Option = 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 {