You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Move find_apk_path to Rust
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
use crate::logging::{magisk_logging, zygisk_logging};
|
||||
use std::cell::RefCell;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::sync::{Mutex, OnceLock};
|
||||
|
||||
use base::{copy_str, cstr, Directory, ResultExt, WalkResult};
|
||||
|
||||
use crate::logging::{magisk_logging, zygisk_logging};
|
||||
|
||||
// Global magiskd singleton
|
||||
pub static MAGISKD: OnceLock<MagiskD> = OnceLock::new();
|
||||
|
||||
@@ -29,3 +33,30 @@ pub fn get_magiskd() -> &'static MagiskD {
|
||||
}
|
||||
|
||||
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;
|
||||
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'-' {
|
||||
// Found the APK path, we can abort now
|
||||
len = e.path(data)?;
|
||||
return Ok(Abort);
|
||||
}
|
||||
if d_name.starts_with(b"~~") {
|
||||
return Ok(Continue);
|
||||
}
|
||||
Ok(Skip)
|
||||
})?;
|
||||
if len > 0 {
|
||||
len += copy_str(&mut data[len..], "/base.apk");
|
||||
}
|
||||
Ok(len)
|
||||
}
|
||||
inner(pkg, data).log().unwrap_or(0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user