diff --git a/edxp-core/src/main/cpp/main/include/art/runtime/class_linker.h b/edxp-core/src/main/cpp/main/include/art/runtime/class_linker.h index 6bcdbc90..915d5ea2 100644 --- a/edxp-core/src/main/cpp/main/include/art/runtime/class_linker.h +++ b/edxp-core/src/main/cpp/main/include/art/runtime/class_linker.h @@ -124,13 +124,8 @@ namespace art { HOOK_FUNC(FixupStaticTrampolines, "_ZN3art11ClassLinker22FixupStaticTrampolinesENS_6ObjPtrINS_6mirror5ClassEEE"); - // Sandhook will hook ShouldUseInterpreterEntrypoint, so we just skip - // edxp::Context::GetInstance()->GetVariant() will not work here, so we use smh dirty hack - if (!edxp::path_exists(edxp::kLibSandHookNativePath)) { - LOGD("Not sandhook, installing _ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv"); - HOOK_FUNC(ShouldUseInterpreterEntrypoint, - "_ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv"); - } + HOOK_FUNC(ShouldUseInterpreterEntrypoint, + "_ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv"); // MakeInitializedClassesVisiblyInitialized will cause deadlock // IsQuickToInterpreterBridge cannot be hooked by Dobby yet diff --git a/edxp-core/src/main/cpp/main/include/config.h b/edxp-core/src/main/cpp/main/include/config.h index 33b70734..772cfb48 100644 --- a/edxp-core/src/main/cpp/main/include/config.h +++ b/edxp-core/src/main/cpp/main/include/config.h @@ -37,15 +37,12 @@ inline constexpr bool is64 = Is64(); static const auto kLibArtName = "libart.so"s; static const auto kLibFwName = "libandroidfw.so"s; static const auto kLibSandHookName = "libsandhook.edxp.so"s; - static const auto kLibDlName = "libdl.so"s; - static const auto kLibSandHookNativeName = "libsandhook-native.so"s; static const auto kLibBasePath = LP_SELECT("/system/lib/"s, "/system/lib64/"s); static const auto kLibArtLegacyPath = kLibBasePath + kLibArtName; static const auto kLibSandHookPath = kLibBasePath + kLibSandHookName; - static const auto kLibSandHookNativePath = kLibBasePath + kLibSandHookNativeName; static const auto kLibFwPath = kLibBasePath + kLibFwName; inline constexpr const char *const BoolToString(bool b) { diff --git a/edxp-core/template_override/customize.sh b/edxp-core/template_override/customize.sh index 95f06f3e..da7a9200 100644 --- a/edxp-core/template_override/customize.sh +++ b/edxp-core/template_override/customize.sh @@ -246,7 +246,6 @@ else ui_print "- Extracting arm libraries" extract "$ZIPFILE" 'system/lib/libriru_edxp.so' "$MODPATH" if [[ "${VARIANTS}" == "SandHook" ]]; then - extract "$ZIPFILE" 'system/lib/libsandhook-native.so' "$MODPATH" extract "$ZIPFILE" 'system/lib/libsandhook.edxp.so' "$MODPATH" fi @@ -254,7 +253,6 @@ else ui_print "- Extracting arm64 libraries" extract "$ZIPFILE" 'system/lib64/libriru_edxp.so' "$MODPATH" if [[ "${VARIANTS}" == "SandHook" ]]; then - extract "$ZIPFILE" 'system/lib64/libsandhook-native.so' "$MODPATH" extract "$ZIPFILE" 'system/lib64/libsandhook.edxp.so' "$MODPATH" fi fi diff --git a/edxp-sandhook/template_override/system/lib/libsandhook-native.so b/edxp-sandhook/template_override/system/lib/libsandhook-native.so deleted file mode 100644 index 34a2ce0f..00000000 Binary files a/edxp-sandhook/template_override/system/lib/libsandhook-native.so and /dev/null differ diff --git a/edxp-sandhook/template_override/system/lib64/libsandhook-native.so b/edxp-sandhook/template_override/system/lib64/libsandhook-native.so deleted file mode 100644 index 1d64ee53..00000000 Binary files a/edxp-sandhook/template_override/system/lib64/libsandhook-native.so and /dev/null differ diff --git a/sandhook-hooklib/src/main/cpp/utils/hide_api.cpp b/sandhook-hooklib/src/main/cpp/utils/hide_api.cpp index de0146e1..e6a86480 100644 --- a/sandhook-hooklib/src/main/cpp/utils/hide_api.cpp +++ b/sandhook-hooklib/src/main/cpp/utils/hide_api.cpp @@ -30,23 +30,9 @@ extern "C" { void (*profileSaver_ForceProcessProfiles)() = nullptr; - //for Android R - void *jniIdManager = nullptr; - ArtMethod *(*origin_DecodeArtMethodId)(void *thiz, jmethodID jmethodId) = nullptr; - ArtMethod *replace_DecodeArtMethodId(void *thiz, jmethodID jmethodId) { - jniIdManager = thiz; - return origin_DecodeArtMethodId(thiz, jmethodId); - } + jfieldID fieldArtMethod = nullptr; - bool (*origin_ShouldUseInterpreterEntrypoint)(ArtMethod *artMethod, const void* quick_code) = nullptr; - bool replace_ShouldUseInterpreterEntrypoint(ArtMethod *artMethod, const void* quick_code) { - if (SandHook::TrampolineManager::get().methodHooked(artMethod) && quick_code != nullptr) { - return false; - } - return origin_ShouldUseInterpreterEntrypoint(artMethod, quick_code); - } - - // paths +// paths const char* art_lib_path; const char* jit_lib_path; @@ -139,32 +125,9 @@ extern "C" { profileSaver_ForceProcessProfiles = reinterpret_cast(getSymCompat(art_lib_path, "_ZN3art12ProfileSaver20ForceProcessProfilesEv")); } - //init native hook lib - void* native_hook_handle = dlopen("libsandhook-native.so", RTLD_LAZY | RTLD_GLOBAL); - if (native_hook_handle) { - hook_native = reinterpret_cast(dlsym(native_hook_handle, "SandInlineHook")); - } else { - hook_native = reinterpret_cast(getSymCompat( - "libsandhook-native.so", "SandInlineHook")); - } - - if (SDK_INT >= ANDROID_R && hook_native) { - const char *symbol_decode_method = sizeof(void*) == 8 ? "_ZN3art3jni12JniIdManager15DecodeGenericIdINS_9ArtMethodEEEPT_m" : "_ZN3art3jni12JniIdManager15DecodeGenericIdINS_9ArtMethodEEEPT_j"; - void *decodeArtMethod = getSymCompat(art_lib_path, symbol_decode_method); - if (art_lib_path != nullptr) { - origin_DecodeArtMethodId = reinterpret_cast(hook_native( - decodeArtMethod, - reinterpret_cast(replace_DecodeArtMethodId))); - } - void *shouldUseInterpreterEntrypoint = getSymCompat(art_lib_path, - "_ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv"); - if (shouldUseInterpreterEntrypoint != nullptr) { - origin_ShouldUseInterpreterEntrypoint = reinterpret_cast(hook_native( - shouldUseInterpreterEntrypoint, - reinterpret_cast(replace_ShouldUseInterpreterEntrypoint))); - } + if (SDK_INT >=ANDROID_R) { + auto classExecutable = env->FindClass("java/lang/reflect/Executable"); + fieldArtMethod = env->GetFieldID(classExecutable, "artMethod", "J"); } } @@ -283,8 +246,7 @@ extern "C" { void fake_jit_update_options(void* handle) { //do nothing LOGW("android q: art request update compiler options"); - return; - } + } bool replaceUpdateCompilerOptionsQ() { if (SDK_INT < ANDROID_Q) @@ -349,16 +311,10 @@ extern "C" { } ArtMethod* getArtMethod(JNIEnv *env, jobject method) { - jmethodID methodId = env->FromReflectedMethod(method); - if (SDK_INT >= ANDROID_R && isIndexId(methodId)) { - if (origin_DecodeArtMethodId == nullptr || jniIdManager == nullptr) { - auto res = callStaticMethodAddr(env, "com/swift/sandhook/SandHook", "getArtMethod", - "(Ljava/lang/reflect/Member;)J", method); - return reinterpret_cast(res); - } else { - return origin_DecodeArtMethodId(jniIdManager, methodId); - } + if (SDK_INT >= ANDROID_R) { + return reinterpret_cast(env->GetLongField(method, fieldArtMethod)); } else { + jmethodID methodId = env->FromReflectedMethod(method); return reinterpret_cast(methodId); } } diff --git a/sandhook-hooklib/src/main/java/com/swift/sandhook/SandHook.java b/sandhook-hooklib/src/main/java/com/swift/sandhook/SandHook.java index 231e236b..071616f6 100644 --- a/sandhook-hooklib/src/main/java/com/swift/sandhook/SandHook.java +++ b/sandhook-hooklib/src/main/java/com/swift/sandhook/SandHook.java @@ -95,8 +95,6 @@ public class SandHook { if (SandHookConfig.delayHook && PendingHookHandler.canWork() && ClassStatusUtils.isStaticAndNoInited(entity.target)) { PendingHookHandler.addPendingHook(entity); return; - } else if (entity.initClass) { - resolveStaticMethod(target); } resolveStaticMethod(backup);