diff --git a/core/build.gradle b/core/build.gradle index bc595df4..c91a1aec 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -152,7 +152,6 @@ afterEvaluate { def prepareMagiskFilesTask = task("prepareMagiskFiles${variantCapped}", type: Delete) { dependsOn "assemble${variantCapped}" - dependsOn tasks.getByPath(":sandhook-hooklib:copySandHook${variantCapped}LibraryToMagiskTemplate") dependsOn tasks.getByPath(":key-selector:copyKeySelector${variantCapped}LibraryToMagiskTemplate") doFirst { copy { diff --git a/core/src/main/cpp/external/CMakeLists.txt b/core/src/main/cpp/external/CMakeLists.txt index 46f56a4a..e0531e16 100644 --- a/core/src/main/cpp/external/CMakeLists.txt +++ b/core/src/main/cpp/external/CMakeLists.txt @@ -15,4 +15,7 @@ if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") endif (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") add_subdirectory(Dobby) target_include_directories(dobby PUBLIC Dobby/include) -target_include_directories(dobby PUBLIC Dobby/builtin-plugin/BionicLinkerRestriction) \ No newline at end of file +target_include_directories(dobby PUBLIC Dobby/builtin-plugin/BionicLinkerRestriction) + +add_subdirectory(SandHook) +target_include_directories(sandhook.lspd PUBLIC SandHook) \ No newline at end of file diff --git a/sandhook-hooklib/src/main/cpp/CMakeLists.txt b/core/src/main/cpp/external/SandHook/CMakeLists.txt similarity index 78% rename from sandhook-hooklib/src/main/cpp/CMakeLists.txt rename to core/src/main/cpp/external/SandHook/CMakeLists.txt index 87430b32..e5bb4ba5 100644 --- a/sandhook-hooklib/src/main/cpp/CMakeLists.txt +++ b/core/src/main/cpp/external/SandHook/CMakeLists.txt @@ -5,6 +5,7 @@ ENABLE_LANGUAGE(ASM) add_definitions(-std=c++11) +if (${CMAKE_ANDROID_ARCH_ABI} STREQUAL armeabi-v7a OR ${CMAKE_ANDROID_ARCH_ABI} STREQUAL arm64-v8a) set(${PROJECT_NAME}_SOURCES sandhook.cpp trampoline/trampoline.cpp @@ -25,9 +26,11 @@ set(${PROJECT_NAME}_SOURCES inst/insts_arm64.cpp nativehook/native_hook.cpp ) - +else() + set(${PROJECT_NAME}_SOURCES dummy.cpp) +endif() add_library(${PROJECT_NAME} - SHARED + STATIC ${${PROJECT_NAME}_SOURCES}) target_link_libraries(${PROJECT_NAME} log) \ No newline at end of file diff --git a/sandhook-hooklib/src/main/cpp/art/art_classlinker.cpp b/core/src/main/cpp/external/SandHook/art/art_classlinker.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/art/art_classlinker.cpp rename to core/src/main/cpp/external/SandHook/art/art_classlinker.cpp diff --git a/sandhook-hooklib/src/main/cpp/art/art_compiler_options.cpp b/core/src/main/cpp/external/SandHook/art/art_compiler_options.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/art/art_compiler_options.cpp rename to core/src/main/cpp/external/SandHook/art/art_compiler_options.cpp diff --git a/sandhook-hooklib/src/main/cpp/art/art_method.cpp b/core/src/main/cpp/external/SandHook/art/art_method.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/art/art_method.cpp rename to core/src/main/cpp/external/SandHook/art/art_method.cpp diff --git a/sandhook-hooklib/src/main/cpp/casts/cast_art_method.cpp b/core/src/main/cpp/external/SandHook/casts/cast_art_method.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/casts/cast_art_method.cpp rename to core/src/main/cpp/external/SandHook/casts/cast_art_method.cpp diff --git a/sandhook-hooklib/src/main/cpp/casts/cast_compiler_options.cpp b/core/src/main/cpp/external/SandHook/casts/cast_compiler_options.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/casts/cast_compiler_options.cpp rename to core/src/main/cpp/external/SandHook/casts/cast_compiler_options.cpp diff --git a/core/src/main/cpp/external/SandHook/dummy.cpp b/core/src/main/cpp/external/SandHook/dummy.cpp new file mode 100644 index 00000000..8d299843 --- /dev/null +++ b/core/src/main/cpp/external/SandHook/dummy.cpp @@ -0,0 +1,10 @@ +// +// Created by Kotori0 on 2021/1/30. +// +#include "sandhook.h" +#include "includes/log.h" + +bool JNI_Load_Ex(JNIEnv* env, jclass classSandHook, jclass classNeverCall) { + LOGE("Sandhook: Unsupported platform."); + return false; +} \ No newline at end of file diff --git a/sandhook-hooklib/src/main/cpp/includes/arch.h b/core/src/main/cpp/external/SandHook/includes/arch.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/arch.h rename to core/src/main/cpp/external/SandHook/includes/arch.h diff --git a/sandhook-hooklib/src/main/cpp/includes/arch_base.h b/core/src/main/cpp/external/SandHook/includes/arch_base.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/arch_base.h rename to core/src/main/cpp/external/SandHook/includes/arch_base.h diff --git a/sandhook-hooklib/src/main/cpp/includes/art_classlinker.h b/core/src/main/cpp/external/SandHook/includes/art_classlinker.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/art_classlinker.h rename to core/src/main/cpp/external/SandHook/includes/art_classlinker.h diff --git a/sandhook-hooklib/src/main/cpp/includes/art_compiler_options.h b/core/src/main/cpp/external/SandHook/includes/art_compiler_options.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/art_compiler_options.h rename to core/src/main/cpp/external/SandHook/includes/art_compiler_options.h diff --git a/sandhook-hooklib/src/main/cpp/includes/art_jit.h b/core/src/main/cpp/external/SandHook/includes/art_jit.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/art_jit.h rename to core/src/main/cpp/external/SandHook/includes/art_jit.h diff --git a/sandhook-hooklib/src/main/cpp/includes/art_method.h b/core/src/main/cpp/external/SandHook/includes/art_method.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/art_method.h rename to core/src/main/cpp/external/SandHook/includes/art_method.h diff --git a/sandhook-hooklib/src/main/cpp/includes/art_runtime.h b/core/src/main/cpp/external/SandHook/includes/art_runtime.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/art_runtime.h rename to core/src/main/cpp/external/SandHook/includes/art_runtime.h diff --git a/sandhook-hooklib/src/main/cpp/includes/cast.h b/core/src/main/cpp/external/SandHook/includes/cast.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/cast.h rename to core/src/main/cpp/external/SandHook/includes/cast.h diff --git a/sandhook-hooklib/src/main/cpp/includes/cast_art_method.h b/core/src/main/cpp/external/SandHook/includes/cast_art_method.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/cast_art_method.h rename to core/src/main/cpp/external/SandHook/includes/cast_art_method.h diff --git a/sandhook-hooklib/src/main/cpp/includes/cast_compiler_options.h b/core/src/main/cpp/external/SandHook/includes/cast_compiler_options.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/cast_compiler_options.h rename to core/src/main/cpp/external/SandHook/includes/cast_compiler_options.h diff --git a/sandhook-hooklib/src/main/cpp/includes/dlfcn_nougat.h b/core/src/main/cpp/external/SandHook/includes/dlfcn_nougat.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/dlfcn_nougat.h rename to core/src/main/cpp/external/SandHook/includes/dlfcn_nougat.h diff --git a/sandhook-hooklib/src/main/cpp/includes/elf_util.h b/core/src/main/cpp/external/SandHook/includes/elf_util.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/elf_util.h rename to core/src/main/cpp/external/SandHook/includes/elf_util.h diff --git a/sandhook-hooklib/src/main/cpp/includes/hide_api.h b/core/src/main/cpp/external/SandHook/includes/hide_api.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/hide_api.h rename to core/src/main/cpp/external/SandHook/includes/hide_api.h diff --git a/sandhook-hooklib/src/main/cpp/includes/inst.h b/core/src/main/cpp/external/SandHook/includes/inst.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/inst.h rename to core/src/main/cpp/external/SandHook/includes/inst.h diff --git a/sandhook-hooklib/src/main/cpp/includes/log.h b/core/src/main/cpp/external/SandHook/includes/log.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/log.h rename to core/src/main/cpp/external/SandHook/includes/log.h diff --git a/sandhook-hooklib/src/main/cpp/includes/native_hook.h b/core/src/main/cpp/external/SandHook/includes/native_hook.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/native_hook.h rename to core/src/main/cpp/external/SandHook/includes/native_hook.h diff --git a/sandhook-hooklib/src/main/cpp/includes/never_call.h b/core/src/main/cpp/external/SandHook/includes/never_call.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/never_call.h rename to core/src/main/cpp/external/SandHook/includes/never_call.h diff --git a/sandhook-hooklib/src/main/cpp/includes/offset.h b/core/src/main/cpp/external/SandHook/includes/offset.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/offset.h rename to core/src/main/cpp/external/SandHook/includes/offset.h diff --git a/sandhook-hooklib/src/main/cpp/includes/sandhook.h b/core/src/main/cpp/external/SandHook/includes/sandhook.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/sandhook.h rename to core/src/main/cpp/external/SandHook/includes/sandhook.h diff --git a/sandhook-hooklib/src/main/cpp/includes/trampoline.h b/core/src/main/cpp/external/SandHook/includes/trampoline.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/trampoline.h rename to core/src/main/cpp/external/SandHook/includes/trampoline.h diff --git a/sandhook-hooklib/src/main/cpp/includes/trampoline_manager.h b/core/src/main/cpp/external/SandHook/includes/trampoline_manager.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/trampoline_manager.h rename to core/src/main/cpp/external/SandHook/includes/trampoline_manager.h diff --git a/sandhook-hooklib/src/main/cpp/includes/utils.h b/core/src/main/cpp/external/SandHook/includes/utils.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/includes/utils.h rename to core/src/main/cpp/external/SandHook/includes/utils.h diff --git a/sandhook-hooklib/src/main/cpp/inst/insts_arm32.cpp b/core/src/main/cpp/external/SandHook/inst/insts_arm32.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/inst/insts_arm32.cpp rename to core/src/main/cpp/external/SandHook/inst/insts_arm32.cpp diff --git a/sandhook-hooklib/src/main/cpp/inst/insts_arm64.cpp b/core/src/main/cpp/external/SandHook/inst/insts_arm64.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/inst/insts_arm64.cpp rename to core/src/main/cpp/external/SandHook/inst/insts_arm64.cpp diff --git a/sandhook-hooklib/src/main/cpp/nativehook/native_hook.cpp b/core/src/main/cpp/external/SandHook/nativehook/native_hook.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/nativehook/native_hook.cpp rename to core/src/main/cpp/external/SandHook/nativehook/native_hook.cpp diff --git a/sandhook-hooklib/src/main/cpp/sandhook.cpp b/core/src/main/cpp/external/SandHook/sandhook.cpp similarity index 99% rename from sandhook-hooklib/src/main/cpp/sandhook.cpp rename to core/src/main/cpp/external/SandHook/sandhook.cpp index 3add5a6d..436b85a1 100644 --- a/sandhook-hooklib/src/main/cpp/sandhook.cpp +++ b/core/src/main/cpp/external/SandHook/sandhook.cpp @@ -547,8 +547,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_VERSION_1_6; } -extern "C" -JNIEXPORT bool JNI_Load_Ex(JNIEnv* env, jclass classSandHook, jclass classNeverCall) { +bool JNI_Load_Ex(JNIEnv* env, jclass classSandHook, jclass classNeverCall) { int jniMethodSize = sizeof(JNINativeMethod); if (env == nullptr || classSandHook == nullptr || classNeverCall == nullptr) diff --git a/core/src/main/cpp/external/SandHook/sandhook.h b/core/src/main/cpp/external/SandHook/sandhook.h new file mode 100644 index 00000000..35a316a7 --- /dev/null +++ b/core/src/main/cpp/external/SandHook/sandhook.h @@ -0,0 +1,9 @@ +// +// Created by Kotori0 on 2021/1/29. +// + +#ifndef EDXPOSED_SANDHOOK_H +#define EDXPOSED_SANDHOOK_H +#include +bool JNI_Load_Ex(JNIEnv* env, jclass classSandHook, jclass classNeverCall); +#endif //EDXPOSED_SANDHOOK_H diff --git a/sandhook-hooklib/src/main/cpp/trampoline/arch/arm32.S b/core/src/main/cpp/external/SandHook/trampoline/arch/arm32.S similarity index 100% rename from sandhook-hooklib/src/main/cpp/trampoline/arch/arm32.S rename to core/src/main/cpp/external/SandHook/trampoline/arch/arm32.S diff --git a/sandhook-hooklib/src/main/cpp/trampoline/arch/arm64.S b/core/src/main/cpp/external/SandHook/trampoline/arch/arm64.S similarity index 100% rename from sandhook-hooklib/src/main/cpp/trampoline/arch/arm64.S rename to core/src/main/cpp/external/SandHook/trampoline/arch/arm64.S diff --git a/sandhook-hooklib/src/main/cpp/trampoline/trampoline.cpp b/core/src/main/cpp/external/SandHook/trampoline/trampoline.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/trampoline/trampoline.cpp rename to core/src/main/cpp/external/SandHook/trampoline/trampoline.cpp diff --git a/sandhook-hooklib/src/main/cpp/trampoline/trampoline_manager.cpp b/core/src/main/cpp/external/SandHook/trampoline/trampoline_manager.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/trampoline/trampoline_manager.cpp rename to core/src/main/cpp/external/SandHook/trampoline/trampoline_manager.cpp diff --git a/sandhook-hooklib/src/main/cpp/utils/dlfcn_nougat.cpp b/core/src/main/cpp/external/SandHook/utils/dlfcn_nougat.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/utils/dlfcn_nougat.cpp rename to core/src/main/cpp/external/SandHook/utils/dlfcn_nougat.cpp diff --git a/sandhook-hooklib/src/main/cpp/utils/elf_util.cpp b/core/src/main/cpp/external/SandHook/utils/elf_util.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/utils/elf_util.cpp rename to core/src/main/cpp/external/SandHook/utils/elf_util.cpp diff --git a/sandhook-hooklib/src/main/cpp/utils/hide_api.cpp b/core/src/main/cpp/external/SandHook/utils/hide_api.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/utils/hide_api.cpp rename to core/src/main/cpp/external/SandHook/utils/hide_api.cpp diff --git a/sandhook-hooklib/src/main/cpp/utils/lock.h b/core/src/main/cpp/external/SandHook/utils/lock.h similarity index 100% rename from sandhook-hooklib/src/main/cpp/utils/lock.h rename to core/src/main/cpp/external/SandHook/utils/lock.h diff --git a/sandhook-hooklib/src/main/cpp/utils/offset.cpp b/core/src/main/cpp/external/SandHook/utils/offset.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/utils/offset.cpp rename to core/src/main/cpp/external/SandHook/utils/offset.cpp diff --git a/sandhook-hooklib/src/main/cpp/utils/utils.cpp b/core/src/main/cpp/external/SandHook/utils/utils.cpp similarity index 100% rename from sandhook-hooklib/src/main/cpp/utils/utils.cpp rename to core/src/main/cpp/external/SandHook/utils/utils.cpp diff --git a/core/src/main/cpp/external/yahfa/CMakeLists.txt b/core/src/main/cpp/external/yahfa/CMakeLists.txt index 53fb50fd..392bfc24 100644 --- a/core/src/main/cpp/external/yahfa/CMakeLists.txt +++ b/core/src/main/cpp/external/yahfa/CMakeLists.txt @@ -2,8 +2,7 @@ cmake_minimum_required(VERSION 3.4.1) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall -Wextra -fvisibility=hidden") -aux_source_directory(src SRC_LIST) -add_library(yahfa STATIC ${SRC_LIST}) +add_library(yahfa STATIC src/HookMain.cpp src/trampoline.c) find_library(log-lib log) target_link_libraries(yahfa ${log-lib}) diff --git a/core/src/main/cpp/external/yahfa/include/HookMain.h b/core/src/main/cpp/external/yahfa/include/HookMain.h index 70bf4e4f..cdd2ad79 100644 --- a/core/src/main/cpp/external/yahfa/include/HookMain.h +++ b/core/src/main/cpp/external/yahfa/include/HookMain.h @@ -19,7 +19,7 @@ jboolean Java_lab_galaxy_yahfa_HookMain_backupAndHookNative(JNIEnv *env, jclass void setNonCompilable(void *method); -void *getArtMethod(JNIEnv *env, jobject jmethod); +void *getArtMethodYahfa(JNIEnv *env, jobject jmethod); #ifdef __cplusplus } diff --git a/core/src/main/cpp/external/yahfa/include/trampoline.h b/core/src/main/cpp/external/yahfa/include/trampoline.h index 69fd7458..56611b81 100644 --- a/core/src/main/cpp/external/yahfa/include/trampoline.h +++ b/core/src/main/cpp/external/yahfa/include/trampoline.h @@ -4,7 +4,9 @@ #ifndef YAHFA_TAMPOLINE_H #define YAHFA_TAMPOLINE_H - +#ifdef __cplusplus +extern "C" { +#endif extern int SDKVersion; extern int OFFSET_entry_point_from_quick_compiled_code_in_ArtMethod; @@ -18,5 +20,7 @@ void setupTrampoline(); void *genTrampoline(void *hookMethod); #define DEFAULT_CAP 1 //size of each trampoline area would be no more than 4k Bytes(one page) - +#ifdef __cplusplus +} +#endif #endif //YAHFA_TAMPOLINE_H diff --git a/core/src/main/cpp/external/yahfa/src/HookMain.c b/core/src/main/cpp/external/yahfa/src/HookMain.cpp similarity index 80% rename from core/src/main/cpp/external/yahfa/src/HookMain.c rename to core/src/main/cpp/external/yahfa/src/HookMain.cpp index 1532645d..b567f214 100644 --- a/core/src/main/cpp/external/yahfa/src/HookMain.c +++ b/core/src/main/cpp/external/yahfa/src/HookMain.cpp @@ -1,8 +1,7 @@ #include "jni.h" -#include +#include #include -#include -#include +#include #include "common.h" #include "trampoline.h" @@ -21,7 +20,7 @@ static uint32_t kAccProtected = 0x0004; // field, method, ic static uint32_t kAccStatic = 0x0008; // field, method, ic -static jfieldID fieldArtMethod = NULL; +static jfieldID fieldArtMethod = nullptr; static inline uint32_t read32(void *addr) { return *((uint32_t *) addr); @@ -39,14 +38,14 @@ static inline void writeAddr(void *addr, void *value) { *((void **) addr) = value; } -void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVersion) { +extern "C" void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVersion) { SDKVersion = sdkVersion; jclass classExecutable; LOGI("init to SDK %d", sdkVersion); switch (sdkVersion) { case __ANDROID_API_R__: - classExecutable = (*env)->FindClass(env, "java/lang/reflect/Executable"); - fieldArtMethod = (*env)->GetFieldID(env, classExecutable, "artMethod", "J"); + classExecutable = env->FindClass("java/lang/reflect/Executable"); + fieldArtMethod = env->GetFieldID(classExecutable, "artMethod", "J"); case __ANDROID_API_Q__: case __ANDROID_API_P__: kAccCompileDontBother = 0x02000000; @@ -188,63 +187,61 @@ static int doBackupAndHook(JNIEnv *env, void *targetMethod, void *hookMethod, vo return 0; } -void *getArtMethod(JNIEnv *env, jobject jmethod) { - void *artMethod = NULL; +void *getArtMethodYahfa(JNIEnv *env, jobject jmethod) { + void *artMethod = nullptr; - if (jmethod == NULL) { + if (jmethod == nullptr) { return artMethod; } if (SDKVersion == __ANDROID_API_R__) { - artMethod = (void *) (*env)->GetLongField(env, jmethod, fieldArtMethod); + artMethod = (void *) env->GetLongField(jmethod, fieldArtMethod); } else { - artMethod = (void *) (*env)->FromReflectedMethod(env, jmethod); + artMethod = (void *) env->FromReflectedMethod(jmethod); } LOGI("ArtMethod: %p", artMethod); return artMethod; - } -jobject Java_lab_galaxy_yahfa_HookMain_findMethodNative(JNIEnv *env, jclass clazz, +extern "C" jobject Java_lab_galaxy_yahfa_HookMain_findMethodNative(JNIEnv *env, jclass clazz, jclass targetClass, jstring methodName, jstring methodSig) { - const char *c_methodName = (*env)->GetStringUTFChars(env, methodName, NULL); - const char *c_methodSig = (*env)->GetStringUTFChars(env, methodSig, NULL); - jobject ret = NULL; + const char *c_methodName = env->GetStringUTFChars(methodName, nullptr); + const char *c_methodSig = env->GetStringUTFChars(methodSig, nullptr); + jobject ret = nullptr; //Try both GetMethodID and GetStaticMethodID -- Whatever works :) - jmethodID method = (*env)->GetMethodID(env, targetClass, c_methodName, c_methodSig); - if (!(*env)->ExceptionCheck(env)) { - ret = (*env)->ToReflectedMethod(env, targetClass, method, JNI_FALSE); + jmethodID method = env->GetMethodID(targetClass, c_methodName, c_methodSig); + if (!env->ExceptionCheck()) { + ret = env->ToReflectedMethod(targetClass, method, JNI_FALSE); } else { - (*env)->ExceptionClear(env); - method = (*env)->GetStaticMethodID(env, targetClass, c_methodName, c_methodSig); - if (!(*env)->ExceptionCheck(env)) { - ret = (*env)->ToReflectedMethod(env, targetClass, method, JNI_TRUE); + env->ExceptionClear(); + method = env->GetStaticMethodID(targetClass, c_methodName, c_methodSig); + if (!env->ExceptionCheck()) { + ret = env->ToReflectedMethod(targetClass, method, JNI_TRUE); } else { - (*env)->ExceptionClear(env); + env->ExceptionClear(); } } - (*env)->ReleaseStringUTFChars(env, methodName, c_methodName); - (*env)->ReleaseStringUTFChars(env, methodSig, c_methodSig); + env->ReleaseStringUTFChars(methodName, c_methodName); + env->ReleaseStringUTFChars(methodSig, c_methodSig); return ret; } -jboolean Java_lab_galaxy_yahfa_HookMain_backupAndHookNative(JNIEnv *env, jclass clazz, +extern "C" jboolean Java_lab_galaxy_yahfa_HookMain_backupAndHookNative(JNIEnv *env, jclass clazz, jobject target, jobject hook, jobject backup) { if (!doBackupAndHook(env, - getArtMethod(env, target), - getArtMethod(env, hook), - getArtMethod(env, backup) + getArtMethodYahfa(env, target), + getArtMethodYahfa(env, hook), + getArtMethodYahfa(env, backup) )) { - (*env)->NewGlobalRef(env, - hook); // keep a global ref so that the hook method would not be GCed - if (backup) (*env)->NewGlobalRef(env, backup); + env->NewGlobalRef(hook); // keep a global ref so that the hook method would not be GCed + if (backup) env->NewGlobalRef(backup); return JNI_TRUE; } else { return JNI_FALSE; diff --git a/core/src/main/cpp/main/CMakeLists.txt b/core/src/main/cpp/main/CMakeLists.txt index eab0db5b..2f59bc66 100644 --- a/core/src/main/cpp/main/CMakeLists.txt +++ b/core/src/main/cpp/main/CMakeLists.txt @@ -9,4 +9,4 @@ add_library(riru_lspd SHARED ${SRC_LIST} ${SRC_JNI_LIST}) find_package(riru REQUIRED CONFIG) find_library(log-lib log) -target_link_libraries(riru_lspd yahfa riru::riru xhook android dobby ${log-lib}) \ No newline at end of file +target_link_libraries(riru_lspd yahfa riru::riru xhook android dobby sandhook.lspd ${log-lib}) \ No newline at end of file diff --git a/core/src/main/cpp/main/src/config_manager.h b/core/src/main/cpp/main/src/config_manager.h index b7db3a5c..89237759 100644 --- a/core/src/main/cpp/main/src/config_manager.h +++ b/core/src/main/cpp/main/src/config_manager.h @@ -63,13 +63,6 @@ namespace lspd { return misc_path_ / "cache" / suffix; } - inline static auto GetLibSandHookName() { - if constexpr(lspd::is64) - return GetFrameworkPath("lib64/libsandhook.lspd.so"); - else - return GetFrameworkPath("lib/libsandhook.lspd.so"); - } - inline auto GetConfigPath(const std::string &suffix = {}) const { return base_config_path_ / "conf" / suffix; } diff --git a/core/src/main/cpp/main/src/context.cpp b/core/src/main/cpp/main/src/context.cpp index ef1aeb0c..17395e76 100644 --- a/core/src/main/cpp/main/src/context.cpp +++ b/core/src/main/cpp/main/src/context.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include "context.h" @@ -126,25 +127,19 @@ namespace lspd { RegisterPendingHooks(env); variant_ = Variant(ConfigManager::GetInstance()->GetVariant()); -// LOGI("EdxpVariant: %d", variant_); + LOGI("LSP Variant: %d", variant_); initialized_ = true; if (variant_ == SANDHOOK) { //for SandHook variant - ScopedDlHandle sandhook_handle(ConfigManager::GetLibSandHookName().c_str()); - if (!sandhook_handle.IsValid()) { - return; - } - typedef bool *(*TYPE_JNI_LOAD)(JNIEnv *, jclass, jclass); - auto jni_load = sandhook_handle.DlSym("JNI_Load_Ex"); ScopedLocalRef sandhook_class(env, FindClassFromLoader(env, kSandHookClassName)); ScopedLocalRef nevercall_class(env, FindClassFromLoader(env, kSandHookNeverCallClassName)); if (sandhook_class == nullptr || nevercall_class == nullptr) { // fail-fast return; } - if (!jni_load(env, sandhook_class.get(), nevercall_class.get())) { + if (!JNI_Load_Ex(env, sandhook_class.get(), nevercall_class.get())) { LOGE("SandHook: HookEntry class error. %d", getpid()); } diff --git a/core/src/main/cpp/main/src/jni/art_class_linker.cpp b/core/src/main/cpp/main/src/jni/art_class_linker.cpp index b5df1eda..6a8390fe 100644 --- a/core/src/main/cpp/main/src/jni/art_class_linker.cpp +++ b/core/src/main/cpp/main/src/jni/art_class_linker.cpp @@ -12,7 +12,7 @@ namespace lspd { static std::unordered_set deopted_methods; static void ClassLinker_setEntryPointsToInterpreter(JNI_START, jobject method) { - void *reflected_method = getArtMethod(env, method); + void *reflected_method = getArtMethodYahfa(env, method); if (deopted_methods.count(reflected_method)) { LOGD("method %p has been deopted before, skip...", reflected_method); return; diff --git a/core/src/main/cpp/main/src/jni/config_manager.cpp b/core/src/main/cpp/main/src/jni/config_manager.cpp index 8144dedc..5341cfd0 100644 --- a/core/src/main/cpp/main/src/jni/config_manager.cpp +++ b/core/src/main/cpp/main/src/jni/config_manager.cpp @@ -19,10 +19,6 @@ namespace lspd { return env->NewStringUTF(ConfigManager::GetInstance()->GetInstallerPackageName().c_str()); } - static jstring ConfigManager_getLibSandHookName(JNI_START) { - return env->NewStringUTF(ConfigManager::GetLibSandHookName().c_str()); - } - static jstring ConfigManager_getDataPathPrefix(JNI_START) { return env->NewStringUTF(ConfigManager::GetInstance()->GetDataPathPrefix().c_str()); } @@ -71,7 +67,6 @@ namespace lspd { NATIVE_METHOD(ConfigManager, isResourcesHookEnabled, "()Z"), NATIVE_METHOD(ConfigManager, isNoModuleLogEnabled, "()Z"), NATIVE_METHOD(ConfigManager, getInstallerPackageName, "()Ljava/lang/String;"), - NATIVE_METHOD(ConfigManager, getLibSandHookName, "()Ljava/lang/String;"), NATIVE_METHOD(ConfigManager, getDataPathPrefix, "()Ljava/lang/String;"), NATIVE_METHOD(ConfigManager, getPrefsPath, "(Ljava/lang/String;)Ljava/lang/String;"), diff --git a/core/src/main/cpp/main/src/jni/pending_hooks.cpp b/core/src/main/cpp/main/src/jni/pending_hooks.cpp index 76e8b16d..1f4f21db 100644 --- a/core/src/main/cpp/main/src/jni/pending_hooks.cpp +++ b/core/src/main/cpp/main/src/jni/pending_hooks.cpp @@ -31,7 +31,7 @@ namespace lspd { static void PendingHooks_recordPendingMethodNative(JNI_START, jobject method_ref, jclass class_ref) { auto *class_ptr = art::Thread::Current().DecodeJObject(class_ref); - auto *method = getArtMethod(env, method_ref); + auto *method = getArtMethodYahfa(env, method_ref); art::mirror::Class mirror_class(class_ptr); if (auto def = mirror_class.GetClassDef(); LIKELY(def)) { LOGD("record pending: %p (%s) with %p", class_ptr, mirror_class.GetDescriptor().c_str(), method); diff --git a/core/src/main/cpp/main/src/jni/yahfa.cpp b/core/src/main/cpp/main/src/jni/yahfa.cpp index f2f0d43b..d132d6f0 100644 --- a/core/src/main/cpp/main/src/jni/yahfa.cpp +++ b/core/src/main/cpp/main/src/jni/yahfa.cpp @@ -25,11 +25,11 @@ namespace lspd { } static void Yahfa_recordHooked(JNI_START, jobject member) { - lspd::recordHooked(getArtMethod(env, member)); + lspd::recordHooked(getArtMethodYahfa(env, member)); } static jboolean Yahfa_isHooked(JNI_START, jobject member) { - return lspd::isHooked(getArtMethod(env, member)); + return lspd::isHooked(getArtMethodYahfa(env, member)); } static JNINativeMethod gMethods[] = { diff --git a/core/src/main/java/io/github/lsposed/lspd/config/ConfigManager.java b/core/src/main/java/io/github/lsposed/lspd/config/ConfigManager.java index 6d874f27..cbac55c2 100644 --- a/core/src/main/java/io/github/lsposed/lspd/config/ConfigManager.java +++ b/core/src/main/java/io/github/lsposed/lspd/config/ConfigManager.java @@ -12,8 +12,6 @@ public class ConfigManager { public static native String getInstallerPackageName(); - public static native String getLibSandHookName(); - public static native String getPrefsPath(String suffix); public static native String getCachePath(String suffix); diff --git a/core/src/main/java/io/swift/sandhook/xposedcompat/methodgen/SandHookXposedBridge.java b/core/src/main/java/io/swift/sandhook/xposedcompat/methodgen/SandHookXposedBridge.java index 39e5b6c3..6f4bd3e1 100644 --- a/core/src/main/java/io/swift/sandhook/xposedcompat/methodgen/SandHookXposedBridge.java +++ b/core/src/main/java/io/swift/sandhook/xposedcompat/methodgen/SandHookXposedBridge.java @@ -120,13 +120,7 @@ public final class SandHookXposedBridge { } public static void init() { - if (Process.is64Bit()) { -// SandHookConfig.libSandHookPath = "/system/lib64/libsandhook.lspd.so"; - SandHookConfig.libSandHookPath = "/system/lib64/" + ConfigManager.getLibSandHookName(); - } else { -// SandHookConfig.libSandHookPath = "/system/lib/libsandhook.lspd.so"; - SandHookConfig.libSandHookPath = "/system/lib/" + ConfigManager.getLibSandHookName(); - } + SandHookConfig.libSandHookPath = ""; SandHookConfig.libLoader = new SandHookConfig.LibLoader() { @Override public void loadLib() { diff --git a/core/template_override/customize.sh b/core/template_override/customize.sh index 66e92141..796cbd4d 100644 --- a/core/template_override/customize.sh +++ b/core/template_override/customize.sh @@ -46,10 +46,6 @@ VERSION=$(grep_prop version "${TMPDIR}/module.prop") RIRU_MIN_API_VERSION=$(grep_prop api "${TMPDIR}/module.prop") LIB_RIRU_EDXP="libriru_${RIRU_EDXP}.so" -LIB_SANDHOOK_EDXP="lib$(getRandomNameExist 13 "lib" ".so" " -/system/lib -/system/lib64 -").so" ### lang start ### # Default en_US @@ -187,12 +183,10 @@ if [ "$ARCH" = "x86" ] || [ "$ARCH" = "x64" ]; then else ui_print "- ${LANG_CUST_INST_EXT_LIB_ARM}" extract "$ZIPFILE" 'system/lib/libriru_lspd.so' "${MODPATH}" - extract "$ZIPFILE" 'system/lib/libsandhook.lspd.so' "${MODPATH}" if [ "$IS64BIT" = true ]; then ui_print "- ${LANG_CUST_INST_EXT_LIB_ARM64}" extract "$ZIPFILE" 'system/lib64/libriru_lspd.so' "${MODPATH}" - extract "$ZIPFILE" 'system/lib64/libsandhook.lspd.so' "${MODPATH}" fi fi @@ -246,9 +240,9 @@ set_perm /data/misc/$MISC_PATH root root 0771 "u:object_r:magisk_file:s0" || abo echo "[[ -f /data/adb/lspd/keep_data ]] || rm -rf /data/misc/$MISC_PATH" >> "${MODPATH}/uninstall.sh" || abortC "! ${LANG_CUST_ERR_CONF_UNINST}" echo "[[ -f /data/adb/lspd/new_install ]] || rm -rf /data/adb/lspd" >> "${MODPATH}/uninstall.sh" || abortC "! ${LANG_CUST_ERR_CONF_UNINST}" -if [ $VARIANT == 17 ]; then +if [ $VARIANT == 17 ]; then # YAHFA echo "1" > /data/misc/$MISC_PATH/variant -elif [ $VARIANT == 18 ]; then +elif [ $VARIANT == 18 ]; then # SandHook echo "2" > /data/misc/$MISC_PATH/variant else abortC "${LANG_UTIL_ERR_VARIANT_UNSUPPORT} ${VARIANT}" @@ -261,10 +255,8 @@ mv "${MODPATH}/system/framework" "/data/misc/$MISC_PATH/framework" mkdir -p "/data/misc/$MISC_PATH/framework/lib" -mv "${MODPATH}/system/lib/libsandhook.lspd.so" "/data/misc/$MISC_PATH/framework/lib/libsandhook.lspd.so" if [ "$IS64BIT" = true ]; then mkdir -p "/data/misc/$MISC_PATH/framework/lib64" - mv "${MODPATH}/system/lib64/libsandhook.lspd.so" "/data/misc/$MISC_PATH/framework/lib64/libsandhook.lspd.so" fi set_perm_recursive /data/misc/$MISC_PATH/framework root root 0755 0644 "u:object_r:magisk_file:s0" || abortC "! ${LANG_CUST_ERR_PERM}" diff --git a/sandhook-hooklib/build.gradle b/sandhook-hooklib/build.gradle index bb106263..cbeba763 100644 --- a/sandhook-hooklib/build.gradle +++ b/sandhook-hooklib/build.gradle @@ -9,23 +9,9 @@ android { versionCode 1 versionName "1.0" - externalNativeBuild { - cmake { - //arguments "-DCMAKE_BUILD_TYPE=Release" - } - } - ndk { - abiFilters 'armeabi-v7a', 'arm64-v8a' - } consumerProguardFiles 'proguard-rules.pro' } - externalNativeBuild { - cmake { - path "src/main/cpp/CMakeLists.txt" - } - } - buildTypes { release { minifyEnabled false @@ -38,28 +24,4 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') api project(':sandhook-annotation') -} - -afterEvaluate { - android.libraryVariants.all { variant -> - def variantNameCapped = variant.name.capitalize() - def variantNameLowered = variant.name.toLowerCase() - - task("copySandHook${variantNameCapped}LibraryToMagiskTemplate") { - def libPathRelease = "${buildDir}/intermediates/cmake/${variantNameLowered}/obj" - doLast { - copy { - include "libsandhook.lspd.so" - from "${libPathRelease}/armeabi-v7a" - into "${zipPathMagiskReleasePath}/system/lib" - } - copy { - include "libsandhook.lspd.so" - from "${libPathRelease}/arm64-v8a" - into "${zipPathMagiskReleasePath}/system/lib64" - } - } - } - - } -} +} \ No newline at end of file