diff --git a/native/src/zygisk/hook.cpp b/native/src/zygisk/hook.cpp index 8bd1728f1..9dd9b7457 100644 --- a/native/src/zygisk/hook.cpp +++ b/native/src/zygisk/hook.cpp @@ -313,6 +313,9 @@ ZygiskModule::ZygiskModule(int id, void *handle, void *entry) } bool ZygiskModule::RegisterModuleImpl(ApiTable *api, long *module) { + if (api == nullptr || module == nullptr) + return false; + long api_version = *module; // Unsupported version if (api_version > ZYGISK_API_VERSION) @@ -355,6 +358,24 @@ bool ZygiskModule::RegisterModuleImpl(ApiTable *api, long *module) { return true; } +bool ZygiskModule::valid() const { + if (mod.api_version == nullptr) + return false; + switch (*mod.api_version) { + case 4: + // fallthrough + case 3: + // fallthrough + case 2: + // fallthrough + case 1: + return mod.v1->impl && mod.v1->preAppSpecialize && mod.v1->postAppSpecialize && + mod.v1->preServerSpecialize && mod.v1->postServerSpecialize; + default: + return false; + } +} + int ZygiskModule::connectCompanion() const { if (int fd = zygisk_request(ZygiskRequest::CONNECT_COMPANION); fd >= 0) { write_int(fd, id); diff --git a/native/src/zygisk/module.hpp b/native/src/zygisk/module.hpp index 9ee41a498..bab594ea0 100644 --- a/native/src/zygisk/module.hpp +++ b/native/src/zygisk/module.hpp @@ -180,10 +180,8 @@ struct ZygiskModule { void postServerSpecialize(const ServerSpecializeArgs_v1 *args) const { mod.v1->postServerSpecialize(mod.v1->impl, args); } - bool valid() const { - return entry.fn && mod.api_version; - } + bool valid() const; int connectCompanion() const; int getModuleDir() const; void setOption(zygisk::Option opt);