Skip to content

Commit

Permalink
Renamed some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
snake-4 committed Apr 14, 2024
1 parent 6e33358 commit 6a61f6a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions module/jni/include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
22 changes: 11 additions & 11 deletions module/jni/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

/*
Expand All @@ -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;
Expand Down Expand Up @@ -84,8 +83,8 @@ class ZygiskModule : public zygisk::ModuleBase
return;
}

do_unmount();
do_remount();
doUnmount();
doRemount();
}

void preServerSpecialize(ServerSpecializeArgs *args) override
Expand All @@ -97,17 +96,18 @@ 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;
}
}
}

bool plt_hook_wrapper(const std::string &libName, const std::string &symbolName, void *hookFunction, void **originalFunction)
template <typename T>
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:
Expand All @@ -116,4 +116,4 @@ class ZygiskModule : public zygisk::ModuleBase
JNIEnv *env;
};

REGISTER_ZYGISK_MODULE(ZygiskModule)
REGISTER_ZYGISK_MODULE(ZygiskModule)
4 changes: 2 additions & 2 deletions module/jni/unmount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static bool shouldUnmount(const mount_entry_t &mount)
return false;
}

void do_unmount()
void doUnmount()
{
std::vector<std::string> mountPoints;

Expand Down Expand Up @@ -96,7 +96,7 @@ void do_unmount()
}
}

void do_remount()
void doRemount()
{
std::vector<mount_entry_t> mounts = parseMountsFromPath("/proc/self/mounts");
auto data_mount_it = std::find_if(mounts.begin(), mounts.end(), [](const mount_entry_t &mount)
Expand Down
4 changes: 2 additions & 2 deletions module/jni/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand All @@ -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)
Expand Down

0 comments on commit 6a61f6a

Please sign in to comment.