From 983b74be779d0dd9342b29d658602abaafbab441 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 27 Oct 2021 03:25:54 -0700 Subject: [PATCH] Pass MAGISKTMP over to zygote --- native/jni/zygisk/entry.cpp | 10 +++++++--- native/jni/zygisk/main.cpp | 9 +++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/native/jni/zygisk/entry.cpp b/native/jni/zygisk/entry.cpp index 0bd455015..a0b44b736 100644 --- a/native/jni/zygisk/entry.cpp +++ b/native/jni/zygisk/entry.cpp @@ -70,8 +70,9 @@ static void zygisk_cleanup_wait() { #define SECOND_STAGE_PTR "ZYGISK_PTR" -static void second_stage_entry(void *handle, char *path) { +static void second_stage_entry(void *handle, const char *tmp, char *path) { self_handle = handle; + MAGISKTMP = tmp; unsetenv(INJECT_ENV_2); unsetenv(SECOND_STAGE_PTR); @@ -101,6 +102,8 @@ static void first_stage_entry() { ZLOGD("inject 1st stage\n"); char *ld = getenv("LD_PRELOAD"); + char tmp[128]; + strlcpy(tmp, getenv("MAGISKTMP"), sizeof(tmp)); char *path; if (char *c = strrchr(ld, ':')) { *c = '\0'; @@ -111,6 +114,7 @@ static void first_stage_entry() { path = strdup(ld); } unsetenv(INJECT_ENV_1); + unsetenv("MAGISKTMP"); sanitize_environ(); // Update path to 2nd stage lib @@ -128,7 +132,7 @@ static void first_stage_entry() { char *env = getenv(SECOND_STAGE_PTR); decltype(&second_stage_entry) second_stage; sscanf(env, "%p", &second_stage); - second_stage(handle, path); + second_stage(handle, tmp, path); } __attribute__((constructor)) @@ -308,7 +312,7 @@ static void setup_files(int client, const sock_cred *cred) { string path = MAGISKTMP + "/" ZYGISKBIN "/zygisk." + basename(buf); cp_afc(buf, (path + ".1.so").data()); cp_afc(buf, (path + ".2.so").data()); - write_string(client, path); + write_string(client, MAGISKTMP); } static void magiskd_passthrough(int client) { diff --git a/native/jni/zygisk/main.cpp b/native/jni/zygisk/main.cpp index 46864550a..b46f8dab4 100644 --- a/native/jni/zygisk/main.cpp +++ b/native/jni/zygisk/main.cpp @@ -69,8 +69,12 @@ int app_process_main(int argc, char *argv[]) { if (app_proc_fd < 0) break; - string path = read_string(socket); - string lib = path + ".1.so"; + string tmp = read_string(socket); +#if defined(__LP64__) + string lib = tmp + "/" ZYGISKBIN "/zygisk.app_process64.1.so"; +#else + string lib = tmp + "/" ZYGISKBIN "/zygisk.app_process32.1.so"; +#endif if (char *ld = getenv("LD_PRELOAD")) { char env[256]; sprintf(env, "%s:%s", ld, lib.data()); @@ -79,6 +83,7 @@ int app_process_main(int argc, char *argv[]) { setenv("LD_PRELOAD", lib.data(), 1); } setenv(INJECT_ENV_1, "1", 1); + setenv("MAGISKTMP", tmp.data(), 1); close(socket);