Commit 19478899 authored by swift_gan's avatar swift_gan

pre support Android Q

parent a9597adf
...@@ -42,5 +42,7 @@ static void clearCacheArm32(char* begin, char *end) ...@@ -42,5 +42,7 @@ static void clearCacheArm32(char* begin, char *end)
#define ANDROID_O 26 #define ANDROID_O 26
#define ANDROID_O2 27 #define ANDROID_O2 27
#define ANDROID_P 28 #define ANDROID_P 28
//could not 29
#define ANDROID_Q 29
#endif //SANDHOOK_ARCH_H #endif //SANDHOOK_ARCH_H
\ No newline at end of file
...@@ -33,6 +33,8 @@ extern "C" { ...@@ -33,6 +33,8 @@ extern "C" {
void* getInterpreterBridge(bool isNative); void* getInterpreterBridge(bool isNative);
bool replaceUpdateCompilerOptionsQ();
} }
#endif //SANDHOOK_HIDE_API_H #endif //SANDHOOK_HIDE_API_H
...@@ -306,6 +306,7 @@ JNIEXPORT jboolean JNICALL ...@@ -306,6 +306,7 @@ JNIEXPORT jboolean JNICALL
Java_com_swift_sandhook_SandHook_disableVMInline(JNIEnv *env, jclass type) { Java_com_swift_sandhook_SandHook_disableVMInline(JNIEnv *env, jclass type) {
if (SDK_INT < ANDROID_N) if (SDK_INT < ANDROID_N)
return JNI_FALSE; return JNI_FALSE;
replaceUpdateCompilerOptionsQ();
art::CompilerOptions* compilerOptions = getGlobalCompilerOptions(); art::CompilerOptions* compilerOptions = getGlobalCompilerOptions();
if (compilerOptions == nullptr) if (compilerOptions == nullptr)
return JNI_FALSE; return JNI_FALSE;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "../includes/hide_api.h" #include "../includes/hide_api.h"
#include "../includes/arch.h" #include "../includes/arch.h"
#include "../includes/elf_util.h" #include "../includes/elf_util.h"
#include "../includes/log.h"
extern int SDK_INT; extern int SDK_INT;
...@@ -13,6 +14,7 @@ extern "C" { ...@@ -13,6 +14,7 @@ extern "C" {
void* (*jitLoad)(bool*) = nullptr; void* (*jitLoad)(bool*) = nullptr;
void* jitCompilerHandle = nullptr; void* jitCompilerHandle = nullptr;
bool (*jitCompileMethod)(void*, void*, void*, bool) = nullptr; bool (*jitCompileMethod)(void*, void*, void*, bool) = nullptr;
bool (*jitCompileMethodQ)(void*, void*, void*, bool, bool) = nullptr;
void (*innerSuspendVM)() = nullptr; void (*innerSuspendVM)() = nullptr;
void (*innerResumeVM)() = nullptr; void (*innerResumeVM)() = nullptr;
...@@ -21,6 +23,9 @@ extern "C" { ...@@ -21,6 +23,9 @@ extern "C" {
art::jit::JitCompiler** globalJitCompileHandlerAddr = nullptr; art::jit::JitCompiler** globalJitCompileHandlerAddr = nullptr;
//for Android Q
void (**origin_jit_update_options)(void *) = nullptr;
void* (*get)(bool*) = nullptr; void* (*get)(bool*) = nullptr;
const char* art_lib_path; const char* art_lib_path;
...@@ -40,8 +45,14 @@ extern "C" { ...@@ -40,8 +45,14 @@ extern "C" {
//init compile //init compile
if (SDK_INT >= ANDROID_N) { if (SDK_INT >= ANDROID_N) {
jitCompileMethod = reinterpret_cast<bool (*)(void *, void *, void *, if (SDK_INT >= ANDROID_Q) {
bool)>(getSymCompat(jit_lib_path, "jit_compile_method")); jitCompileMethodQ = reinterpret_cast<bool (*)(void *, void *, void *, bool,
bool)>(getSymCompat(jit_lib_path, "jit_compile_method"));
} else {
jitCompileMethod = reinterpret_cast<bool (*)(void *, void *, void *,
bool)>(getSymCompat(jit_lib_path,
"jit_compile_method"));
}
jitLoad = reinterpret_cast<void* (*)(bool*)>(getSymCompat(jit_lib_path, "jit_load")); jitLoad = reinterpret_cast<void* (*)(bool*)>(getSymCompat(jit_lib_path, "jit_load"));
bool generate_debug_info = false; bool generate_debug_info = false;
jitCompilerHandle = (jitLoad)(&generate_debug_info); jitCompilerHandle = (jitLoad)(&generate_debug_info);
...@@ -79,19 +90,26 @@ extern "C" { ...@@ -79,19 +90,26 @@ extern "C" {
if (SDK_INT >= ANDROID_N) { if (SDK_INT >= ANDROID_N) {
globalJitCompileHandlerAddr = reinterpret_cast<art::jit::JitCompiler **>(getSymCompat(art_lib_path, "_ZN3art3jit3Jit20jit_compiler_handle_E")); globalJitCompileHandlerAddr = reinterpret_cast<art::jit::JitCompiler **>(getSymCompat(art_lib_path, "_ZN3art3jit3Jit20jit_compiler_handle_E"));
SandHook::ElfImg elfImg(art_lib_path); }
void* sym = reinterpret_cast<void *>(elfImg.getSymbAddress("art_quick_to_interpreter_bridge"));
int i = 1; if (SDK_INT >= ANDROID_Q) {
origin_jit_update_options = reinterpret_cast<void (**)(void *)>(getSymCompat(art_lib_path, "_ZN3art3jit3Jit20jit_update_options_E"));
} }
} }
bool compileMethod(void* artMethod, void* thread) { bool compileMethod(void* artMethod, void* thread) {
if (jitCompileMethod == nullptr) { if (SDK_INT >= ANDROID_Q) {
return false; if (jitCompileMethodQ == nullptr) {
return false;
}
return jitCompileMethodQ(jitCompilerHandle, artMethod, thread, false, false);
} else {
if (jitCompileMethod == nullptr) {
return false;
}
return jitCompileMethod(jitCompilerHandle, artMethod, thread, false);
} }
return jitCompileMethod(jitCompilerHandle, artMethod, thread, false);
} }
void suspendVM() { void suspendVM() {
...@@ -169,5 +187,23 @@ extern "C" { ...@@ -169,5 +187,23 @@ extern "C" {
} }
} }
//to replace jit_update_option
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)
return false;
if (origin_jit_update_options == nullptr
|| origin_jit_update_options <= 0
|| *origin_jit_update_options == nullptr
|| *origin_jit_update_options <= 0)
return false;
*origin_jit_update_options = fake_jit_update_options;
}
} }
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