From 3a72258df4143b91e3ea9a21ef558b390ec53ded Mon Sep 17 00:00:00 2001 From: snake-4 <18491360+snake-4@users.noreply.github.com> Date: Fri, 3 May 2024 02:30:58 +0200 Subject: [PATCH] Added prop hiding --- .gitmodules | 3 ++ module/jni/Android.mk | 5 +-- module/jni/include/modules.hpp | 1 + module/jni/main.cpp | 4 +-- module/jni/modules.cpp | 60 +++++++++++++++++++++++++++++++++- module/jni/system_properties | 1 + 6 files changed, 69 insertions(+), 5 deletions(-) create mode 160000 module/jni/system_properties diff --git a/.gitmodules b/.gitmodules index df02122..b19adfd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "module/jni/libcxx"] path = module/jni/libcxx url = https://github.com/topjohnwu/libcxx.git +[submodule "module/jni/system_properties"] + path = module/jni/system_properties + url = https://github.com/topjohnwu/system_properties diff --git a/module/jni/Android.mk b/module/jni/Android.mk index 0d3c95f..7d86b01 100644 --- a/module/jni/Android.mk +++ b/module/jni/Android.mk @@ -4,8 +4,9 @@ include $(CLEAR_VARS) LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/elfio LOCAL_MODULE := zygisk LOCAL_SRC_FILES := utils.cpp map_parser.cpp mountinfo_parser.cpp modules.cpp main.cpp -LOCAL_STATIC_LIBRARIES := libcxx +LOCAL_STATIC_LIBRARIES := libcxx libsystemproperties LOCAL_LDLIBS := -llog include $(BUILD_SHARED_LIBRARY) -include jni/libcxx/Android.mk \ No newline at end of file +include jni/libcxx/Android.mk +include jni/system_properties/Android.mk \ No newline at end of file diff --git a/module/jni/include/modules.hpp b/module/jni/include/modules.hpp index be24108..891d8b1 100644 --- a/module/jni/include/modules.hpp +++ b/module/jni/include/modules.hpp @@ -3,3 +3,4 @@ void doUnmount(); void doRemount(); void doHideZygisk(); +void doMrProp(); diff --git a/module/jni/main.cpp b/module/jni/main.cpp index 285d91c..99e5d65 100644 --- a/module/jni/main.cpp +++ b/module/jni/main.cpp @@ -113,9 +113,8 @@ class ZygiskModule : public zygisk::ModuleBase LOGD("Invoking the companion was successful."); else { - LOGW("Invoking the companion failed. Performing operations in Zygote context!"); + LOGW("Invoking the companion failed. Functionality will be limited in Zygote context!"); doUnmount(); - doRemount(); } doHideZygisk(); @@ -165,6 +164,7 @@ void zygisk_companion_handler(int fd) { doUnmount(); doRemount(); + doMrProp(); })); }(); diff --git a/module/jni/modules.cpp b/module/jni/modules.cpp index 4c820f8..19f1b82 100644 --- a/module/jni/modules.cpp +++ b/module/jni/modules.cpp @@ -1,10 +1,18 @@ #include +#include #include +#include #include #include #include #include +// These includes are from the system_properties submodule, not NDK! +#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ +#include +#include +#include + #include "zygisk.hpp" #include "logging.hpp" #include "map_parser.hpp" @@ -45,7 +53,7 @@ static bool shouldUnmount(const mountinfo_entry_t &mount, const mountinfo_root_r if (type == "overlay") { const auto &options = mount.getSuperOptions(); - + if (options.contains("lowerdir") && options.at("lowerdir").starts_with("/data/adb")) return true; @@ -159,3 +167,53 @@ void doHideZygisk() LOGD("libnativebridge.so had_error was reset."); } } + +void doMrProp() +{ + static bool isInitialized = false; + static int resetCount = 0; + if (!isInitialized) + { + isInitialized = __system_properties_init() == 0; + } + + if (!isInitialized) + { + LOGE("Could not initialize system_properties!"); + return; + } + + int ret = __system_property_foreach( + [](const prop_info *pi, void *) + { + if (std::string_view(pi->name).starts_with("ro.") && !pi->is_long()) + { + auto serial = std::atomic_load_explicit(&pi->serial, std::memory_order_relaxed); + + // Well this is a bit dangerous + bool shouldReset = (serial & 0xFF) != 0; + auto length = strlen(pi->value); + + if (!shouldReset) + { + for (size_t i = length; i < PROP_VALUE_MAX; i++) + { + if (pi->value[i] != 0) + { + shouldReset = true; + break; + } + } + } + + if (shouldReset) + { + resetCount++; + __system_property_update(const_cast(pi), pi->value, length); + } + } + }, + nullptr); + + LOGD("__system_property_foreach returned %d. resetCount=%d", ret, resetCount); +} \ No newline at end of file diff --git a/module/jni/system_properties b/module/jni/system_properties new file mode 160000 index 0000000..e1a3e77 --- /dev/null +++ b/module/jni/system_properties @@ -0,0 +1 @@ +Subproject commit e1a3e77d2376be2ba747baa7ba16b34554b14956