reformat code

This commit is contained in:
5ec1cff
2024-01-05 13:02:46 +08:00
parent 331b01b0f4
commit ad32c4efb0
10 changed files with 172 additions and 114 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ pub fn uid_should_umount(uid: i32) -> bool {
// TODO: signature
pub fn uid_is_manager(uid: i32) -> bool {
if let Ok(s) = rustix::fs::stat("/data/user_de/0/me.weishu.kernelsu") {
return s.st_uid == uid as u32
return s.st_uid == uid as u32;
}
false
}
+30 -14
View File
@@ -1,5 +1,5 @@
use std::process::{Command, Stdio};
use crate::constants::MIN_MAGISK_VERSION;
use std::process::{Command, Stdio};
const MAGISK_VANILLA: &str = "com.topjohnwu.magisk";
const MAGISK_ALPHA: &str = "io.github.vvb2060.magisk";
@@ -15,21 +15,25 @@ pub fn get_magisk() -> Option<Version> {
Command::new("magisk")
.arg("-v")
.stdout(Stdio::piped())
.spawn().ok()
.spawn()
.ok()
.and_then(|child| child.wait_with_output().ok())
.and_then(|output| String::from_utf8(output.stdout).ok())
.map(|version| {
if (version.contains("alpha")) {
if version.contains("alpha") {
MAGISK_ALPHA
} else {
MAGISK_VANILLA
}
})
.map(|variant| { unsafe { VARIANT = variant }; });
.map(|variant| {
unsafe { VARIANT = variant };
});
let version: Option<i32> = Command::new("magisk")
.arg("-V")
.stdout(Stdio::piped())
.spawn().ok()
.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());
@@ -45,19 +49,24 @@ pub fn get_magisk() -> Option<Version> {
pub fn uid_granted_root(uid: i32) -> bool {
Command::new("magisk")
.arg("--sqlite")
.arg(format!("select 1 from policies where uid={uid} and policy=2 limit 1"))
.arg(format!(
"select 1 from policies where uid={uid} and policy=2 limit 1"
))
.stdout(Stdio::piped())
.spawn().ok()
.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)
.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())
.spawn().ok()
.spawn()
.ok()
.and_then(|child| child.wait_with_output().ok())
.and_then(|output| String::from_utf8(output.stdout).ok());
let line = match output {
@@ -73,12 +82,16 @@ pub fn uid_should_umount(uid: i32) -> bool {
};
Command::new("magisk")
.arg("--sqlite")
.arg(format!("select 1 from denylist where package_name=\"{pkg}\" limit 1"))
.arg(format!(
"select 1 from denylist where package_name=\"{pkg}\" limit 1"
))
.stdout(Stdio::piped())
.spawn().ok()
.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)
.map(|output| output.is_empty())
== Some(false)
}
// TODO: signature
@@ -86,9 +99,12 @@ pub fn uid_should_umount(uid: i32) -> bool {
pub fn uid_is_manager(uid: i32) -> bool {
let output = Command::new("magisk")
.arg("--sqlite")
.arg(format!("select value from strings where key=\"requester\" limit 1"))
.arg(format!(
"select value from strings where key=\"requester\" limit 1"
))
.stdout(Stdio::piped())
.spawn().ok()
.spawn()
.ok()
.and_then(|child| child.wait_with_output().ok())
.and_then(|output| String::from_utf8(output.stdout).ok())
.map(|output| output.trim().to_string());
+12 -14
View File
@@ -20,21 +20,19 @@ pub fn setup() {
let impl_ = match (ksu_version, magisk_version) {
(None, None) => RootImpl::None,
(Some(_), Some(_)) => RootImpl::Multiple,
(Some(ksu_version), None) => {
match ksu_version {
kernelsu::Version::Supported => RootImpl::KernelSU,
kernelsu::Version::TooOld => RootImpl::TooOld,
kernelsu::Version::Abnormal => RootImpl::Abnormal,
}
}
(None, Some(magisk_version)) => {
match magisk_version {
magisk::Version::Supported => RootImpl::Magisk,
magisk::Version::TooOld => RootImpl::TooOld,
}
}
(Some(ksu_version), None) => match ksu_version {
kernelsu::Version::Supported => RootImpl::KernelSU,
kernelsu::Version::TooOld => RootImpl::TooOld,
kernelsu::Version::Abnormal => RootImpl::Abnormal,
},
(None, Some(magisk_version)) => match magisk_version {
magisk::Version::Supported => RootImpl::Magisk,
magisk::Version::TooOld => RootImpl::TooOld,
},
};
unsafe { ROOT_IMPL = impl_; }
unsafe {
ROOT_IMPL = impl_;
}
}
pub fn get_impl() -> &'static RootImpl {