Support setting more options

This commit is contained in:
topjohnwu
2021-10-21 03:20:04 -07:00
parent ffb5d9ea9c
commit 4194ac894c
3 changed files with 51 additions and 27 deletions

View File

@@ -282,7 +282,7 @@ bool ZygiskModule::registerModule(ApiTable *table, long *module) {
};
table->v1.pltHookCommit = []() { return xhook_refresh(0) == 0; };
table->v1.connectCompanion = [](ZygiskModule *m) { return m->connectCompanion(); };
table->v1.forceDenyListUnmount = [](auto) { ZygiskModule::forceDenyListUnmount(); };
table->v1.setOption = [](ZygiskModule *m, auto opt) { m->setOption(opt); };
return true;
}
@@ -297,10 +297,17 @@ int ZygiskModule::connectCompanion() const {
return -1;
}
void ZygiskModule::forceDenyListUnmount() {
void ZygiskModule::setOption(zygisk::Option opt) {
if (g_ctx == nullptr)
return;
g_ctx->toggle_unmount();
switch (opt) {
case zygisk::FORCE_DENYLIST_UNMOUNT:
g_ctx->toggle_unmount();
break;
case zygisk::DLCLOSE_MODULE_LIBRARY:
unload = true;
break;
}
}
void HookContext::run_modules_pre(const vector<int> &fds) {
@@ -311,7 +318,7 @@ void HookContext::run_modules_pre(const vector<int> &fds) {
void (*module_entry)(void *, void *);
*(void **) &module_entry = dlsym(h, "zygisk_module_entry");
if (module_entry) {
modules.emplace_back(i);
modules.emplace_back(i, h);
auto api = new ApiTable(&modules.back());
module_entry(api, env);
}
@@ -334,6 +341,9 @@ void HookContext::run_modules_post() {
} else if (flags[SERVER_SPECIALIZE]) {
m.postServerSpecialize(server_args);
}
if (m.unload) {
dlclose(m.handle);
}
}
}