Fix module loading

This commit is contained in:
Nullptr
2023-10-20 23:27:40 +08:00
parent 8c0d5b5395
commit 218659dcbf
2 changed files with 11 additions and 10 deletions

View File

@@ -84,7 +84,7 @@ impl Filesystem for DelegateFilesystem {
let process = &process[..process.find('\0').unwrap()]; let process = &process[..process.find('\0').unwrap()];
info!("Process {} is reading preloaded-classes", process); info!("Process {} is reading preloaded-classes", process);
if process == "zygote64" { if process == "zygote64" {
ptrace_zygote(pid).unwrap() ptrace_zygote(pid).unwrap();
} }
} }
reply.opened(0, 0); reply.opened(0, 0);

View File

@@ -1,6 +1,6 @@
use anyhow::Result; use anyhow::Result;
use std::{fs, io::{Read, Write}, os::unix::net::UnixStream}; use std::{fs, io::{Read, Write}, os::unix::net::UnixStream};
use std::ffi::c_char; use std::ffi::{c_char, CStr, CString};
use std::os::unix::net::UnixListener; use std::os::unix::net::UnixListener;
use std::process::Command; use std::process::Command;
use std::sync::OnceLock; use std::sync::OnceLock;
@@ -57,8 +57,8 @@ pub fn chcon(path: &str, context: &str) -> Result<()> {
} }
pub fn log_raw(level: i32, tag: &str, message: &str) -> Result<()> { pub fn log_raw(level: i32, tag: &str, message: &str) -> Result<()> {
let tag = std::ffi::CString::new(tag)?; let tag = CString::new(tag)?;
let message = std::ffi::CString::new(message)?; let message = CString::new(message)?;
unsafe { unsafe {
__android_log_print(level, tag.as_ptr(), message.as_ptr()); __android_log_print(level, tag.as_ptr(), message.as_ptr());
} }
@@ -66,17 +66,18 @@ pub fn log_raw(level: i32, tag: &str, message: &str) -> Result<()> {
} }
pub fn get_property(name: &str) -> Result<String> { pub fn get_property(name: &str) -> Result<String> {
let name = std::ffi::CString::new(name)?; let name = CString::new(name)?;
let mut buf = vec![0u8; 92]; let mut buf = vec![0u8; 92];
unsafe { let prop = unsafe {
__system_property_get(name.as_ptr(), buf.as_mut_ptr() as *mut c_char); __system_property_get(name.as_ptr(), buf.as_mut_ptr() as *mut c_char);
} CStr::from_bytes_until_nul(&buf)?
Ok(String::from_utf8(buf)?) };
Ok(prop.to_string_lossy().to_string())
} }
pub fn set_property(name: &str, value: &str) -> Result<()> { pub fn set_property(name: &str, value: &str) -> Result<()> {
let name = std::ffi::CString::new(name)?; let name = CString::new(name)?;
let value = std::ffi::CString::new(value)?; let value = CString::new(value)?;
unsafe { unsafe {
__system_property_set(name.as_ptr(), value.as_ptr()); __system_property_set(name.as_ptr(), value.as_ptr());
} }