Skip to content

Commit

Permalink
Added prop hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
snake-4 committed May 3, 2024
1 parent b6603b1 commit 3a72258
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions module/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
include jni/libcxx/Android.mk
include jni/system_properties/Android.mk
1 change: 1 addition & 0 deletions module/jni/include/modules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
void doUnmount();
void doRemount();
void doHideZygisk();
void doMrProp();
4 changes: 2 additions & 2 deletions module/jni/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -165,6 +164,7 @@ void zygisk_companion_handler(int fd)
{
doUnmount();
doRemount();
doMrProp();
}));
}();

Expand Down
60 changes: 59 additions & 1 deletion module/jni/modules.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#include <string>
#include <string_view>
#include <set>
#include <atomic>
#include <unordered_map>
#include <cstdint>
#include <sys/mount.h>
#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 "logging.hpp"
#include "map_parser.hpp"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<prop_info *>(pi), pi->value, length);
}
}
},
nullptr);

LOGD("__system_property_foreach returned %d. resetCount=%d", ret, resetCount);
}
1 change: 1 addition & 0 deletions module/jni/system_properties
Submodule system_properties added at e1a3e7

0 comments on commit 3a72258

Please sign in to comment.