You've already forked ReZygisk
mirror of
https://github.com/PerformanC/ReZygisk.git
synced 2025-09-06 06:37:01 +00:00
Refine uid_is_manager
This commit is contained in:
@@ -472,7 +472,7 @@ public:
|
|||||||
} while (false);
|
} while (false);
|
||||||
updateStatus();
|
updateStatus();
|
||||||
} else {
|
} else {
|
||||||
LOGE("process %d received unknown status %s", pid,
|
LOGW("process %d received unknown status %s", pid,
|
||||||
parse_status(status).c_str());
|
parse_status(status).c_str());
|
||||||
}
|
}
|
||||||
process.erase(state);
|
process.erase(state);
|
||||||
@@ -595,7 +595,6 @@ void send_control_command(Command cmd) {
|
|||||||
.sun_family = AF_UNIX,
|
.sun_family = AF_UNIX,
|
||||||
.sun_path={0},
|
.sun_path={0},
|
||||||
};
|
};
|
||||||
zygiskd::Init(getenv("TMP_PATH"));
|
|
||||||
sprintf(addr.sun_path, "%s/%s", zygiskd::GetTmpPath().c_str(), SOCKET_NAME);
|
sprintf(addr.sun_path, "%s/%s", zygiskd::GetTmpPath().c_str(), SOCKET_NAME);
|
||||||
socklen_t socklen = sizeof(sa_family_t) + strlen(addr.sun_path);
|
socklen_t socklen = sizeof(sa_family_t) + strlen(addr.sun_path);
|
||||||
auto nsend = sendto(sockfd, (void *) &cmd, sizeof(cmd), 0, (sockaddr *) &addr, socklen);
|
auto nsend = sendto(sockfd, (void *) &cmd, sizeof(cmd), 0, (sockaddr *) &addr, socklen);
|
||||||
|
|||||||
@@ -1,49 +1,55 @@
|
|||||||
|
use std::fs;
|
||||||
|
use std::os::android::fs::MetadataExt;
|
||||||
use crate::constants::MIN_MAGISK_VERSION;
|
use crate::constants::MIN_MAGISK_VERSION;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
use log::info;
|
||||||
|
use crate::utils::LateInit;
|
||||||
|
|
||||||
const MAGISK_VANILLA: &str = "com.topjohnwu.magisk";
|
const MAGISK_OFFICIAL: &str = "com.topjohnwu.magisk";
|
||||||
const MAGISK_ALPHA: &str = "io.github.vvb2060.magisk";
|
const MAGISK_THIRD_PARTIES: &[(&str, &str)] = &[
|
||||||
|
("alpha", "io.github.vvb2060.magisk"),
|
||||||
|
("kitsune", "io.github.huskydg.magisk"),
|
||||||
|
];
|
||||||
|
|
||||||
pub enum Version {
|
pub enum Version {
|
||||||
Supported,
|
Supported,
|
||||||
TooOld,
|
TooOld,
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut VARIANT: &str = MAGISK_VANILLA;
|
static VARIANT: LateInit<&str> = LateInit::new();
|
||||||
|
|
||||||
pub fn get_magisk() -> Option<Version> {
|
pub fn get_magisk() -> Option<Version> {
|
||||||
|
if !VARIANT.initiated() {
|
||||||
|
Command::new("magisk")
|
||||||
|
.arg("-v")
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.ok()
|
||||||
|
.and_then(|child| child.wait_with_output().ok())
|
||||||
|
.and_then(|output| String::from_utf8(output.stdout).ok())
|
||||||
|
.map(|version| {
|
||||||
|
let third_party = MAGISK_THIRD_PARTIES.iter().find_map(|v| {
|
||||||
|
version.contains(v.0).then_some(v.1)
|
||||||
|
});
|
||||||
|
VARIANT.init(third_party.unwrap_or(MAGISK_OFFICIAL));
|
||||||
|
info!("Magisk variant: {}", *VARIANT);
|
||||||
|
});
|
||||||
|
}
|
||||||
Command::new("magisk")
|
Command::new("magisk")
|
||||||
.arg("-v")
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.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") {
|
|
||||||
MAGISK_ALPHA
|
|
||||||
} else {
|
|
||||||
MAGISK_VANILLA
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map(|variant| {
|
|
||||||
unsafe { VARIANT = variant };
|
|
||||||
});
|
|
||||||
let version: Option<i32> = Command::new("magisk")
|
|
||||||
.arg("-V")
|
.arg("-V")
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.ok()
|
.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())
|
||||||
.and_then(|output| output.trim().parse().ok());
|
.and_then(|output| output.trim().parse::<i32>().ok())
|
||||||
version.map(|version| {
|
.map(|version| {
|
||||||
if version >= MIN_MAGISK_VERSION {
|
if version >= MIN_MAGISK_VERSION {
|
||||||
Version::Supported
|
Version::Supported
|
||||||
} else {
|
} else {
|
||||||
Version::TooOld
|
Version::TooOld
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uid_granted_root(uid: i32) -> bool {
|
pub fn uid_granted_root(uid: i32) -> bool {
|
||||||
@@ -95,13 +101,10 @@ pub fn uid_should_umount(uid: i32) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: signature
|
// TODO: signature
|
||||||
// TODO: magisk random package name
|
|
||||||
pub fn uid_is_manager(uid: i32) -> bool {
|
pub fn uid_is_manager(uid: i32) -> bool {
|
||||||
let output = Command::new("magisk")
|
let output = Command::new("magisk")
|
||||||
.arg("--sqlite")
|
.arg("--sqlite")
|
||||||
.arg(format!(
|
.arg(format!("select value from strings where key=\"requester\" limit 1"))
|
||||||
"select value from strings where key=\"requester\" limit 1"
|
|
||||||
))
|
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.ok()
|
.ok()
|
||||||
@@ -110,18 +113,12 @@ pub fn uid_is_manager(uid: i32) -> bool {
|
|||||||
.map(|output| output.trim().to_string());
|
.map(|output| output.trim().to_string());
|
||||||
if let Some(output) = output {
|
if let Some(output) = output {
|
||||||
if let Some(manager) = output.strip_prefix("value=") {
|
if let Some(manager) = output.strip_prefix("value=") {
|
||||||
if let Ok(s) = rustix::fs::stat(format!("/data/user_de/0/{}", manager)) {
|
return fs::metadata(format!("/data/user_de/0/{}", manager))
|
||||||
return s.st_uid == uid as u32;
|
.map(|s| s.st_uid() == uid as u32)
|
||||||
} else {
|
.unwrap_or(false);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let variant = unsafe { VARIANT };
|
fs::metadata(format!("/data/user_de/0/{}", *VARIANT))
|
||||||
if let Ok(s) = rustix::fs::stat(format!("/data/user_de/0/{variant}")) {
|
.map(|s| s.st_uid() == uid as u32)
|
||||||
if s.st_uid == uid as u32 {
|
.unwrap_or(false)
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ impl<T> LateInit<T> {
|
|||||||
pub fn init(&self, value: T) {
|
pub fn init(&self, value: T) {
|
||||||
assert!(self.cell.set(value).is_ok())
|
assert!(self.cell.set(value).is_ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn initiated(&self) -> bool {
|
||||||
|
self.cell.get().is_some()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> std::ops::Deref for LateInit<T> {
|
impl<T> std::ops::Deref for LateInit<T> {
|
||||||
|
|||||||
Reference in New Issue
Block a user