Stricter validation

This commit is contained in:
topjohnwu 2022-11-22 14:19:40 -08:00 committed by John Wu
parent cd5384f13e
commit ed37ddd570
2 changed files with 22 additions and 3 deletions

View File

@ -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);

View File

@ -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);