mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-11-16 07:23:18 +00:00
Refactor Zygisk loading
Co-authored-by: topjohnwu <topjohnwu@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <sys/mount.h>
|
||||
#include <android/dlext.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <magisk.hpp>
|
||||
@@ -13,7 +14,7 @@ using namespace std;
|
||||
// Entrypoint for app_process overlay
|
||||
int app_process_main(int argc, char *argv[]) {
|
||||
android_logging();
|
||||
char buf[256];
|
||||
char buf[PATH_MAX];
|
||||
|
||||
bool zygote = false;
|
||||
if (auto fp = open_file("/proc/self/attr/current", "r")) {
|
||||
@@ -51,9 +52,8 @@ int app_process_main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
close(fds[0]);
|
||||
|
||||
snprintf(buf, sizeof(buf), "/proc/self/fd/%d", app_proc_fd);
|
||||
fcntl(app_proc_fd, F_SETFD, FD_CLOEXEC);
|
||||
execve(buf, argv, environ);
|
||||
fexecve(app_proc_fd, argv, environ);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -70,26 +70,22 @@ int app_process_main(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
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
|
||||
xreadlink("/proc/self/exe", buf, sizeof(buf));
|
||||
if (char *ld = getenv("LD_PRELOAD")) {
|
||||
char env[256];
|
||||
sprintf(env, "%s:%s", ld, lib.data());
|
||||
setenv("LD_PRELOAD", env, 1);
|
||||
string env = ld;
|
||||
env += ':';
|
||||
env += buf;
|
||||
setenv("LD_PRELOAD", env.data(), 1);
|
||||
} else {
|
||||
setenv("LD_PRELOAD", lib.data(), 1);
|
||||
setenv("LD_PRELOAD", buf, 1);
|
||||
}
|
||||
setenv(INJECT_ENV_1, "1", 1);
|
||||
setenv("MAGISKTMP", tmp.data(), 1);
|
||||
setenv(MAGISKTMP_ENV, tmp.data(), 1);
|
||||
|
||||
close(socket);
|
||||
|
||||
snprintf(buf, sizeof(buf), "/proc/self/fd/%d", app_proc_fd);
|
||||
fcntl(app_proc_fd, F_SETFD, FD_CLOEXEC);
|
||||
execve(buf, argv, environ);
|
||||
fexecve(app_proc_fd, argv, environ);
|
||||
} while (false);
|
||||
|
||||
close(socket);
|
||||
|
||||
Reference in New Issue
Block a user