Skip to content

Commit

Permalink
Fix implementation of UnhookPLT
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JingMatrix committed Sep 23, 2024
1 parent e55ecdf commit bb869ea
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions magisk-loader/src/main/jni/src/magisk_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(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;
};
Expand Down

0 comments on commit bb869ea

Please sign in to comment.