Add missing specialize arguments

This commit is contained in:
topjohnwu
2022-03-02 22:01:35 -08:00
parent e0b5645064
commit 80dd37ee31
5 changed files with 123 additions and 63 deletions

View File

@@ -43,8 +43,8 @@ void name##_post();
struct HookContext {
JNIEnv *env;
union {
AppSpecializeArgsImpl *args;
ServerSpecializeArgsImpl *server_args;
AppSpecializeArgs_v3 *args;
ServerSpecializeArgs_v1 *server_args;
void *raw_args;
};
const char *process;
@@ -292,10 +292,11 @@ bool ZygiskModule::RegisterModule(ApiTable *table, long *module) {
// Fill in API accordingly with module API version
switch (ver) {
case 3:
case 2:
table->v2.getModuleDir = [](ZygiskModule *m) { return m->getModuleDir(); };
table->v2.getFlags = [](auto) { return ZygiskModule::getFlags(); };
[[fallthrough]];
// fallthrough
case 1:
table->v1.hookJniNativeMethods = &hookJniNativeMethods;
table->v1.pltHookRegister = [](const char *p, const char *s, void *n, void **o) {
@@ -391,6 +392,19 @@ void HookContext::run_modules_pre(const vector<int> &fds) {
}
}
// Add all ignored fd onto whitelist
if (state[APP_SPECIALIZE] && args->fds_to_ignore) {
int len = env->GetArrayLength(*args->fds_to_ignore);
int *arr = env->GetIntArrayElements(*args->fds_to_ignore, nullptr);
for (int i = 0; i < len; ++i) {
int fd = arr[i];
if (fd >= 0 && fd < 1024) {
open_fds[fd] = true;
}
}
env->ReleaseIntArrayElements(*args->fds_to_ignore, arr, 0);
}
// Close all unrecorded fds
rewinddir(dir.get());
for (dirent *entry; (entry = xreaddir(dir.get()));) {