Commit 8cb1f361 authored by swift_gan's avatar swift_gan Committed by swift_gan

[XposedCompat]fix GetOatQuickMethodHeader error

parent 5818b078
......@@ -5,7 +5,7 @@
#ifndef SANDHOOK_SANDHOOK_NATIVE_H
#define SANDHOOK_SANDHOOK_NATIVE_H
#include "hook.h"
typedef size_t REG;
#define EXPORT __attribute__ ((visibility ("default")))
......
......@@ -49,8 +49,17 @@ include_directories(
src/main/cpp
src/main/cpp/libffi
src/main/cpp/libffi/platform_include
../nativehook/src/main/cpp
)
add_library(sandhook-native
SHARED
IMPORTED)
set_target_properties(sandhook-native
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libsandhook-native.so)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
......@@ -71,6 +80,7 @@ find_library( # Sets the name of the path variable.
target_link_libraries( # Specifies the target library.
sandhook-xp
sandhook-native
# Links the target library to the log library
# included in the NDK.
${log-lib})
......
......@@ -3,8 +3,20 @@
//
#include <cstring>
#include <utils/log.h>
#include "art_jni_trampoline.h"
#include "sandhook_native.h"
//bug fix hooks
void* NewGetOatQuickMethodHeader(void* artMethod, uintptr_t pc) {
std::set<void*>::iterator it = hookMethods.find(artMethod);
if (it != hookMethods.end()) {
LOGE("skip GetOatQuickMethodHeader");
return nullptr;
}
return GetOatQuickMethodHeaderBackup(artMethod, pc);
}
//bug fix hooks
#define EXPORT_LANG_ClASS(c) jclass Types::java_lang_##c; jmethodID Types::java_lang_##c##_init; jmethodID Types::java_value_##c;
......@@ -274,6 +286,13 @@ Java_com_swift_sandhook_xposedcompat_1new_XposedCompat_init(JNIEnv *env, jclass
bridgeMethod = env->FromReflectedMethod(jbridgeMethod);
env->GetJavaVM(&javaVM);
Types::Load(env);
if (sizeof(size_t) == 8) {
GetOatQuickMethodHeaderBackup = reinterpret_cast<void *(*)(void *,
uintptr_t)>(SandInlineHookSym("/system/lib64/libart.so", "_ZN3art9ArtMethod23GetOatQuickMethodHeaderEm", (void*)NewGetOatQuickMethodHeader));
} else {
GetOatQuickMethodHeaderBackup = reinterpret_cast<void *(*)(void *,
uintptr_t)>(SandInlineHookSym("/system/lib/libart.so", "_ZN3art9ArtMethod23GetOatQuickMethodHeaderEj", (void*)NewGetOatQuickMethodHeader));
}
}
extern "C"
......@@ -299,3 +318,9 @@ Java_com_swift_sandhook_xposedcompat_1new_XposedCompat_getJNITrampoline(JNIEnv *
return 0;
}
}
extern "C"
JNIEXPORT void JNICALL
Java_com_swift_sandhook_xposedcompat_1new_XposedCompat_addHookMethod(JNIEnv *env, jclass type, jobject hookMethod) {
hookMethods.insert(env->FromReflectedMethod(hookMethod));
}
......@@ -8,6 +8,7 @@
#include <cstdint>
#include <jni.h>
#include <list>
#include <set>
#include "ffi_cxx.h"
jclass java_lang_Object;
......@@ -16,6 +17,9 @@ jclass bridgeClass;
jmethodID bridgeMethod;
void* (*GetOatQuickMethodHeaderBackup)(void*,uintptr_t) = nullptr;
struct ArtHookParam {
jint slot;
bool is_static_;
......@@ -24,6 +28,7 @@ struct ArtHookParam {
};
std::list<ArtHookParam*> hookParams = std::list<ArtHookParam*>();
std::set<void*> hookMethods = std::set<void*>();
template<typename U, typename T>
U ForceCast(T *x) {
......
......@@ -61,6 +61,7 @@ public class XposedCompat {
private native static long getJNITrampoline(int slot, boolean isStatic, char retShorty, char[] paramsShorty);
private native static void addHookMethod(Member hookMethod);
public static long getJNITrampoline(Member origin, int slot) {
if (origin instanceof Constructor) {
......@@ -98,6 +99,7 @@ public class XposedCompat {
hookInfos[slot] = hookInfo;
try {
SandHook.hook(new HookWrapper.HookEntity(origin, hook, backup));
addHookMethod(hook);
return true;
} catch (HookErrorException e) {
HookLog.e("hook error!", e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment