From 4b55e3d033b8656dc739b52002840393cd37a008 Mon Sep 17 00:00:00 2001 From: solohsu Date: Sun, 17 Feb 2019 04:32:54 +0800 Subject: [PATCH] Fix "ELOOP: too many symbolic links encountered" --- Core/jni/main/native_hook/native_hook.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Core/jni/main/native_hook/native_hook.cpp b/Core/jni/main/native_hook/native_hook.cpp index 7b4a49b3..215bcee8 100644 --- a/Core/jni/main/native_hook/native_hook.cpp +++ b/Core/jni/main/native_hook/native_hook.cpp @@ -80,12 +80,16 @@ static void hook_IsInSamePackage(int api_level, void *artHandle, isInSamePackageSym = "_ZN3art6mirror5Class15IsInSamePackageENS_6ObjPtrIS1_EE"; } void *original = dlsym(artHandle, isInSamePackageSym); - getDesc = reinterpret_cast(dlsym(artHandle, - getDescriptorSym)); if (!original) { - LOGE("can't get isInSamePackageSym"); + LOGE("can't get isInSamePackageSym: %s", dlerror()); return; } + void *getDescSym = dlsym(artHandle, getDescriptorSym); + if (!getDescSym) { + LOGE("can't get GetDescriptorSym: %s", dlerror()); + return; + } + getDesc = reinterpret_cast(getDescSym); (*hookFun)(original, reinterpret_cast(onIsInSamePackageCalled), reinterpret_cast(&isInSamePackageBackup)); } @@ -95,21 +99,21 @@ void install_inline_hooks() { if (api_level < ANDROID_LOLLIPOP) { return; } - void *whaleHandle = dlopen(kLibWhalePath, RTLD_NOW); + void *whaleHandle = dlopen(kLibWhalePath, RTLD_LAZY | RTLD_GLOBAL); if (!whaleHandle) { - LOGE("can't open libwhale"); + LOGE("can't open libwhale: %s", dlerror()); return; } void *hookFunSym = dlsym(whaleHandle, "WInlineHookFunction"); if (!hookFunSym) { - LOGE("can't get WInlineHookFunction"); + LOGE("can't get WInlineHookFunction: %s", dlerror()); return; } void (*hookFun)(void *, void *, void **) = reinterpret_cast(hookFunSym); - void *artHandle = dlopen(kLibArtPath, RTLD_NOW); + void *artHandle = dlopen(kLibArtPath, RTLD_LAZY | RTLD_GLOBAL); if (!artHandle) { - LOGE("can't open libart"); + LOGE("can't open libart: %s", dlerror()); return; } hook_IsInSamePackage(api_level, artHandle, hookFun); @@ -118,5 +122,7 @@ void install_inline_hooks() { } else { LOGE("disable_HiddenAPIPolicyImpl failed."); } + dlclose(whaleHandle); + dlclose(artHandle); }