Migrate resetprop to Rust

This commit is contained in:
topjohnwu
2025-08-27 22:48:48 -07:00
committed by John Wu
parent 42d9f87bc9
commit c4e2985677
21 changed files with 678 additions and 655 deletions
+7 -8
View File
@@ -1,8 +1,7 @@
use crate::consts::MODULEROOT;
use crate::daemon::{MagiskD, to_user_id};
use crate::ffi::{
ZygiskRequest, ZygiskStateFlags, get_magisk_tmp, get_prop, set_prop, update_deny_flags,
};
use crate::ffi::{ZygiskRequest, ZygiskStateFlags, get_magisk_tmp, update_deny_flags};
use crate::resetprop::{get_prop, set_prop};
use crate::socket::{IpcRead, UnixSocketExt};
use base::libc::{O_CLOEXEC, O_CREAT, O_RDONLY, STDOUT_FILENO};
use base::{
@@ -132,18 +131,18 @@ impl ZygiskState {
if !self.lib_name.is_empty() {
return;
}
let orig = get_prop(NBPROP, false);
let orig = get_prop(NBPROP);
self.lib_name = if orig.is_empty() || orig == "0" {
ZYGISKLDR.to_string()
} else {
orig + ZYGISKLDR
};
set_prop(NBPROP, Utf8CStr::from_string(&mut self.lib_name), false);
set_prop(NBPROP, Utf8CStr::from_string(&mut self.lib_name));
// Whether Huawei's Maple compiler is enabled.
// If so, system server will be created by a special Zygote which ignores the native bridge
// and make system server out of our control. Avoid it by disabling.
if get_prop(cstr!("ro.maple.enable"), false) == "1" {
set_prop(cstr!("ro.maple.enable"), cstr!("0"), false);
if get_prop(cstr!("ro.maple.enable")) == "1" {
set_prop(cstr!("ro.maple.enable"), cstr!("0"));
}
}
@@ -152,7 +151,7 @@ impl ZygiskState {
if self.lib_name.len() > ZYGISKLDR.len() {
orig = self.lib_name[ZYGISKLDR.len()..].to_string();
}
set_prop(NBPROP, Utf8CStr::from_string(&mut orig), false);
set_prop(NBPROP, Utf8CStr::from_string(&mut orig));
self.lib_name.clear();
}
}
-1
View File
@@ -2,7 +2,6 @@
#include <android/dlext.h>
#include <dlfcn.h>
#include <consts.hpp>
#include <base.hpp>
#include <core.hpp>
+1 -1
View File
@@ -366,7 +366,7 @@ void HookContext::post_native_bridge_load(void *handle) {
auto nb = get_prop(NBPROP);
auto len = sizeof(ZYGISKLDR) - 1;
if (nb.size() > len) {
arg.load_native_bridge(nb.data() + len, arg.callbacks);
arg.load_native_bridge(nb.c_str() + len, arg.callbacks);
}
runtime_callbacks = arg.callbacks;
}