You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Add more to the Utf8CStr family
Better C strings with path operations
This commit is contained in:
@@ -3,7 +3,7 @@ use std::fs::File;
|
||||
use std::io;
|
||||
use std::sync::{Mutex, OnceLock};
|
||||
|
||||
use base::{copy_str, cstr, Directory, ResultExt, Utf8CStr, WalkResult};
|
||||
use base::{cstr, Directory, ResultExt, Utf8CStr, Utf8CStrBuf, Utf8CStrSlice, WalkResult};
|
||||
|
||||
use crate::logging::{magisk_logging, zygisk_logging};
|
||||
|
||||
@@ -36,8 +36,7 @@ impl MagiskD {}
|
||||
|
||||
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;
|
||||
fn inner(pkg: &[u8], buf: &mut dyn Utf8CStrBuf) -> io::Result<usize> {
|
||||
let pkg = match Utf8CStr::from_bytes(pkg) {
|
||||
Ok(pkg) => pkg,
|
||||
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)),
|
||||
@@ -49,7 +48,7 @@ pub fn find_apk_path(pkg: &[u8], data: &mut [u8]) -> usize {
|
||||
let d_name = e.d_name().to_bytes();
|
||||
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)?;
|
||||
e.path(buf)?;
|
||||
return Ok(Abort);
|
||||
}
|
||||
if d_name.starts_with(b"~~") {
|
||||
@@ -57,10 +56,12 @@ pub fn find_apk_path(pkg: &[u8], data: &mut [u8]) -> usize {
|
||||
}
|
||||
Ok(Skip)
|
||||
})?;
|
||||
if len > 0 {
|
||||
len += copy_str(&mut data[len..], "/base.apk");
|
||||
if !buf.is_empty() {
|
||||
buf.append("/base.apk");
|
||||
}
|
||||
Ok(len)
|
||||
Ok(buf.len())
|
||||
}
|
||||
inner(pkg, data).log().unwrap_or(0)
|
||||
inner(pkg, &mut Utf8CStrSlice::from(data))
|
||||
.log()
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user