mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-22 08:38:29 +00:00
Use ANDROID_DLEXT_FORCE_LOAD
to load second stage if possible
Fix #6095
This commit is contained in:
parent
52ba6d11bc
commit
1735a713cb
@ -51,16 +51,20 @@ static void *unload_first_stage(void *) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__LP64__)
|
||||||
|
// Use symlink to workaround linker bug on old broken Android
|
||||||
|
// https://issuetracker.google.com/issues/36914295
|
||||||
|
#define SECOND_STAGE_PATH "/system/bin/app_process"
|
||||||
|
#else
|
||||||
|
#define SECOND_STAGE_PATH "/system/bin/app_process32"
|
||||||
|
#endif
|
||||||
|
|
||||||
static void second_stage_entry() {
|
static void second_stage_entry() {
|
||||||
zygisk_logging();
|
zygisk_logging();
|
||||||
ZLOGD("inject 2nd stage\n");
|
ZLOGD("inject 2nd stage\n");
|
||||||
|
|
||||||
MAGISKTMP = getenv(MAGISKTMP_ENV);
|
MAGISKTMP = getenv(MAGISKTMP_ENV);
|
||||||
#if defined(__LP64__)
|
self_handle = dlopen(SECOND_STAGE_PATH, RTLD_NOLOAD);
|
||||||
self_handle = dlopen("/system/bin/app_process", RTLD_NOLOAD);
|
|
||||||
#else
|
|
||||||
self_handle = dlopen("/system/bin/app_process32", RTLD_NOLOAD);
|
|
||||||
#endif
|
|
||||||
dlclose(self_handle);
|
dlclose(self_handle);
|
||||||
|
|
||||||
unsetenv(MAGISKTMP_ENV);
|
unsetenv(MAGISKTMP_ENV);
|
||||||
@ -81,12 +85,18 @@ static void first_stage_entry() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load second stage
|
// Load second stage
|
||||||
|
android_dlextinfo info {
|
||||||
|
.flags = ANDROID_DLEXT_FORCE_LOAD
|
||||||
|
};
|
||||||
setenv(INJECT_ENV_2, "1", 1);
|
setenv(INJECT_ENV_2, "1", 1);
|
||||||
#if defined(__LP64__)
|
if (android_dlopen_ext(SECOND_STAGE_PATH, RTLD_LAZY, &info) == nullptr) {
|
||||||
dlopen("/system/bin/app_process", RTLD_LAZY);
|
// Android 5.x doesn't support ANDROID_DLEXT_FORCE_LOAD
|
||||||
#else
|
ZLOGI("ANDROID_DLEXT_FORCE_LOAD is not supported, fallback to dlopen\n");
|
||||||
dlopen("/system/bin/app_process32", RTLD_LAZY);
|
if (dlopen(SECOND_STAGE_PATH, RTLD_LAZY) == nullptr) {
|
||||||
#endif
|
ZLOGE("Cannot load the second stage\n");
|
||||||
|
unsetenv(INJECT_ENV_2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[gnu::constructor]] [[maybe_unused]]
|
[[gnu::constructor]] [[maybe_unused]]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user