From 53257b6ea1eda809138512ad95e6db9c0368992a Mon Sep 17 00:00:00 2001 From: LoveSy Date: Wed, 14 Jun 2023 18:44:53 +0800 Subject: [PATCH] Fix `find_apk_path` --- native/src/base/files.rs | 2 +- native/src/core/daemon.rs | 8 ++++++-- native/src/core/package.cpp | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/native/src/base/files.rs b/native/src/base/files.rs index 39561b9e1..81d835843 100644 --- a/native/src/base/files.rs +++ b/native/src/base/files.rs @@ -378,7 +378,7 @@ impl Directory { None => return Ok(Continue), Some(ref e) => match f(e)? { Abort => return Ok(Abort), - Skip => return Ok(Continue), + Skip => continue, Continue => { if e.is_dir() { let mut dir = e.open_as_dir()?; diff --git a/native/src/core/daemon.rs b/native/src/core/daemon.rs index 1d2f0dbe9..4891fa1b9 100644 --- a/native/src/core/daemon.rs +++ b/native/src/core/daemon.rs @@ -3,7 +3,7 @@ use std::fs::File; use std::io; 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}; @@ -38,12 +38,16 @@ pub fn find_apk_path(pkg: &[u8], data: &mut [u8]) -> usize { use WalkResult::*; fn inner(pkg: &[u8], data: &mut [u8]) -> io::Result { 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| { if !e.is_dir() { return Ok(Skip); } 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 len = e.path(data)?; return Ok(Abort); diff --git a/native/src/core/package.cpp b/native/src/core/package.cpp index 1fba87db9..0dde74154 100644 --- a/native/src/core/package.cpp +++ b/native/src/core/package.cpp @@ -224,7 +224,7 @@ int get_manager(int user_id, string *pkg, bool install) { if (stat(app_path, &st) == 0) { #if ENFORCE_SIGNATURE byte_array 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); string cert = read_certificate(fd, MAGISK_VER_CODE); close(fd);