Skip to content

Commit

Permalink
Fix find_apk_path
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 authored and topjohnwu committed Jun 15, 2023
1 parent c874391 commit 53257b6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion native/src/base/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
8 changes: 6 additions & 2 deletions native/src/core/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<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| {
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);
Expand Down
2 changes: 1 addition & 1 deletion native/src/core/package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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);
string cert = read_certificate(fd, MAGISK_VER_CODE);
close(fd);
Expand Down

0 comments on commit 53257b6

Please sign in to comment.