Replace Whale with Dobby and rebase everything

This commit is contained in:
kotori0 2020-11-15 20:02:02 +08:00 committed by solohsu
parent caf38beec2
commit 46b2e87c58
12 changed files with 51 additions and 49 deletions

3
.gitmodules vendored Normal file
View File

@ -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

View File

@ -4,4 +4,13 @@ add_subdirectory(xhook)
add_subdirectory(riru)
add_subdirectory(yahfa)
add_subdirectory(substrate)
add_subdirectory(android)
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)

@ -0,0 +1 @@
Subproject commit 70ae8ee195dd1d7b5e0040efc3cf357b6add9ac6

View File

@ -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})
target_link_libraries(riru_edxp yahfa riru xhook substrate android dobby ${log-lib})

View File

@ -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;

View File

@ -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;
}

View File

@ -8,6 +8,8 @@
#include <art/runtime/runtime.h>
#include <dl_util.h>
#include <art/runtime/jni_env_ext.h>
#include <dobby.h>
#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<soinfo_t> 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<void *>("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<HookFunType>(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<void *(*)(const char *, const char *)>(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;

View File

@ -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