From f1fe6b4435f0f4fa627b6fec3f3b264e188d53fe Mon Sep 17 00:00:00 2001 From: Captain Throwback Date: Sat, 13 Jul 2024 14:43:24 -0400 Subject: [PATCH] add: support for APatch reset su path (#26) This commit allows proper root detection when using multiple root solutions. Co-authored-by: Admire <43035036+Admirepowered@users.noreply.github.com> --- zygiskd/src/root_impl/apatch.rs | 44 +++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/zygiskd/src/root_impl/apatch.rs b/zygiskd/src/root_impl/apatch.rs index bec3ba6..aeab57f 100644 --- a/zygiskd/src/root_impl/apatch.rs +++ b/zygiskd/src/root_impl/apatch.rs @@ -1,5 +1,6 @@ use std::process::{Command, Stdio}; use std::fs::File; +use std::io::{self, BufRead, BufReader}; use serde::Deserialize; use crate::constants::MIN_APATCH_VERSION; @@ -8,6 +9,7 @@ pub enum Version { TooOld, Abnormal, } + fn parse_version(output: &str) -> i32 { let mut version: Option = None; for line in output.lines() { @@ -21,7 +23,29 @@ fn parse_version(output: &str) -> i32 { version.unwrap_or_default() } +fn read_su_path() -> Result { + let file = File::open("/data/adb/ap/su_path")?; + let mut reader = BufReader::new(file); + let mut su_path = String::new(); + reader.read_line(&mut su_path)?; + Ok(su_path.trim().to_string()) +} + pub fn get_apatch() -> Option { + let default_su_path = String::from("/system/bin/su"); + let su_path = read_su_path().ok()?; + + let output = Command::new(&su_path) + .arg("-v") + .stdout(Stdio::piped()) + .stderr(Stdio::null()) + .output() + .ok()?; + let stdout = String::from_utf8(output.stdout).ok()?; + if !stdout.contains("APatch") { + return None; + } + let output1 = Command::new("/data/adb/apd") .arg("-V") .stdout(Stdio::piped()) @@ -29,13 +53,17 @@ pub fn get_apatch() -> Option { .output() .ok()?; let stdout1 = String::from_utf8(output1.stdout).ok()?; - let version = parse_version(&stdout1); - const MAX_OLD_VERSION: i32 = MIN_APATCH_VERSION - 1; - match version { - 0 => Some(Version::Abnormal), - v if v >= MIN_APATCH_VERSION && v <= 999999 => Some(Version::Supported), - v if v >= 1 && v <= MAX_OLD_VERSION => Some(Version::TooOld), - _ => None, + if su_path == default_su_path { + let version = parse_version(&stdout1); + const MAX_OLD_VERSION: i32 = MIN_APATCH_VERSION - 1; + match version { + 0 => Some(Version::Abnormal), + v if v >= MIN_APATCH_VERSION && v <= 999999 => Some(Version::Supported), + v if v >= 1 && v <= MAX_OLD_VERSION => Some(Version::TooOld), + _ => None, + } + } else { + return None; } } @@ -110,4 +138,4 @@ pub fn uid_is_manager(uid: i32) -> bool { return s.st_uid == uid as u32; } false -} \ No newline at end of file +}