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>
This commit is contained in:
Captain Throwback
2024-07-13 14:43:24 -04:00
committed by GitHub
parent 4b7178f1ea
commit f1fe6b4435

View File

@@ -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<i32> = 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<String, io::Error> {
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<Version> {
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<Version> {
.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
}
}