From bb869eac2d4527a64874037916c439af44490d45 Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Mon, 23 Sep 2024 15:14:58 +0200 Subject: [PATCH] Fix implementation of UnhookPLT Currently, inline_unhooker is not used in the code. We still fix the logic to avoid confusion. There is no feasible way to determinate if the parameter original is a valid function pointer or a `const char` pointer. We suppose it as a char pointer in the first step. --- magisk-loader/src/main/jni/src/magisk_loader.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/magisk-loader/src/main/jni/src/magisk_loader.cpp b/magisk-loader/src/main/jni/src/magisk_loader.cpp index 2b32966a15f..6f309e0272a 100644 --- a/magisk-loader/src/main/jni/src/magisk_loader.cpp +++ b/magisk-loader/src/main/jni/src/magisk_loader.cpp @@ -123,19 +123,19 @@ void MagiskLoader::InitializeZygiskApi(zygisk::Api *api) { }; auto UnhookPLT = [HookPLT, &plt_hook_saved](void *original) { - Dl_info info; - - if (!dladdr(original, &info) || info.dli_sname != nullptr) return 1; if (!GetArt()->isStripped()) return UnhookInline(original); + auto symbol = reinterpret_cast(original); auto hook_iter = std::find_if(plt_hook_saved.begin(), plt_hook_saved.end(), - [info](auto record) { return strcmp(record.first, info.dli_sname) == 0; }); + [symbol](auto record) { return strcmp(record.first, symbol) == 0; }); void *stub = nullptr; if (hook_iter != plt_hook_saved.end() && HookPLT(original, *(hook_iter->second), &stub, false)) { plt_hook_saved.erase(hook_iter); return 0; + } else { + return UnhookInline(original); } return 1; };