diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..3448c611 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "edxp-core/src/main/cpp/external/Dobby"] + path = edxp-core/src/main/cpp/external/Dobby + url = https://github.com/jmpews/Dobby.git diff --git a/edxp-common/template_override/system/lib/libwhale.edxp.so b/edxp-common/template_override/system/lib/libwhale.edxp.so deleted file mode 100755 index d718e9aa..00000000 Binary files a/edxp-common/template_override/system/lib/libwhale.edxp.so and /dev/null differ diff --git a/edxp-common/template_override/system/lib64/libwhale.edxp.so b/edxp-common/template_override/system/lib64/libwhale.edxp.so deleted file mode 100755 index ccd342dc..00000000 Binary files a/edxp-common/template_override/system/lib64/libwhale.edxp.so and /dev/null differ diff --git a/edxp-common/template_override/system_x86/lib/libwhale.edxp.so b/edxp-common/template_override/system_x86/lib/libwhale.edxp.so deleted file mode 100755 index 618b2f4b..00000000 Binary files a/edxp-common/template_override/system_x86/lib/libwhale.edxp.so and /dev/null differ diff --git a/edxp-common/template_override/system_x86/lib64/libwhale.edxp.so b/edxp-common/template_override/system_x86/lib64/libwhale.edxp.so deleted file mode 100755 index 35d9cf8a..00000000 Binary files a/edxp-common/template_override/system_x86/lib64/libwhale.edxp.so and /dev/null differ diff --git a/edxp-core/src/main/cpp/external/CMakeLists.txt b/edxp-core/src/main/cpp/external/CMakeLists.txt index 79df4435..c8e411b7 100644 --- a/edxp-core/src/main/cpp/external/CMakeLists.txt +++ b/edxp-core/src/main/cpp/external/CMakeLists.txt @@ -4,4 +4,13 @@ add_subdirectory(xhook) add_subdirectory(riru) add_subdirectory(yahfa) add_subdirectory(substrate) -add_subdirectory(android) \ No newline at end of file +add_subdirectory(android) + +macro(SET_OPTION option value) + set(${option} ${value} CACHE INTERNAL "" FORCE) +endmacro() + +SET_OPTION(DOBBY_GENERATE_SHARED OFF) +add_subdirectory(Dobby) +target_include_directories(dobby PUBLIC Dobby/include) +target_include_directories(dobby PUBLIC Dobby/builtin-plugin/AndroidRestriction) \ No newline at end of file diff --git a/edxp-core/src/main/cpp/external/Dobby b/edxp-core/src/main/cpp/external/Dobby new file mode 160000 index 00000000..70ae8ee1 --- /dev/null +++ b/edxp-core/src/main/cpp/external/Dobby @@ -0,0 +1 @@ +Subproject commit 70ae8ee195dd1d7b5e0040efc3cf357b6add9ac6 diff --git a/edxp-core/src/main/cpp/main/CMakeLists.txt b/edxp-core/src/main/cpp/main/CMakeLists.txt index 71a612cb..a120aaf1 100644 --- a/edxp-core/src/main/cpp/main/CMakeLists.txt +++ b/edxp-core/src/main/cpp/main/CMakeLists.txt @@ -8,4 +8,4 @@ include_directories(include src) add_library(riru_edxp SHARED ${SRC_LIST} ${SRC_JNI_LIST}) find_library(log-lib log) -target_link_libraries(riru_edxp yahfa riru xhook substrate android ${log-lib}) \ No newline at end of file +target_link_libraries(riru_edxp yahfa riru xhook substrate android dobby ${log-lib}) \ No newline at end of file diff --git a/edxp-core/src/main/cpp/main/include/config.h b/edxp-core/src/main/cpp/main/include/config.h index 436d180c..cd0a9acd 100644 --- a/edxp-core/src/main/cpp/main/include/config.h +++ b/edxp-core/src/main/cpp/main/include/config.h @@ -45,7 +45,6 @@ namespace edxp { static const auto kLibDlPath = kLibBasePath + kLibDlName; static const auto kLibArtLegacyPath = kLibBasePath + kLibArtName; - static const auto kLibWhalePath = kLibBasePath + kLibWhaleName; static const auto kLibSandHookPath = kLibBasePath + kLibSandHookName; static const auto kLibSandHookNativePath = kLibBasePath + kLibSandHookNativeName; static const auto kLibFwPath = kLibBasePath + kLibFwName; diff --git a/edxp-core/src/main/cpp/main/src/edxp_context.cpp b/edxp-core/src/main/cpp/main/src/edxp_context.cpp index 9ca3deac..b5d09c2f 100644 --- a/edxp-core/src/main/cpp/main/src/edxp_context.cpp +++ b/edxp-core/src/main/cpp/main/src/edxp_context.cpp @@ -159,7 +159,7 @@ namespace edxp { } else { LOG(ERROR) << "No loadClass/findClass method found"; } - LOG(ERROR) << "Class %s not found: " << class_name; + LOG(ERROR) << "Class " << class_name << " not found"; return ret; } diff --git a/edxp-core/src/main/cpp/main/src/native_hook.cpp b/edxp-core/src/main/cpp/main/src/native_hook.cpp index 7e286eb3..7940b61b 100644 --- a/edxp-core/src/main/cpp/main/src/native_hook.cpp +++ b/edxp-core/src/main/cpp/main/src/native_hook.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include "android_restriction.h" // from Dobby #include "logging.h" #include "native_hook.h" @@ -19,6 +21,8 @@ #include "art/runtime/oat_file_manager.h" #include "framework/fd_utils.h" +std::vector linker_get_solist(); // Dobby but not in .h + namespace edxp { static volatile bool installed = false; @@ -35,6 +39,7 @@ namespace edxp { LOGI("Inline hooks have been installed, skip"); return; } + installed = true; LOGI("Start to install inline hooks"); int api_level = GetAndroidApiLevel(); if (UNLIKELY(api_level < __ANDROID_API_L__)) { @@ -43,12 +48,8 @@ namespace edxp { } LOGI("Using api level %d", api_level); InstallRiruHooks(); -#ifdef __LP64__ - ScopedDlHandle whale_handle(kLibWhalePath.c_str()); - if (!whale_handle.IsValid()) { - return; - } - void *hook_func_symbol = whale_handle.DlSym("WInlineHookFunction"); +#ifndef __i386__ // Dobby doesn't support x86 for now + void *hook_func_symbol = (void *)DobbyHook; #else void *hook_func_symbol = (void *) MSHookFunction; #endif @@ -57,15 +58,26 @@ namespace edxp { } hook_func = reinterpret_cast(hook_func_symbol); + // install ART hooks if (api_level >= __ANDROID_API_Q__) { -#if defined(__i386__) || defined(__x86_64__) - ScopedDlHandle dl_handle(kLibDlPath.c_str()); - void *handle = dl_handle.Get(); - HOOK_FUNC(mydlopen, "__loader_dlopen"); -#else - InstallLinkerHooks(kLinkerPath.c_str()); -#endif + // From Riru v22 we can't get ART handle by hooking dlopen, so we get libart.so from soinfo. + // Ref: https://android.googlesource.com/platform/bionic/+/master/linker/linker_soinfo.h + auto solist = linker_get_solist(); + bool found = false; + for (auto & it : solist) { + const char* real_path = linker_soinfo_get_realpath(it); + if (real_path != nullptr && std::string(real_path).find(kLibArtName) != std::string::npos) { + found = true; + InstallArtHooks(it); + break; + } + } + if(!found) { + LOGE("Android 10+ detected and libart.so can't be found in memory."); + return; + } } else { + // do dlopen directly in Android 9- ScopedDlHandle art_handle(kLibArtLegacyPath.c_str()); InstallArtHooks(art_handle.Get()); } @@ -74,36 +86,6 @@ namespace edxp { InstallFwkHooks(fwk_handle.Get()); } - // @ApiSensitive(Level.MIDDLE) - bool InstallLinkerHooks(const char *linker_path) { - // TODO flags - void *handle = dlopen(kLibSandHookNativePath.c_str(), RTLD_NOW); - - if (!handle) { - LOGI("Failed to open libsandhook-native"); - return false; - } - - auto getSym = reinterpret_cast(dlsym(handle, - "SandGetSym")); - if (!getSym) { - LOGI("SandGetSym is null"); - return false; - } - - auto dlopen_symbol = "__dl__Z9do_dlopenPKciPK17android_dlextinfoPKv"; - void *dlopen_addr = getSym(linker_path, dlopen_symbol); - if (dlopen_addr) { - hook_func(dlopen_addr, (void *) mydlopenReplace, - (void **) &mydlopenBackup); - LOGI("dlopen hooked"); - return true; - } - - LOGI("dlopen_addr is null"); - return false; - } - void InstallArtHooks(void *art_handle) { if (art_hooks_installed) { return; diff --git a/edxp-core/template_override/customize.sh b/edxp-core/template_override/customize.sh index b957245c..aebc8fdf 100644 --- a/edxp-core/template_override/customize.sh +++ b/edxp-core/template_override/customize.sh @@ -273,12 +273,20 @@ mv "${MODPATH}/system/framework/eddexmaker.jar" "${MODPATH}/system/framework/${J mv "${MODPATH}/system/framework/edconfig.jar" "${MODPATH}/system/framework/${JAR_EDCONFIG}" mv "${MODPATH}/system/lib/libriru_edxp.so" "${MODPATH}/system/lib/${LIB_RIRU_EDXP}" #mv "${MODPATH}/system/lib/libwhale.edxp.so" "${MODPATH}/system/lib/${LIB_WHALE_EDXP}" +<<<<<<< HEAD #mv "${MODPATH}/system/lib/libsandhook-native.so" "${MODPATH}/system/lib/libsandhook-native.so" +======= +mv "${MODPATH}/system/lib/libsandhook-native.so" "${MODPATH}/system/lib/libsandhook-native.so" +>>>>>>> e43e709... Replace Whale with Dobby by adding submodule if [[ "${IS64BIT}" == true ]]; then mv "${MODPATH}/system/lib64/libriru_edxp.so" "${MODPATH}/system/lib64/${LIB_RIRU_EDXP}" #mv "${MODPATH}/system/lib64/libwhale.edxp.so" "${MODPATH}/system/lib64/${LIB_WHALE_EDXP}" +<<<<<<< HEAD #mv "${MODPATH}/system/lib64/libsandhook-native.so" "${MODPATH}/system/lib64/libsandhook-native.so" +======= + mv "${MODPATH}/system/lib64/libsandhook-native.so" "${MODPATH}/system/lib64/libsandhook-native.so" +>>>>>>> e43e709... Replace Whale with Dobby by adding submodule fi if [[ "${VARIANTS}" == "SandHook" ]]; then @@ -293,14 +301,14 @@ ui_print "- Resetting libraries path" sed -i 's:/system/framework/edxp.jar\:/system/framework/eddalvikdx.jar\:/system/framework/eddexmaker.jar:/system/framework/'"${JAR_EDXP}"'\:/system/framework/'"${JAR_EDDALVIKDX}"'\:/system/framework/'"${JAR_EDDEXMAKER}"':g' "${MODPATH}/system/lib/${LIB_RIRU_EDXP}" sed -i 's:/system/framework/edconfig.jar:/system/framework/'"${JAR_EDCONFIG}"':g' "${MODPATH}/system/lib/${LIB_RIRU_EDXP}" sed -i 's:libriru_edxp.so:'"${LIB_RIRU_EDXP}"':g' "${MODPATH}/system/lib/${LIB_RIRU_EDXP}" -sed -i 's:libwhale.edxp.so:'"${LIB_WHALE_EDXP}"':g' "${MODPATH}/system/lib/${LIB_RIRU_EDXP}" +#sed -i 's:libwhale.edxp.so:'"${LIB_WHALE_EDXP}"':g' "${MODPATH}/system/lib/${LIB_RIRU_EDXP}" sed -i 's:libsandhook.edxp.so:'"${LIB_SANDHOOK_EDXP}"':g' "${MODPATH}/system/lib/${LIB_RIRU_EDXP}" if [[ "${IS64BIT}" == true ]]; then sed -i 's:/system/framework/edxp.jar\:/system/framework/eddalvikdx.jar\:/system/framework/eddexmaker.jar:/system/framework/'"${JAR_EDXP}"'\:/system/framework/'"${JAR_EDDALVIKDX}"'\:/system/framework/'"${JAR_EDDEXMAKER}"':g' "${MODPATH}/system/lib64/${LIB_RIRU_EDXP}" sed -i 's:/system/framework/edconfig.jar:/system/framework/'"${JAR_EDCONFIG}"':g' "${MODPATH}/system/lib64/${LIB_RIRU_EDXP}" sed -i 's:libriru_edxp.so:'"${LIB_RIRU_EDXP}"':g' "${MODPATH}/system/lib64/${LIB_RIRU_EDXP}" - sed -i 's:libwhale.edxp.so:'"${LIB_WHALE_EDXP}"':g' "${MODPATH}/system/lib64/${LIB_RIRU_EDXP}" + #sed -i 's:libwhale.edxp.so:'"${LIB_WHALE_EDXP}"':g' "${MODPATH}/system/lib64/${LIB_RIRU_EDXP}" sed -i 's:libsandhook.edxp.so:'"${LIB_SANDHOOK_EDXP}"':g' "${MODPATH}/system/lib64/${LIB_RIRU_EDXP}" fi