Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ impl ZygiskModule for MyModule {
_env: EnvUnowned,
_args: &<V4 as ZygiskRaw>::AppSpecializeArgs,
) {
let is_full_mode = *IS_FULL_MODE.lock().unwrap();
if !is_full_mode {
if !IS_FULL_MODE.load(std::sync::atomic::Ordering::Relaxed) {
api.set_option(ZygiskOption::DlCloseModuleLibrary);
}
}
Expand Down Expand Up @@ -187,7 +186,7 @@ impl MyModule {

fn apply_lite_mode(api: &mut ZygiskApi<V4>, debug: bool) -> anyhow::Result<()> {
*FAKE_PROPS.lock().unwrap() = None;
*IS_FULL_MODE.lock().unwrap() = false;
IS_FULL_MODE.store(false, std::sync::atomic::Ordering::Relaxed);
if debug {
info!("Lite mode: only Build fields hooked, unloading module");
}
Expand All @@ -211,7 +210,7 @@ impl MyModule {
}

*FAKE_PROPS.lock().unwrap() = Some(prop_map);
*IS_FULL_MODE.lock().unwrap() = true;
IS_FULL_MODE.store(true, std::sync::atomic::Ordering::Relaxed);
hook_system_properties(api, env)?;
hook_native_property_get(api)?;

Expand Down Expand Up @@ -241,7 +240,7 @@ impl MyModule {
}

*FAKE_PROPS.lock().unwrap() = None;
*IS_FULL_MODE.lock().unwrap() = false;
IS_FULL_MODE.store(false, std::sync::atomic::Ordering::Relaxed);
api.set_option(ZygiskOption::DlCloseModuleLibrary);
Ok(())
}
Expand Down
7 changes: 5 additions & 2 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{collections::HashMap, sync::Mutex};
use std::{
collections::HashMap,
sync::{Mutex, atomic::AtomicBool},
};

/// 用于恢复真实属性值的 native_get 原始函数签名。
pub type OriginalNativeGet = unsafe extern "C" fn(
Expand All @@ -9,7 +12,7 @@ pub type OriginalNativeGet = unsafe extern "C" fn(
) -> jni::sys::jstring;

pub static FAKE_PROPS: Mutex<Option<HashMap<String, String>>> = Mutex::new(None);
pub static IS_FULL_MODE: Mutex<bool> = Mutex::new(false);
pub static IS_FULL_MODE: AtomicBool = AtomicBool::new(false);
pub static ACTIVE_RESET_SESSION: Mutex<Option<ActiveResetSession>> = Mutex::new(None);
pub static ORIGINAL_NATIVE_GET: Mutex<Option<OriginalNativeGet>> = Mutex::new(None);

Expand Down