Skip to content

Commit

Permalink
Update main.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
snake-4 committed Mar 25, 2024
1 parent c630bb1 commit 5f30e2b
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions module/jni/main.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/* Copyright 2022-2023 John "topjohnwu" Wu
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/

#include <cstdlib>
#include <unistd.h>
#include <fcntl.h>
Expand All @@ -23,28 +9,31 @@ using zygisk::Api;
using zygisk::AppSpecializeArgs;
using zygisk::ServerSpecializeArgs;

class ZygiskModule : public zygisk::ModuleBase {
class ZygiskModule : public zygisk::ModuleBase
{
public:
void onLoad(Api *api, JNIEnv *env) override {
void onLoad(Api *api, JNIEnv *env) override
{
this->api = api;
this->env = env;
}

void preAppSpecialize(AppSpecializeArgs *args) override {
uint32_t flags = api->getFlags();
void preAppSpecialize(AppSpecializeArgs *args) override
{
api->setOption(zygisk::Option::DLCLOSE_MODULE_LIBRARY);

if (flags & zygisk::StateFlag::PROCESS_GRANTED_ROOT) {
return;
}
uint32_t flags = api->getFlags();
bool isRoot = (flags & zygisk::StateFlag::PROCESS_GRANTED_ROOT) != 0;
bool isOnDenylist = (flags & zygisk::StateFlag::PROCESS_ON_DENYLIST) != 0;

if ((flags & zygisk::PROCESS_ON_DENYLIST) && args->uid > 1000) {
if (!isRoot && isOnDenylist && args->uid > 1000)
{
api->setOption(zygisk::Option::FORCE_DENYLIST_UNMOUNT);
}
api->setOption(zygisk::Option::DLCLOSE_MODULE_LIBRARY);
return;
}

void preServerSpecialize(ServerSpecializeArgs *args) override {
void preServerSpecialize(ServerSpecializeArgs *args)
{
api->setOption(zygisk::Option::DLCLOSE_MODULE_LIBRARY);
}

Expand Down

0 comments on commit 5f30e2b

Please sign in to comment.