From 6a61f6a4b6c4aafc9571402590d1feb3e22639bf Mon Sep 17 00:00:00 2001 From: snake-4 <18491360+snake-4@users.noreply.github.com> Date: Sun, 14 Apr 2024 18:37:38 +0200 Subject: [PATCH] Renamed some functions --- module/jni/include/utils.hpp | 4 ++-- module/jni/main.cpp | 22 +++++++++++----------- module/jni/unmount.cpp | 4 ++-- module/jni/utils.cpp | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/module/jni/include/utils.hpp b/module/jni/include/utils.hpp index 5054275..92fba95 100644 --- a/module/jni/include/utils.hpp +++ b/module/jni/include/utils.hpp @@ -6,5 +6,5 @@ ret (*old_##func)(__VA_ARGS__); \ ret new_##func(__VA_ARGS__) -int is_userapp_uid(int uid); -bool hook_plt_by_name(zygisk::Api *api, const std::string &libName, const std::string &symbolName, void *hookFunc, void **origFunc); +int isUserAppUID(int uid); +bool hookPLTByName(zygisk::Api *api, const std::string &libName, const std::string &symbolName, void *hookFunc, void **origFunc); diff --git a/module/jni/main.cpp b/module/jni/main.cpp index 7544c9b..2c6a010 100644 --- a/module/jni/main.cpp +++ b/module/jni/main.cpp @@ -10,8 +10,8 @@ using zygisk::Api; using zygisk::AppSpecializeArgs; using zygisk::ServerSpecializeArgs; -void do_unmount(); -void do_remount(); +void doUnmount(); +void doRemount(); DCL_HOOK_FUNC(static int, unshare, int flags) { @@ -42,12 +42,11 @@ class ZygiskModule : public zygisk::ModuleBase uint32_t flags = api->getFlags(); bool isRoot = (flags & zygisk::StateFlag::PROCESS_GRANTED_ROOT) != 0; bool isOnDenylist = (flags & zygisk::StateFlag::PROCESS_ON_DENYLIST) != 0; - if (isRoot || !isOnDenylist || !is_userapp_uid(args->uid)) + if (isRoot || !isOnDenylist || !isUserAppUID(args->uid)) { LOGD("Skipping pid=%d ppid=%d uid=%d", getpid(), getppid(), args->uid); return; } - LOGD("Processing pid=%d ppid=%d uid=%d", getpid(), getppid(), args->uid); /* @@ -56,7 +55,7 @@ class ZygiskModule : public zygisk::ModuleBase * The logic behind whether there's going to be an unshare or not changes with each major Android version. * For maximum compatibility, we will always unshare but prevent further unshare by this Zygote fork in appSpecialize. */ - if (!plt_hook_wrapper("libandroid_runtime.so", "unshare", new_unshare, (void **)&old_unshare)) + if (!hookPLTByName("libandroid_runtime.so", "unshare", &new_unshare, &old_unshare)) { LOGE("plt_hook_wrapper(\"libandroid_runtime.so\", \"unshare\", new_unshare, old_unshare) returned false"); return; @@ -84,8 +83,8 @@ class ZygiskModule : public zygisk::ModuleBase return; } - do_unmount(); - do_remount(); + doUnmount(); + doRemount(); } void preServerSpecialize(ServerSpecializeArgs *args) override @@ -97,7 +96,7 @@ class ZygiskModule : public zygisk::ModuleBase { if (isHooked) { - if (!plt_hook_wrapper("libandroid_runtime.so", "unshare", old_unshare, nullptr)) + if (!hookPLTByName("libandroid_runtime.so", "unshare", old_unshare)) { LOGE("plt_hook_wrapper(\"libandroid_runtime.so\", \"unshare\", old_unshare, nullptr) returned false"); return; @@ -105,9 +104,10 @@ class ZygiskModule : public zygisk::ModuleBase } } - bool plt_hook_wrapper(const std::string &libName, const std::string &symbolName, void *hookFunction, void **originalFunction) + template + bool hookPLTByName(const std::string &libName, const std::string &symbolName, T *hookFunction, T **originalFunction = nullptr) { - return hook_plt_by_name(api, libName, symbolName, hookFunction, originalFunction) && api->pltHookCommit(); + return ::hookPLTByName(api, libName, symbolName, (void *)hookFunction, (void **)originalFunction) && api->pltHookCommit(); } private: @@ -116,4 +116,4 @@ class ZygiskModule : public zygisk::ModuleBase JNIEnv *env; }; -REGISTER_ZYGISK_MODULE(ZygiskModule) \ No newline at end of file +REGISTER_ZYGISK_MODULE(ZygiskModule) diff --git a/module/jni/unmount.cpp b/module/jni/unmount.cpp index d50ef09..ad98fdb 100644 --- a/module/jni/unmount.cpp +++ b/module/jni/unmount.cpp @@ -57,7 +57,7 @@ static bool shouldUnmount(const mount_entry_t &mount) return false; } -void do_unmount() +void doUnmount() { std::vector mountPoints; @@ -96,7 +96,7 @@ void do_unmount() } } -void do_remount() +void doRemount() { std::vector mounts = parseMountsFromPath("/proc/self/mounts"); auto data_mount_it = std::find_if(mounts.begin(), mounts.end(), [](const mount_entry_t &mount) diff --git a/module/jni/utils.cpp b/module/jni/utils.cpp index 7e47cde..ff7940c 100644 --- a/module/jni/utils.cpp +++ b/module/jni/utils.cpp @@ -5,7 +5,7 @@ #include "android_filesystem_config.h" #include "zygisk.hpp" -bool hook_plt_by_name(zygisk::Api *api, const std::string &libName, const std::string &symbolName, void *hookFunc, void **origFunc) +bool hookPLTByName(zygisk::Api *api, const std::string &libName, const std::string &symbolName, void *hookFunc, void **origFunc) { for (const auto &map : parseMapsFromPath("/proc/self/maps")) { @@ -18,7 +18,7 @@ bool hook_plt_by_name(zygisk::Api *api, const std::string &libName, const std::s return false; } -int is_userapp_uid(int uid) +int isUserAppUID(int uid) { int appid = uid % AID_USER_OFFSET; if (appid >= AID_APP_START && appid <= AID_APP_END)