Commit a4a49bb9 authored by swift_gan's avatar swift_gan

fix call origin with android p 32bit

parent bd2c91b1
...@@ -30,18 +30,35 @@ void disableCompilable(art::mirror::ArtMethod* method) { ...@@ -30,18 +30,35 @@ void disableCompilable(art::mirror::ArtMethod* method) {
uint32_t accessFlag = SandHook::CastArtMethod::accessFlag->get(method); uint32_t accessFlag = SandHook::CastArtMethod::accessFlag->get(method);
if (SDK_INT >= ANDROID_O2) { if (SDK_INT >= ANDROID_O2) {
accessFlag |= 0x02000000; accessFlag |= 0x02000000;
accessFlag |= 0x00800000;
} else { } else {
accessFlag |= 0x01000000; accessFlag |= 0x01000000;
} }
SandHook::CastArtMethod::accessFlag->set(method, accessFlag); SandHook::CastArtMethod::accessFlag->set(method, accessFlag);
} }
void tryDisableInline(art::mirror::ArtMethod* method) {
if (method == nullptr)
return;
if (SDK_INT < ANDROID_O)
return;
uint32_t accessFlag = SandHook::CastArtMethod::accessFlag->get(method);
accessFlag &= ~ 0x08000000;
SandHook::CastArtMethod::accessFlag->set(method, accessFlag);
}
void disableInterpreterForO(art::mirror::ArtMethod* method) { void disableInterpreterForO(art::mirror::ArtMethod* method) {
uint32_t accessFlag = SandHook::CastArtMethod::accessFlag->get(method); uint32_t accessFlag = SandHook::CastArtMethod::accessFlag->get(method);
accessFlag |= 0x0100; accessFlag |= 0x0100;
SandHook::CastArtMethod::accessFlag->set(method, accessFlag); SandHook::CastArtMethod::accessFlag->set(method, accessFlag);
} }
void disableAccessCheck(art::mirror::ArtMethod* method) {
uint32_t accessFlag = SandHook::CastArtMethod::accessFlag->get(method);
accessFlag |= 0x00080000;
SandHook::CastArtMethod::accessFlag->set(method, accessFlag);
}
void setPrivate(art::mirror::ArtMethod* method) { void setPrivate(art::mirror::ArtMethod* method) {
uint32_t accessFlag = SandHook::CastArtMethod::accessFlag->get(method); uint32_t accessFlag = SandHook::CastArtMethod::accessFlag->get(method);
accessFlag &= ~ 0x1; accessFlag &= ~ 0x1;
...@@ -49,6 +66,12 @@ void setPrivate(art::mirror::ArtMethod* method) { ...@@ -49,6 +66,12 @@ void setPrivate(art::mirror::ArtMethod* method) {
SandHook::CastArtMethod::accessFlag->set(method, accessFlag); SandHook::CastArtMethod::accessFlag->set(method, accessFlag);
} }
void setStatic(art::mirror::ArtMethod* method) {
uint32_t accessFlag = SandHook::CastArtMethod::accessFlag->get(method);
accessFlag |= 0x0008;
SandHook::CastArtMethod::accessFlag->set(method, accessFlag);
}
bool isAbsMethod(art::mirror::ArtMethod* method) { bool isAbsMethod(art::mirror::ArtMethod* method) {
uint32_t accessFlags = SandHook::CastArtMethod::accessFlag->get(method); uint32_t accessFlags = SandHook::CastArtMethod::accessFlag->get(method);
return ((accessFlags & 0x0400) != 0); return ((accessFlags & 0x0400) != 0);
...@@ -92,6 +115,16 @@ bool doHookWithReplacement(art::mirror::ArtMethod *originMethod, ...@@ -92,6 +115,16 @@ bool doHookWithReplacement(art::mirror::ArtMethod *originMethod,
} }
if (backupMethod != nullptr) { if (backupMethod != nullptr) {
memcpy(backupMethod, originMethod, SandHook::CastArtMethod::size); memcpy(backupMethod, originMethod, SandHook::CastArtMethod::size);
if (SDK_INT >= ANDROID_N) {
disableCompilable(backupMethod);
}
if (SDK_INT >= ANDROID_O) {
disableInterpreterForO(backupMethod);
}
tryDisableInline(backupMethod);
disableAccessCheck(backupMethod);
setPrivate(backupMethod);
SandHook::Trampoline::flushCache(reinterpret_cast<Size>(originMethod), SandHook::CastArtMethod::size);
} }
if (SDK_INT >= ANDROID_O) { if (SDK_INT >= ANDROID_O) {
disableInterpreterForO(originMethod); disableInterpreterForO(originMethod);
...@@ -128,13 +161,13 @@ bool doHookWithInline(JNIEnv* env, ...@@ -128,13 +161,13 @@ bool doHookWithInline(JNIEnv* env,
SandHook::Trampoline::flushCache(reinterpret_cast<Size>(originMethod), SandHook::CastArtMethod::size); SandHook::Trampoline::flushCache(reinterpret_cast<Size>(originMethod), SandHook::CastArtMethod::size);
} }
tryDisableInline(originMethod);
disableAccessCheck(originMethod);
SandHook::HookTrampoline* hookTrampoline = trampolineManager.installInlineTrampoline(originMethod, hookMethod, backupMethod, isNative(originMethod)); SandHook::HookTrampoline* hookTrampoline = trampolineManager.installInlineTrampoline(originMethod, hookMethod, backupMethod, isNative(originMethod));
if (hookTrampoline == nullptr) if (hookTrampoline == nullptr)
return false; return false;
// void* entryPointFormInterpreter = SandHook::CastArtMethod::entryPointFormInterpreter->get(hookMethod);
// if (entryPointFormInterpreter != NULL) {
// SandHook::CastArtMethod::entryPointFormInterpreter->set(originMethod, entryPointFormInterpreter);
// }
hookTrampoline->inlineSecondory->flushCache(reinterpret_cast<Size>(hookMethod), SandHook::CastArtMethod::size); hookTrampoline->inlineSecondory->flushCache(reinterpret_cast<Size>(hookMethod), SandHook::CastArtMethod::size);
if (hookTrampoline->callOrigin != nullptr) { if (hookTrampoline->callOrigin != nullptr) {
//backup //backup
...@@ -148,7 +181,9 @@ bool doHookWithInline(JNIEnv* env, ...@@ -148,7 +181,9 @@ bool doHookWithInline(JNIEnv* env,
if (SDK_INT >= ANDROID_O) { if (SDK_INT >= ANDROID_O) {
disableInterpreterForO(backupMethod); disableInterpreterForO(backupMethod);
} }
//setPrivate(backupMethod); tryDisableInline(backupMethod);
disableAccessCheck(backupMethod);
setPrivate(backupMethod);
hookTrampoline->callOrigin->flushCache(reinterpret_cast<Size>(backupMethod), SandHook::CastArtMethod::size); hookTrampoline->callOrigin->flushCache(reinterpret_cast<Size>(backupMethod), SandHook::CastArtMethod::size);
} }
return true; return true;
...@@ -187,6 +222,11 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or ...@@ -187,6 +222,11 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or
} }
if (SDK_INT >= ANDROID_P && BYTE_POINT == 4) { if (SDK_INT >= ANDROID_P && BYTE_POINT == 4) {
bool isInterpreter = SandHook::CastArtMethod::entryPointQuickCompiled->get(hook) == SandHook::CastArtMethod::quickToInterpreterBridge;
if (isInterpreter) {
Size threadId = getAddressFromJavaByCallMethod(env, "com/swift/sandhook/SandHook", "getThreadId");
compileMethod(hook, reinterpret_cast<void*>(threadId));
}
return static_cast<jboolean>(doHookWithReplacement(origin, hook, backup)); return static_cast<jboolean>(doHookWithReplacement(origin, hook, backup));
} else if (isAbsMethod(origin)) { } else if (isAbsMethod(origin)) {
return static_cast<jboolean>(doHookWithReplacement(origin, hook, backup)); return static_cast<jboolean>(doHookWithReplacement(origin, hook, backup));
......
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