Skip to content

Commit

Permalink
Implement uid_should_umount for magisk
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-TSNG committed Oct 21, 2023
1 parent 4587e39 commit abbca19
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions zygiskd/src/root_impl/magisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,40 @@ pub fn get_magisk() -> Option<Version> {
}

pub fn uid_granted_root(uid: i32) -> bool {
let output: Option<String> = Command::new("magisk")
Command::new("magisk")
.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());
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)
})
.and_then(|output| String::from_utf8(output.stdout).ok())
.map(|output| output.is_empty()) == Some(false)
}

pub fn uid_should_umount(uid: i32) -> bool {
// TODO: uid_should_umount
return false;
let output = Command::new("pm")
.args(["list", "packages", "--uid", &uid.to_string()])
.stdout(Stdio::piped())
.spawn().ok()
.and_then(|child| child.wait_with_output().ok())
.and_then(|output| String::from_utf8(output.stdout).ok());
let line = match output {
Some(line) => line,
None => return false,
};
let pkg = line
.strip_prefix("package:")
.and_then(|line| line.split(' ').next());
let pkg = match pkg {
Some(pkg) => pkg,
None => 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)
}

0 comments on commit abbca19

Please sign in to comment.