Implement uid_should_umount for magisk

This commit is contained in:
Nullptr
2023-10-22 00:23:12 +08:00
parent 4587e39964
commit abbca19c82

View File

@@ -24,23 +24,40 @@ pub fn get_magisk() -> Option<Version> {
} }
pub fn uid_granted_root(uid: i32) -> bool { pub fn uid_granted_root(uid: i32) -> bool {
let output: Option<String> = Command::new("magisk") Command::new("magisk")
.arg("--sqlite") .arg("--sqlite")
.arg("select uid from policies where policy=2") .arg(format!("select 1 from policies where uid={uid} and policy=2 limit 1"))
.stdout(Stdio::piped())
.spawn().ok()
.and_then(|child| child.wait_with_output().ok())
.and_then(|output| String::from_utf8(output.stdout).ok())
.map(|output| output.is_empty()) == Some(false)
}
pub fn uid_should_umount(uid: i32) -> bool {
let output = Command::new("pm")
.args(["list", "packages", "--uid", &uid.to_string()])
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.spawn().ok() .spawn().ok()
.and_then(|child| child.wait_with_output().ok()) .and_then(|child| child.wait_with_output().ok())
.and_then(|output| String::from_utf8(output.stdout).ok()); .and_then(|output| String::from_utf8(output.stdout).ok());
let lines = match &output { let line = match output {
Some(output) => output.lines(), Some(line) => line,
None => return false, None => return false,
}; };
lines.into_iter().any(|line| { let pkg = line
line.trim().strip_prefix("uid=").and_then(|uid| uid.parse().ok()) == Some(uid) .strip_prefix("package:")
}) .and_then(|line| line.split(' ').next());
} let pkg = match pkg {
Some(pkg) => pkg,
pub fn uid_should_umount(uid: i32) -> bool { None => return false,
// TODO: uid_should_umount };
return false; Command::new("magisk")
.arg("--sqlite")
.arg(format!("select 1 from denylist where package_name=\"{pkg}\" limit 1"))
.stdout(Stdio::piped())
.spawn().ok()
.and_then(|child| child.wait_with_output().ok())
.and_then(|output| String::from_utf8(output.stdout).ok())
.map(|output| output.is_empty()) == Some(false)
} }