Skip to content

Commit

Permalink
One stage zygisk loading
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 authored and topjohnwu committed Jan 12, 2024
1 parent df66458 commit 79334b7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
20 changes: 3 additions & 17 deletions native/src/core/zygisk/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,11 @@ using namespace std;
void *self_handle = nullptr;
string native_bridge = "0";

extern "C" [[maybe_unused]] void zygisk_inject_entry(void *handle) {
self_handle = handle;
zygisk_logging();
hook_functions();
ZLOGD("load success\n");
}

static bool is_compatible_with(uint32_t) {
auto name = get_prop(NBPROP);
android_dlextinfo info = {
.flags = ANDROID_DLEXT_FORCE_LOAD
};
void *handle = android_dlopen_ext(name.data(), RTLD_LAZY, &info);
if (handle) {
auto entry = reinterpret_cast<void (*)(void *)>(dlsym(handle, "zygisk_inject_entry"));
if (entry) {
entry(handle);
}
}
android_logging();
hook_functions();
ZLOGD("load success\n");
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions native/src/core/zygisk/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ DCL_HOOK_FUNC(static int, pthread_attr_destroy, void *target) {
if (should_unmap_zygisk) {
g_hook->restore_plt_hook();
if (should_unmap_zygisk) {
ZLOGV("dlclosing self\n");
delete g_hook;

// Because both `pthread_attr_destroy` and `dlclose` have the same function signature,
Expand All @@ -202,13 +203,12 @@ DCL_HOOK_FUNC(static int, pthread_attr_destroy, void *target) {

// it should be safe to assume all dlclose's in libnativebridge are for zygisk_loader
DCL_HOOK_FUNC(static int, dlclose, void *handle) {
static bool kDone = false;
if (!kDone) {
if (!self_handle) {
ZLOGV("dlclose zygisk_loader\n");
kDone = true;
self_handle = handle;
g_hook->post_native_bridge_load();
}
[[clang::musttail]] return old_dlclose(handle);
return 0;
}

#undef DCL_HOOK_FUNC
Expand Down
1 change: 0 additions & 1 deletion native/src/exported_sym.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
zygisk_inject_entry;
NativeBridgeItf;
};

0 comments on commit 79334b7

Please sign in to comment.