Added prop hiding

This commit is contained in:
snake-4
2024-05-03 02:30:58 +02:00
parent b6603b12c2
commit 3a72258df4
6 changed files with 69 additions and 5 deletions

3
.gitmodules vendored
View File

@@ -4,3 +4,6 @@
[submodule "module/jni/libcxx"] [submodule "module/jni/libcxx"]
path = module/jni/libcxx path = module/jni/libcxx
url = https://github.com/topjohnwu/libcxx.git url = https://github.com/topjohnwu/libcxx.git
[submodule "module/jni/system_properties"]
path = module/jni/system_properties
url = https://github.com/topjohnwu/system_properties

View File

@@ -4,8 +4,9 @@ include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/elfio LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/elfio
LOCAL_MODULE := zygisk LOCAL_MODULE := zygisk
LOCAL_SRC_FILES := utils.cpp map_parser.cpp mountinfo_parser.cpp modules.cpp main.cpp 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 LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)
include jni/libcxx/Android.mk include jni/libcxx/Android.mk
include jni/system_properties/Android.mk

View File

@@ -3,3 +3,4 @@
void doUnmount(); void doUnmount();
void doRemount(); void doRemount();
void doHideZygisk(); void doHideZygisk();
void doMrProp();

View File

@@ -113,9 +113,8 @@ public:
LOGD("Invoking the companion was successful."); LOGD("Invoking the companion was successful.");
else else
{ {
LOGW("Invoking the companion failed. Performing operations in Zygote context!"); LOGW("Invoking the companion failed. Functionality will be limited in Zygote context!");
doUnmount(); doUnmount();
doRemount();
} }
doHideZygisk(); doHideZygisk();
@@ -165,6 +164,7 @@ void zygisk_companion_handler(int fd)
{ {
doUnmount(); doUnmount();
doRemount(); doRemount();
doMrProp();
})); }));
}(); }();

View File

@@ -1,10 +1,18 @@
#include <string> #include <string>
#include <string_view>
#include <set> #include <set>
#include <atomic>
#include <unordered_map> #include <unordered_map>
#include <cstdint> #include <cstdint>
#include <sys/mount.h> #include <sys/mount.h>
#include <elfio/elfio.hpp> #include <elfio/elfio.hpp>
// These includes are from the system_properties submodule, not NDK!
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <api/system_properties.h>
#include <api/_system_properties.h>
#include <system_properties/prop_info.h>
#include "zygisk.hpp" #include "zygisk.hpp"
#include "logging.hpp" #include "logging.hpp"
#include "map_parser.hpp" #include "map_parser.hpp"
@@ -159,3 +167,53 @@ void doHideZygisk()
LOGD("libnativebridge.so had_error was reset."); 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<prop_info *>(pi), pi->value, length);
}
}
},
nullptr);
LOGD("__system_property_foreach returned %d. resetCount=%d", ret, resetCount);
}