mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-29 22:14:27 +02:00
Rename cstr_buf to cstr::buf
This commit is contained in:
parent
ab2e5d1e7e
commit
e02b5f7868
@ -21,7 +21,7 @@ use crate::{FsPath, FsPathMnt, slice_from_ptr_mut};
|
|||||||
// Utf8CStrBufRef: reference to a fixed sized buffer
|
// Utf8CStrBufRef: reference to a fixed sized buffer
|
||||||
// Utf8CStrBufArr<N>: fixed sized buffer allocated on the stack
|
// Utf8CStrBufArr<N>: fixed sized buffer allocated on the stack
|
||||||
//
|
//
|
||||||
// For easier usage, please use the helper functions in cstr_buf.
|
// For easier usage, please use the helper functions in cstr::buf.
|
||||||
//
|
//
|
||||||
// In most cases, these are the types being used
|
// In most cases, these are the types being used
|
||||||
//
|
//
|
||||||
@ -36,7 +36,7 @@ use crate::{FsPath, FsPathMnt, slice_from_ptr_mut};
|
|||||||
|
|
||||||
// Public helper functions
|
// Public helper functions
|
||||||
|
|
||||||
pub mod cstr_buf {
|
pub mod buf {
|
||||||
use super::{Utf8CStrBufArr, Utf8CStrBufRef, Utf8CString};
|
use super::{Utf8CStrBufArr, Utf8CStrBufRef, Utf8CString};
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -118,7 +118,7 @@ impl<'a> From<&'a mut dyn Utf8CStrBuf> for Utf8CStrBuffer<'a, 0> {
|
|||||||
|
|
||||||
impl Default for Utf8CStrBuffer<'static, 4096> {
|
impl Default for Utf8CStrBuffer<'static, 4096> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Utf8CStrBuffer::Array(cstr_buf::default())
|
Utf8CStrBuffer::Array(buf::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,12 +8,12 @@ use libc::{c_char, mode_t};
|
|||||||
use crate::files::map_file_at;
|
use crate::files::map_file_at;
|
||||||
pub(crate) use crate::xwrap::*;
|
pub(crate) use crate::xwrap::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
CxxResultExt, Directory, FsPath, OsResultStatic, Utf8CStr, clone_attr, cstr, cstr_buf,
|
CxxResultExt, Directory, FsPath, OsResultStatic, Utf8CStr, clone_attr, cstr, fclone_attr,
|
||||||
fclone_attr, fd_path, map_fd, map_file, slice_from_ptr,
|
fd_path, map_fd, map_file, slice_from_ptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn fd_path_for_cxx(fd: RawFd, buf: &mut [u8]) -> isize {
|
pub(crate) fn fd_path_for_cxx(fd: RawFd, buf: &mut [u8]) -> isize {
|
||||||
let mut buf = cstr_buf::wrap(buf);
|
let mut buf = cstr::buf::wrap(buf);
|
||||||
fd_path(fd, &mut buf)
|
fd_path(fd, &mut buf)
|
||||||
.log_cxx()
|
.log_cxx()
|
||||||
.map_or(-1_isize, |_| buf.len() as isize)
|
.map_or(-1_isize, |_| buf.len() as isize)
|
||||||
@ -24,7 +24,7 @@ unsafe extern "C" fn canonical_path(path: *const c_char, buf: *mut u8, bufsz: us
|
|||||||
unsafe {
|
unsafe {
|
||||||
match Utf8CStr::from_ptr(path) {
|
match Utf8CStr::from_ptr(path) {
|
||||||
Ok(path) => {
|
Ok(path) => {
|
||||||
let mut buf = cstr_buf::wrap_ptr(buf, bufsz);
|
let mut buf = cstr::buf::wrap_ptr(buf, bufsz);
|
||||||
path.realpath(&mut buf)
|
path.realpath(&mut buf)
|
||||||
.log_cxx()
|
.log_cxx()
|
||||||
.map_or(-1_isize, |_| buf.len() as isize)
|
.map_or(-1_isize, |_| buf.len() as isize)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::cxx_extern::readlinkat;
|
use crate::cxx_extern::readlinkat;
|
||||||
use crate::{
|
use crate::{
|
||||||
FileAttr, FsPath, FsPathBuilder, LibcReturn, OsError, OsResult, OsResultStatic, Utf8CStr,
|
FileAttr, FsPath, FsPathBuilder, LibcReturn, OsError, OsResult, OsResultStatic, Utf8CStr,
|
||||||
Utf8CStrBuf, cstr_buf, errno, fd_path, fd_set_attr,
|
Utf8CStrBuf, cstr, errno, fd_path, fd_set_attr,
|
||||||
};
|
};
|
||||||
use libc::{EEXIST, O_CLOEXEC, O_CREAT, O_RDONLY, O_TRUNC, O_WRONLY, dirent, mode_t};
|
use libc::{EEXIST, O_CLOEXEC, O_CREAT, O_RDONLY, O_TRUNC, O_WRONLY, dirent, mode_t};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
@ -247,13 +247,13 @@ impl Directory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_attr_at<'a>(&self, name: &'a Utf8CStr) -> OsResult<'a, FileAttr> {
|
pub fn get_attr_at<'a>(&self, name: &'a Utf8CStr) -> OsResult<'a, FileAttr> {
|
||||||
let mut path = cstr_buf::default();
|
let mut path = cstr::buf::default();
|
||||||
self.path_at(name, &mut path)?;
|
self.path_at(name, &mut path)?;
|
||||||
path.get_attr().map_err(|e| e.set_args(Some(name), None))
|
path.get_attr().map_err(|e| e.set_args(Some(name), None))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_attr_at<'a>(&self, name: &'a Utf8CStr, attr: &FileAttr) -> OsResult<'a, ()> {
|
pub fn set_attr_at<'a>(&self, name: &'a Utf8CStr, attr: &FileAttr) -> OsResult<'a, ()> {
|
||||||
let mut path = cstr_buf::default();
|
let mut path = cstr::buf::default();
|
||||||
self.path_at(name, &mut path)?;
|
self.path_at(name, &mut path)?;
|
||||||
path.set_attr(attr)
|
path.set_attr(attr)
|
||||||
.map_err(|e| e.set_args(Some(name), None))
|
.map_err(|e| e.set_args(Some(name), None))
|
||||||
@ -264,14 +264,14 @@ impl Directory {
|
|||||||
name: &'a Utf8CStr,
|
name: &'a Utf8CStr,
|
||||||
con: &mut dyn Utf8CStrBuf,
|
con: &mut dyn Utf8CStrBuf,
|
||||||
) -> OsResult<'a, ()> {
|
) -> OsResult<'a, ()> {
|
||||||
let mut path = cstr_buf::default();
|
let mut path = cstr::buf::default();
|
||||||
self.path_at(name, &mut path)?;
|
self.path_at(name, &mut path)?;
|
||||||
path.get_secontext(con)
|
path.get_secontext(con)
|
||||||
.map_err(|e| e.set_args(Some(name), None))
|
.map_err(|e| e.set_args(Some(name), None))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_secontext_at<'a>(&self, name: &'a Utf8CStr, con: &'a Utf8CStr) -> OsResult<'a, ()> {
|
pub fn set_secontext_at<'a>(&self, name: &'a Utf8CStr, con: &'a Utf8CStr) -> OsResult<'a, ()> {
|
||||||
let mut path = cstr_buf::default();
|
let mut path = cstr::buf::default();
|
||||||
self.path_at(name, &mut path)?;
|
self.path_at(name, &mut path)?;
|
||||||
path.set_secontext(con)
|
path.set_secontext(con)
|
||||||
.map_err(|e| e.set_args(Some(name), Some(con)))
|
.map_err(|e| e.set_args(Some(name), Some(con)))
|
||||||
@ -344,7 +344,7 @@ impl Directory {
|
|||||||
std::io::copy(&mut src, &mut dest)?;
|
std::io::copy(&mut src, &mut dest)?;
|
||||||
fd_set_attr(dest.as_raw_fd(), &attr)?;
|
fd_set_attr(dest.as_raw_fd(), &attr)?;
|
||||||
} else if e.is_symlink() {
|
} else if e.is_symlink() {
|
||||||
let mut target = cstr_buf::default();
|
let mut target = cstr::buf::default();
|
||||||
e.read_link(&mut target)?;
|
e.read_link(&mut target)?;
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::symlinkat(target.as_ptr(), dir.as_raw_fd(), e.d_name.as_ptr())
|
libc::symlinkat(target.as_ptr(), dir.as_raw_fd(), e.d_name.as_ptr())
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
Directory, FsPathFollow, LibcReturn, OsError, OsResult, OsResultStatic, Utf8CStr, Utf8CStrBuf,
|
Directory, FsPathFollow, LibcReturn, OsError, OsResult, OsResultStatic, Utf8CStr, Utf8CStrBuf,
|
||||||
cstr_buf, errno, error,
|
cstr, errno, error,
|
||||||
};
|
};
|
||||||
use bytemuck::{Pod, bytes_of, bytes_of_mut};
|
use bytemuck::{Pod, bytes_of, bytes_of_mut};
|
||||||
use libc::{
|
use libc::{
|
||||||
@ -139,7 +139,7 @@ macro_rules! open_fd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fd_path(fd: RawFd, buf: &mut dyn Utf8CStrBuf) -> OsResult<'static, ()> {
|
pub fn fd_path(fd: RawFd, buf: &mut dyn Utf8CStrBuf) -> OsResult<'static, ()> {
|
||||||
let path = cstr_buf::default()
|
let path = cstr::buf::default()
|
||||||
.join_path("/proc/self/fd")
|
.join_path("/proc/self/fd")
|
||||||
.join_path_fmt(fd);
|
.join_path_fmt(fd);
|
||||||
path.read_link(buf).map_err(|e| e.set_args(None, None))
|
path.read_link(buf).map_err(|e| e.set_args(None, None))
|
||||||
@ -270,7 +270,7 @@ pub trait FsPath: Deref<Target = Utf8CStr> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut path = cstr_buf::default();
|
let mut path = cstr::buf::default();
|
||||||
let mut components = self.split('/').filter(|s| !s.is_empty());
|
let mut components = self.split('/').filter(|s| !s.is_empty());
|
||||||
loop {
|
loop {
|
||||||
let Some(s) = components.next() else {
|
let Some(s) = components.next() else {
|
||||||
@ -396,7 +396,7 @@ pub trait FsPath: Deref<Target = Utf8CStr> {
|
|||||||
let mut dest = path.create(O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0o777)?;
|
let mut dest = path.create(O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0o777)?;
|
||||||
std::io::copy(&mut src, &mut dest)?;
|
std::io::copy(&mut src, &mut dest)?;
|
||||||
} else if attr.is_symlink() {
|
} else if attr.is_symlink() {
|
||||||
let mut buf = cstr_buf::default();
|
let mut buf = cstr::buf::default();
|
||||||
self.read_link(&mut buf)?;
|
self.read_link(&mut buf)?;
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::symlink(buf.as_ptr(), path.as_ptr()).check_os_err(
|
libc::symlink(buf.as_ptr(), path.as_ptr()).check_os_err(
|
||||||
|
@ -6,7 +6,9 @@ pub use const_format;
|
|||||||
pub use libc;
|
pub use libc;
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
|
|
||||||
pub use cstr::*;
|
pub use cstr::{
|
||||||
|
FsPathFollow, StrErr, Utf8CStr, Utf8CStrBuf, Utf8CStrBufArr, Utf8CStrBufRef, Utf8CString,
|
||||||
|
};
|
||||||
use cxx_extern::*;
|
use cxx_extern::*;
|
||||||
pub use dir::*;
|
pub use dir::*;
|
||||||
pub use ffi::fork_dont_care;
|
pub use ffi::fork_dont_care;
|
||||||
@ -16,7 +18,7 @@ pub use misc::*;
|
|||||||
pub use mount::*;
|
pub use mount::*;
|
||||||
pub use result::*;
|
pub use result::*;
|
||||||
|
|
||||||
mod cstr;
|
pub mod cstr;
|
||||||
mod cxx_extern;
|
mod cxx_extern;
|
||||||
mod dir;
|
mod dir;
|
||||||
mod files;
|
mod files;
|
||||||
|
@ -7,7 +7,7 @@ use num_derive::{FromPrimitive, ToPrimitive};
|
|||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
|
|
||||||
use crate::ffi::LogLevelCxx;
|
use crate::ffi::LogLevelCxx;
|
||||||
use crate::{Utf8CStr, cstr_buf};
|
use crate::{Utf8CStr, cstr};
|
||||||
|
|
||||||
// Ugly hack to avoid using enum
|
// Ugly hack to avoid using enum
|
||||||
#[allow(non_snake_case, non_upper_case_globals)]
|
#[allow(non_snake_case, non_upper_case_globals)]
|
||||||
@ -96,7 +96,7 @@ pub fn log_from_cxx(level: LogLevelCxx, msg: &Utf8CStr) {
|
|||||||
|
|
||||||
pub fn log_with_formatter<F: FnOnce(Formatter) -> fmt::Result>(level: LogLevel, f: F) {
|
pub fn log_with_formatter<F: FnOnce(Formatter) -> fmt::Result>(level: LogLevel, f: F) {
|
||||||
log_with_writer(level, |write| {
|
log_with_writer(level, |write| {
|
||||||
let mut buf = cstr_buf::default();
|
let mut buf = cstr::buf::default();
|
||||||
f(&mut buf).ok();
|
f(&mut buf).ok();
|
||||||
write(level, &buf);
|
write(level, &buf);
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use crate::cxx_extern::readlinkat;
|
use crate::cxx_extern::readlinkat;
|
||||||
use crate::{
|
use crate::{
|
||||||
BorrowedDirectory, CxxResultExt, FsPath, LibcReturn, Utf8CStr, cstr_buf, slice_from_ptr,
|
BorrowedDirectory, CxxResultExt, FsPath, LibcReturn, Utf8CStr, cstr, slice_from_ptr,
|
||||||
slice_from_ptr_mut,
|
slice_from_ptr_mut,
|
||||||
};
|
};
|
||||||
use libc::{
|
use libc::{
|
||||||
@ -30,7 +30,7 @@ unsafe extern "C" fn xrealpath(path: *const c_char, buf: *mut u8, bufsz: usize)
|
|||||||
unsafe {
|
unsafe {
|
||||||
match Utf8CStr::from_ptr(path) {
|
match Utf8CStr::from_ptr(path) {
|
||||||
Ok(path) => {
|
Ok(path) => {
|
||||||
let mut buf = cstr_buf::wrap_ptr(buf, bufsz);
|
let mut buf = cstr::buf::wrap_ptr(buf, bufsz);
|
||||||
path.realpath(&mut buf)
|
path.realpath(&mut buf)
|
||||||
.log_cxx()
|
.log_cxx()
|
||||||
.map_or(-1, |_| buf.len() as isize)
|
.map_or(-1, |_| buf.len() as isize)
|
||||||
@ -45,7 +45,7 @@ unsafe extern "C" fn xreadlink(path: *const c_char, buf: *mut u8, bufsz: usize)
|
|||||||
unsafe {
|
unsafe {
|
||||||
match Utf8CStr::from_ptr(path) {
|
match Utf8CStr::from_ptr(path) {
|
||||||
Ok(path) => {
|
Ok(path) => {
|
||||||
let mut buf = cstr_buf::wrap_ptr(buf, bufsz);
|
let mut buf = cstr::buf::wrap_ptr(buf, bufsz);
|
||||||
path.read_link(&mut buf)
|
path.read_link(&mut buf)
|
||||||
.log_cxx()
|
.log_cxx()
|
||||||
.map_or(-1, |_| buf.len() as isize)
|
.map_or(-1, |_| buf.len() as isize)
|
||||||
|
@ -21,7 +21,7 @@ use base::libc::{
|
|||||||
};
|
};
|
||||||
use base::{
|
use base::{
|
||||||
BytesExt, EarlyExitExt, FsPath, LoggedResult, MappedFile, ResultExt, Utf8CStr, Utf8CStrBuf,
|
BytesExt, EarlyExitExt, FsPath, LoggedResult, MappedFile, ResultExt, Utf8CStr, Utf8CStrBuf,
|
||||||
WriteExt, cstr_buf, log_err, map_args,
|
WriteExt, cstr, log_err, map_args,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::check_env;
|
use crate::check_env;
|
||||||
@ -343,7 +343,7 @@ impl Cpio {
|
|||||||
|
|
||||||
let out = Utf8CStr::from_string(out);
|
let out = Utf8CStr::from_string(out);
|
||||||
|
|
||||||
let mut buf = cstr_buf::default();
|
let mut buf = cstr::buf::default();
|
||||||
|
|
||||||
// Make sure its parent directories exist
|
// Make sure its parent directories exist
|
||||||
if out.parent(&mut buf) {
|
if out.parent(&mut buf) {
|
||||||
|
@ -11,8 +11,8 @@ use crate::package::ManagerInfo;
|
|||||||
use crate::su::SuInfo;
|
use crate::su::SuInfo;
|
||||||
use base::libc::{O_CLOEXEC, O_RDONLY};
|
use base::libc::{O_CLOEXEC, O_RDONLY};
|
||||||
use base::{
|
use base::{
|
||||||
AtomicArc, BufReadExt, FsPath, FsPathBuilder, ResultExt, Utf8CStr, cstr, cstr_buf, error, info,
|
AtomicArc, BufReadExt, FsPath, FsPathBuilder, ResultExt, Utf8CStr, cstr, error, info, libc,
|
||||||
libc, open_fd,
|
open_fd,
|
||||||
};
|
};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
@ -229,7 +229,7 @@ pub fn daemon_entry() {
|
|||||||
|| get_prop(cstr!("ro.product.device"), false).contains("vsoc");
|
|| get_prop(cstr!("ro.product.device"), false).contains("vsoc");
|
||||||
|
|
||||||
// Load config status
|
// Load config status
|
||||||
let path = cstr_buf::new::<64>()
|
let path = cstr::buf::new::<64>()
|
||||||
.join_path(get_magisk_tmp())
|
.join_path(get_magisk_tmp())
|
||||||
.join_path(MAIN_CONFIG);
|
.join_path(MAIN_CONFIG);
|
||||||
let mut is_recovery = false;
|
let mut is_recovery = false;
|
||||||
|
@ -7,7 +7,7 @@ use base::libc::{
|
|||||||
};
|
};
|
||||||
use base::{
|
use base::{
|
||||||
FsPathBuilder, LOGGER, LogLevel, Logger, ReadExt, Utf8CStr, Utf8CStrBuf, WriteExt,
|
FsPathBuilder, LOGGER, LogLevel, Logger, ReadExt, Utf8CStr, Utf8CStrBuf, WriteExt,
|
||||||
const_format::concatcp, cstr_buf, libc, raw_cstr,
|
const_format::concatcp, cstr, libc, raw_cstr,
|
||||||
};
|
};
|
||||||
use bytemuck::{Pod, Zeroable, bytes_of, write_zeroes};
|
use bytemuck::{Pod, Zeroable, bytes_of, write_zeroes};
|
||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
@ -130,7 +130,7 @@ fn write_log_to_pipe(mut logd: &File, prio: i32, msg: &Utf8CStr) -> io::Result<u
|
|||||||
let io2 = IoSlice::new(msg);
|
let io2 = IoSlice::new(msg);
|
||||||
let result = logd.write_vectored(&[io1, io2]);
|
let result = logd.write_vectored(&[io1, io2]);
|
||||||
if let Err(ref e) = result {
|
if let Err(ref e) = result {
|
||||||
let mut buf = cstr_buf::default();
|
let mut buf = cstr::buf::default();
|
||||||
buf.write_fmt(format_args!("Cannot write_log_to_pipe: {}", e))
|
buf.write_fmt(format_args!("Cannot write_log_to_pipe: {}", e))
|
||||||
.ok();
|
.ok();
|
||||||
android_log_write(LogLevel::Error, &buf);
|
android_log_write(LogLevel::Error, &buf);
|
||||||
@ -180,7 +180,7 @@ pub fn zygisk_get_logd() -> i32 {
|
|||||||
let mut fd = ZYGISK_LOGD.load(Ordering::Relaxed);
|
let mut fd = ZYGISK_LOGD.load(Ordering::Relaxed);
|
||||||
if fd < 0 {
|
if fd < 0 {
|
||||||
android_logging();
|
android_logging();
|
||||||
let path = cstr_buf::default()
|
let path = cstr::buf::default()
|
||||||
.join_path(get_magisk_tmp())
|
.join_path(get_magisk_tmp())
|
||||||
.join_path(LOG_PIPE);
|
.join_path(LOG_PIPE);
|
||||||
// Open as RW as sometimes it may block
|
// Open as RW as sometimes it may block
|
||||||
@ -268,7 +268,7 @@ extern "C" fn logfile_writer(arg: *mut c_void) -> *mut c_void {
|
|||||||
|
|
||||||
let mut meta = LogMeta::zeroed();
|
let mut meta = LogMeta::zeroed();
|
||||||
let mut msg_buf = [0u8; MAX_MSG_LEN];
|
let mut msg_buf = [0u8; MAX_MSG_LEN];
|
||||||
let mut aux = cstr_buf::new::<64>();
|
let mut aux = cstr::buf::new::<64>();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Read request
|
// Read request
|
||||||
@ -357,7 +357,7 @@ pub fn setup_logfile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_log_daemon() {
|
pub fn start_log_daemon() {
|
||||||
let path = cstr_buf::default()
|
let path = cstr::buf::default()
|
||||||
.join_path(get_magisk_tmp())
|
.join_path(get_magisk_tmp())
|
||||||
.join_path(LOG_PIPE);
|
.join_path(LOG_PIPE);
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use num_traits::AsPrimitive;
|
|||||||
use base::libc::{c_uint, dev_t};
|
use base::libc::{c_uint, dev_t};
|
||||||
use base::{
|
use base::{
|
||||||
FsPath, FsPathBuilder, FsPathMnt, LibcReturn, LoggedResult, MountInfo, ResultExt, Utf8CStr,
|
FsPath, FsPathBuilder, FsPathMnt, LibcReturn, LoggedResult, MountInfo, ResultExt, Utf8CStr,
|
||||||
Utf8CStrBuf, cstr, cstr_buf, debug, info, libc, parse_mount_info, warn,
|
Utf8CStrBuf, cstr, debug, info, libc, parse_mount_info, warn,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::consts::{MODULEMNT, MODULEROOT, PREINITDEV, PREINITMIRR, WORKERDIR};
|
use crate::consts::{MODULEMNT, MODULEROOT, PREINITDEV, PREINITMIRR, WORKERDIR};
|
||||||
@ -21,7 +21,7 @@ pub fn setup_mounts() {
|
|||||||
let magisk_tmp = get_magisk_tmp();
|
let magisk_tmp = get_magisk_tmp();
|
||||||
|
|
||||||
// Mount preinit directory
|
// Mount preinit directory
|
||||||
let dev_path = cstr_buf::new::<64>()
|
let dev_path = cstr::buf::new::<64>()
|
||||||
.join_path(magisk_tmp)
|
.join_path(magisk_tmp)
|
||||||
.join_path(PREINITDEV);
|
.join_path(PREINITDEV);
|
||||||
let mut linked = false;
|
let mut linked = false;
|
||||||
@ -33,7 +33,7 @@ pub fn setup_mounts() {
|
|||||||
// What we do instead is to scan through the current mountinfo and find a pre-existing
|
// What we do instead is to scan through the current mountinfo and find a pre-existing
|
||||||
// mount point mounting our desired partition, and then bind mount the target folder.
|
// mount point mounting our desired partition, and then bind mount the target folder.
|
||||||
let preinit_dev = attr.st.st_rdev;
|
let preinit_dev = attr.st.st_rdev;
|
||||||
let mnt_path = cstr_buf::default()
|
let mnt_path = cstr::buf::default()
|
||||||
.join_path(magisk_tmp)
|
.join_path(magisk_tmp)
|
||||||
.join_path(PREINITMIRR);
|
.join_path(PREINITMIRR);
|
||||||
for info in parse_mount_info("self") {
|
for info in parse_mount_info("self") {
|
||||||
@ -68,7 +68,7 @@ pub fn setup_mounts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bind remount module root to clear nosuid
|
// Bind remount module root to clear nosuid
|
||||||
let module_mnt = cstr_buf::default()
|
let module_mnt = cstr::buf::default()
|
||||||
.join_path(magisk_tmp)
|
.join_path(magisk_tmp)
|
||||||
.join_path(MODULEMNT);
|
.join_path(MODULEMNT);
|
||||||
let _: LoggedResult<()> = try {
|
let _: LoggedResult<()> = try {
|
||||||
@ -81,7 +81,7 @@ pub fn setup_mounts() {
|
|||||||
pub fn clean_mounts() {
|
pub fn clean_mounts() {
|
||||||
let magisk_tmp = get_magisk_tmp();
|
let magisk_tmp = get_magisk_tmp();
|
||||||
|
|
||||||
let mut buf = cstr_buf::default();
|
let mut buf = cstr::buf::default();
|
||||||
|
|
||||||
let module_mnt = buf.append_path(magisk_tmp).append_path(MODULEMNT);
|
let module_mnt = buf.append_path(magisk_tmp).append_path(MODULEMNT);
|
||||||
module_mnt.unmount().log_ok();
|
module_mnt.unmount().log_ok();
|
||||||
@ -186,7 +186,7 @@ pub fn find_preinit_device() -> String {
|
|||||||
&& let Ok(tmp) = std::env::var("MAGISKTMP")
|
&& let Ok(tmp) = std::env::var("MAGISKTMP")
|
||||||
&& !tmp.is_empty()
|
&& !tmp.is_empty()
|
||||||
{
|
{
|
||||||
let mut buf = cstr_buf::default();
|
let mut buf = cstr::buf::default();
|
||||||
let mirror_dir = buf.append_path(&tmp).append_path(PREINITMIRR);
|
let mirror_dir = buf.append_path(&tmp).append_path(PREINITMIRR);
|
||||||
let preinit_dir = Utf8CStr::from_string(&mut preinit_dir);
|
let preinit_dir = Utf8CStr::from_string(&mut preinit_dir);
|
||||||
let _: LoggedResult<()> = try {
|
let _: LoggedResult<()> = try {
|
||||||
|
@ -5,7 +5,7 @@ use base::WalkResult::{Abort, Continue, Skip};
|
|||||||
use base::libc::{O_CLOEXEC, O_CREAT, O_RDONLY, O_TRUNC, O_WRONLY};
|
use base::libc::{O_CLOEXEC, O_CREAT, O_RDONLY, O_TRUNC, O_WRONLY};
|
||||||
use base::{
|
use base::{
|
||||||
BufReadExt, Directory, FsPath, FsPathBuilder, LoggedResult, ReadExt, ResultExt, Utf8CStrBuf,
|
BufReadExt, Directory, FsPath, FsPathBuilder, LoggedResult, ReadExt, ResultExt, Utf8CStrBuf,
|
||||||
cstr, cstr_buf, error, fd_get_attr, open_fd, warn,
|
cstr, error, fd_get_attr, open_fd, warn,
|
||||||
};
|
};
|
||||||
use bit_set::BitSet;
|
use bit_set::BitSet;
|
||||||
use cxx::CxxString;
|
use cxx::CxxString;
|
||||||
@ -239,7 +239,7 @@ impl TrackedFile {
|
|||||||
|
|
||||||
impl ManagerInfo {
|
impl ManagerInfo {
|
||||||
fn check_dyn(&mut self, daemon: &MagiskD, user: i32, pkg: &str) -> Status {
|
fn check_dyn(&mut self, daemon: &MagiskD, user: i32, pkg: &str) -> Status {
|
||||||
let apk = cstr_buf::default()
|
let apk = cstr::buf::default()
|
||||||
.join_path(daemon.app_data_dir())
|
.join_path(daemon.app_data_dir())
|
||||||
.join_path_fmt(user)
|
.join_path_fmt(user)
|
||||||
.join_path(pkg)
|
.join_path(pkg)
|
||||||
@ -273,7 +273,7 @@ impl ManagerInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_stub(&mut self, user: i32, pkg: &str) -> Status {
|
fn check_stub(&mut self, user: i32, pkg: &str) -> Status {
|
||||||
let mut apk = cstr_buf::default();
|
let mut apk = cstr::buf::default();
|
||||||
if find_apk_path(pkg, &mut apk).is_err() {
|
if find_apk_path(pkg, &mut apk).is_err() {
|
||||||
return Status::NotInstalled;
|
return Status::NotInstalled;
|
||||||
}
|
}
|
||||||
@ -297,7 +297,7 @@ impl ManagerInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_orig(&mut self, user: i32) -> Status {
|
fn check_orig(&mut self, user: i32) -> Status {
|
||||||
let mut apk = cstr_buf::default();
|
let mut apk = cstr::buf::default();
|
||||||
if find_apk_path(APP_PACKAGE_NAME, &mut apk).is_err() {
|
if find_apk_path(APP_PACKAGE_NAME, &mut apk).is_err() {
|
||||||
return Status::NotInstalled;
|
return Status::NotInstalled;
|
||||||
}
|
}
|
||||||
@ -441,7 +441,7 @@ impl ManagerInfo {
|
|||||||
|
|
||||||
impl MagiskD {
|
impl MagiskD {
|
||||||
fn get_package_uid(&self, user: i32, pkg: &str) -> i32 {
|
fn get_package_uid(&self, user: i32, pkg: &str) -> i32 {
|
||||||
let path = cstr_buf::default()
|
let path = cstr::buf::default()
|
||||||
.join_path(self.app_data_dir())
|
.join_path(self.app_data_dir())
|
||||||
.join_path_fmt(user)
|
.join_path_fmt(user)
|
||||||
.join_path(pkg);
|
.join_path(pkg);
|
||||||
@ -453,7 +453,7 @@ impl MagiskD {
|
|||||||
pub fn preserve_stub_apk(&self) {
|
pub fn preserve_stub_apk(&self) {
|
||||||
let mut info = self.manager_info.lock().unwrap();
|
let mut info = self.manager_info.lock().unwrap();
|
||||||
|
|
||||||
let apk = cstr_buf::default()
|
let apk = cstr::buf::default()
|
||||||
.join_path(get_magisk_tmp())
|
.join_path(get_magisk_tmp())
|
||||||
.join_path("stub.apk");
|
.join_path("stub.apk");
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ use base::const_format::concatcp;
|
|||||||
use base::libc::{O_CLOEXEC, O_RDONLY};
|
use base::libc::{O_CLOEXEC, O_RDONLY};
|
||||||
use base::{
|
use base::{
|
||||||
Directory, FsPath, FsPathBuilder, LibcReturn, LoggedResult, MappedFile, SilentResultExt,
|
Directory, FsPath, FsPathBuilder, LibcReturn, LoggedResult, MappedFile, SilentResultExt,
|
||||||
Utf8CStr, Utf8CStrBuf, WalkResult, clone_attr, cstr, cstr_buf, debug, libc::mkstemp,
|
Utf8CStr, Utf8CStrBuf, WalkResult, clone_attr, cstr, debug, libc::mkstemp,
|
||||||
};
|
};
|
||||||
|
|
||||||
const PERSIST_PROP_DIR: &str = "/data/property";
|
const PERSIST_PROP_DIR: &str = "/data/property";
|
||||||
@ -68,7 +68,7 @@ fn check_proto() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn file_get_prop(name: &Utf8CStr) -> LoggedResult<String> {
|
fn file_get_prop(name: &Utf8CStr) -> LoggedResult<String> {
|
||||||
let path = cstr_buf::default()
|
let path = cstr::buf::default()
|
||||||
.join_path(PERSIST_PROP_DIR)
|
.join_path(PERSIST_PROP_DIR)
|
||||||
.join_path(name);
|
.join_path(name);
|
||||||
let mut file = path.open(O_RDONLY | O_CLOEXEC).silent()?;
|
let mut file = path.open(O_RDONLY | O_CLOEXEC).silent()?;
|
||||||
@ -79,11 +79,11 @@ fn file_get_prop(name: &Utf8CStr) -> LoggedResult<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn file_set_prop(name: &Utf8CStr, value: Option<&Utf8CStr>) -> LoggedResult<()> {
|
fn file_set_prop(name: &Utf8CStr, value: Option<&Utf8CStr>) -> LoggedResult<()> {
|
||||||
let path = cstr_buf::default()
|
let path = cstr::buf::default()
|
||||||
.join_path(PERSIST_PROP_DIR)
|
.join_path(PERSIST_PROP_DIR)
|
||||||
.join_path(name);
|
.join_path(name);
|
||||||
if let Some(value) = value {
|
if let Some(value) = value {
|
||||||
let mut tmp = cstr_buf::default()
|
let mut tmp = cstr::buf::default()
|
||||||
.join_path(PERSIST_PROP_DIR)
|
.join_path(PERSIST_PROP_DIR)
|
||||||
.join_path("prop.XXXXXX");
|
.join_path("prop.XXXXXX");
|
||||||
{
|
{
|
||||||
@ -115,7 +115,7 @@ fn proto_read_props() -> LoggedResult<PersistentProperties> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn proto_write_props(props: &PersistentProperties) -> LoggedResult<()> {
|
fn proto_write_props(props: &PersistentProperties) -> LoggedResult<()> {
|
||||||
let mut tmp = cstr_buf::default().join_path(concatcp!(PERSIST_PROP, ".XXXXXX"));
|
let mut tmp = cstr::buf::default().join_path(concatcp!(PERSIST_PROP, ".XXXXXX"));
|
||||||
{
|
{
|
||||||
let f = unsafe {
|
let f = unsafe {
|
||||||
mkstemp(tmp.as_mut_ptr())
|
mkstemp(tmp.as_mut_ptr())
|
||||||
|
@ -6,8 +6,8 @@ use crate::ffi::{
|
|||||||
use crate::socket::{IpcRead, UnixSocketExt};
|
use crate::socket::{IpcRead, UnixSocketExt};
|
||||||
use base::libc::{O_CLOEXEC, O_CREAT, O_RDONLY, STDOUT_FILENO};
|
use base::libc::{O_CLOEXEC, O_CREAT, O_RDONLY, STDOUT_FILENO};
|
||||||
use base::{
|
use base::{
|
||||||
Directory, FsPathBuilder, LoggedError, LoggedResult, ResultExt, WriteExt, cstr, cstr_buf,
|
Directory, FsPathBuilder, LoggedError, LoggedResult, ResultExt, WriteExt, cstr, error,
|
||||||
error, fork_dont_care, libc, open_fd, raw_cstr, warn,
|
fork_dont_care, libc, open_fd, raw_cstr, warn,
|
||||||
};
|
};
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::os::fd::{AsRawFd, FromRawFd, RawFd};
|
use std::os::fd::{AsRawFd, FromRawFd, RawFd};
|
||||||
@ -37,11 +37,11 @@ fn exec_zygiskd(is_64_bit: bool, remote: UnixStream) {
|
|||||||
#[cfg(target_pointer_width = "32")]
|
#[cfg(target_pointer_width = "32")]
|
||||||
let magisk = "magisk";
|
let magisk = "magisk";
|
||||||
|
|
||||||
let exe = cstr_buf::new::<64>()
|
let exe = cstr::buf::new::<64>()
|
||||||
.join_path(get_magisk_tmp())
|
.join_path(get_magisk_tmp())
|
||||||
.join_path(magisk);
|
.join_path(magisk);
|
||||||
|
|
||||||
let mut fd_str = cstr_buf::new::<16>();
|
let mut fd_str = cstr::buf::new::<16>();
|
||||||
write!(fd_str, "{}", remote.as_raw_fd()).ok();
|
write!(fd_str, "{}", remote.as_raw_fd()).ok();
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::execl(
|
libc::execl(
|
||||||
@ -185,7 +185,7 @@ impl MagiskD {
|
|||||||
let failed_ids: Vec<i32> = client.read_decodable()?;
|
let failed_ids: Vec<i32> = client.read_decodable()?;
|
||||||
if let Some(module_list) = self.module_list.get() {
|
if let Some(module_list) = self.module_list.get() {
|
||||||
for id in failed_ids {
|
for id in failed_ids {
|
||||||
let path = cstr_buf::default()
|
let path = cstr::buf::default()
|
||||||
.join_path(MODULEROOT)
|
.join_path(MODULEROOT)
|
||||||
.join_path(&module_list[id as usize].name)
|
.join_path(&module_list[id as usize].name)
|
||||||
.join_path("zygisk");
|
.join_path("zygisk");
|
||||||
@ -204,7 +204,7 @@ impl MagiskD {
|
|||||||
fn get_mod_dir(&self, mut client: UnixStream) -> LoggedResult<()> {
|
fn get_mod_dir(&self, mut client: UnixStream) -> LoggedResult<()> {
|
||||||
let id: i32 = client.read_decodable()?;
|
let id: i32 = client.read_decodable()?;
|
||||||
let module = &self.module_list.get().unwrap()[id as usize];
|
let module = &self.module_list.get().unwrap()[id as usize];
|
||||||
let dir = cstr_buf::default()
|
let dir = cstr::buf::default()
|
||||||
.join_path(MODULEROOT)
|
.join_path(MODULEROOT)
|
||||||
.join_path(&module.name);
|
.join_path(&module.name);
|
||||||
let fd = open_fd!(&dir, O_RDONLY | O_CLOEXEC)?;
|
let fd = open_fd!(&dir, O_RDONLY | O_CLOEXEC)?;
|
||||||
|
@ -2,7 +2,7 @@ use crate::ffi::MagiskInit;
|
|||||||
use base::libc::{TMPFS_MAGIC, statfs};
|
use base::libc::{TMPFS_MAGIC, statfs};
|
||||||
use base::{
|
use base::{
|
||||||
Directory, FsPath, FsPathBuilder, FsPathMnt, LibcReturn, LoggedResult, ResultExt, Utf8CStr,
|
Directory, FsPath, FsPathBuilder, FsPathMnt, LibcReturn, LoggedResult, ResultExt, Utf8CStr,
|
||||||
cstr, cstr_buf, debug, libc,
|
cstr, debug, libc,
|
||||||
libc::{chdir, chroot, execve, exit, mount},
|
libc::{chdir, chroot, execve, exit, mount},
|
||||||
parse_mount_info, raw_cstr,
|
parse_mount_info, raw_cstr,
|
||||||
};
|
};
|
||||||
@ -38,7 +38,7 @@ pub(crate) fn switch_root(path: &Utf8CStr) {
|
|||||||
|
|
||||||
let mut target = info.target.clone();
|
let mut target = info.target.clone();
|
||||||
let target = Utf8CStr::from_string(&mut target);
|
let target = Utf8CStr::from_string(&mut target);
|
||||||
let new_path = cstr_buf::default()
|
let new_path = cstr::buf::default()
|
||||||
.join_path(path)
|
.join_path(path)
|
||||||
.join_path(info.target.trim_start_matches('/'));
|
.join_path(info.target.trim_start_matches('/'));
|
||||||
new_path.mkdirs(0o755).ok();
|
new_path.mkdirs(0o755).ok();
|
||||||
|
@ -3,7 +3,7 @@ use crate::ffi::MagiskInit;
|
|||||||
use base::libc::{O_CREAT, O_RDONLY, O_WRONLY};
|
use base::libc::{O_CREAT, O_RDONLY, O_WRONLY};
|
||||||
use base::{
|
use base::{
|
||||||
BufReadExt, Directory, FsPath, FsPathBuilder, FsPathMnt, LoggedResult, ResultExt, Utf8CStr,
|
BufReadExt, Directory, FsPath, FsPathBuilder, FsPathMnt, LoggedResult, ResultExt, Utf8CStr,
|
||||||
Utf8CString, clone_attr, cstr, cstr_buf, debug,
|
Utf8CString, clone_attr, cstr, debug,
|
||||||
};
|
};
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::{
|
use std::{
|
||||||
@ -66,14 +66,14 @@ impl MagiskInit {
|
|||||||
mount_list: &mut String,
|
mount_list: &mut String,
|
||||||
) -> LoggedResult<()> {
|
) -> LoggedResult<()> {
|
||||||
let mut dir = Directory::open(src_dir)?;
|
let mut dir = Directory::open(src_dir)?;
|
||||||
let mut con = cstr_buf::default();
|
let mut con = cstr::buf::default();
|
||||||
loop {
|
loop {
|
||||||
match &dir.read()? {
|
match &dir.read()? {
|
||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
Some(e) => {
|
Some(e) => {
|
||||||
let name = e.name();
|
let name = e.name();
|
||||||
let src = cstr_buf::dynamic(256).join_path(src_dir).join_path(name);
|
let src = cstr::buf::dynamic(256).join_path(src_dir).join_path(name);
|
||||||
let dest = cstr_buf::dynamic(256).join_path(dest_dir).join_path(name);
|
let dest = cstr::buf::dynamic(256).join_path(dest_dir).join_path(name);
|
||||||
if dest.exists() {
|
if dest.exists() {
|
||||||
if e.is_dir() {
|
if e.is_dir() {
|
||||||
// Recursive
|
// Recursive
|
||||||
|
Loading…
x
Reference in New Issue
Block a user