Fix find_apk_path

This commit is contained in:
LoveSy 2023-06-14 18:44:53 +08:00 committed by John Wu
parent c874391be4
commit 53257b6ea1
3 changed files with 8 additions and 4 deletions

View File

@ -378,7 +378,7 @@ impl Directory {
None => return Ok(Continue), None => return Ok(Continue),
Some(ref e) => match f(e)? { Some(ref e) => match f(e)? {
Abort => return Ok(Abort), Abort => return Ok(Abort),
Skip => return Ok(Continue), Skip => continue,
Continue => { Continue => {
if e.is_dir() { if e.is_dir() {
let mut dir = e.open_as_dir()?; let mut dir = e.open_as_dir()?;

View File

@ -3,7 +3,7 @@ use std::fs::File;
use std::io; use std::io;
use std::sync::{Mutex, OnceLock}; use std::sync::{Mutex, OnceLock};
use base::{copy_str, cstr, Directory, ResultExt, WalkResult}; use base::{copy_str, cstr, Directory, ResultExt, Utf8CStr, WalkResult};
use crate::logging::{magisk_logging, zygisk_logging}; use crate::logging::{magisk_logging, zygisk_logging};
@ -38,12 +38,16 @@ pub fn find_apk_path(pkg: &[u8], data: &mut [u8]) -> usize {
use WalkResult::*; use WalkResult::*;
fn inner(pkg: &[u8], data: &mut [u8]) -> io::Result<usize> { fn inner(pkg: &[u8], data: &mut [u8]) -> io::Result<usize> {
let mut len = 0_usize; let mut len = 0_usize;
let pkg = match Utf8CStr::from_bytes(pkg) {
Ok(pkg) => pkg,
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)),
};
Directory::open(cstr!("/data/app"))?.pre_order_walk(|e| { Directory::open(cstr!("/data/app"))?.pre_order_walk(|e| {
if !e.is_dir() { if !e.is_dir() {
return Ok(Skip); return Ok(Skip);
} }
let d_name = e.d_name().to_bytes(); let d_name = e.d_name().to_bytes();
if d_name.starts_with(pkg) && d_name[pkg.len()] == b'-' { if d_name.starts_with(pkg.as_bytes()) && d_name[pkg.len()] == b'-' {
// Found the APK path, we can abort now // Found the APK path, we can abort now
len = e.path(data)?; len = e.path(data)?;
return Ok(Abort); return Ok(Abort);

View File

@ -224,7 +224,7 @@ int get_manager(int user_id, string *pkg, bool install) {
if (stat(app_path, &st) == 0) { if (stat(app_path, &st) == 0) {
#if ENFORCE_SIGNATURE #if ENFORCE_SIGNATURE
byte_array<PATH_MAX> apk; byte_array<PATH_MAX> apk;
find_apk_path(byte_view(str[SU_MANAGER]), apk); find_apk_path(byte_view(JAVA_PACKAGE_NAME), apk);
int fd = xopen((const char *) apk.buf(), O_RDONLY | O_CLOEXEC); int fd = xopen((const char *) apk.buf(), O_RDONLY | O_CLOEXEC);
string cert = read_certificate(fd, MAGISK_VER_CODE); string cert = read_certificate(fd, MAGISK_VER_CODE);
close(fd); close(fd);