Commit c2bf39ef authored by swift_gan's avatar swift_gan

done arm32 compat

parent bd2a9f9a
...@@ -77,6 +77,9 @@ bool doHookWithReplacement(art::mirror::ArtMethod *originMethod, ...@@ -77,6 +77,9 @@ bool doHookWithReplacement(art::mirror::ArtMethod *originMethod,
SandHook::CastArtMethod::entryPointFormInterpreter->set(originMethod, entryPointFormInterpreter); SandHook::CastArtMethod::entryPointFormInterpreter->set(originMethod, entryPointFormInterpreter);
} }
hookTrampoline->replacement->flushCache(reinterpret_cast<Size>(originMethod), SandHook::CastArtMethod::size); hookTrampoline->replacement->flushCache(reinterpret_cast<Size>(originMethod), SandHook::CastArtMethod::size);
return true;
} else {
return false;
} }
} }
...@@ -94,19 +97,33 @@ bool doHookWithInline(JNIEnv* env, ...@@ -94,19 +97,33 @@ bool doHookWithInline(JNIEnv* env,
} }
SandHook::HookTrampoline* hookTrampoline = trampolineManager.installInlineTrampoline(originMethod, hookMethod, backupMethod); SandHook::HookTrampoline* hookTrampoline = trampolineManager.installInlineTrampoline(originMethod, hookMethod, backupMethod);
if (hookTrampoline == nullptr)
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
memcpy(backupMethod, originMethod, SandHook::CastArtMethod::size); memcpy(backupMethod, originMethod, SandHook::CastArtMethod::size);
SandHook::CastArtMethod::entryPointQuickCompiled->set(backupMethod, hookTrampoline->callOrigin->getCode());
Code callOriginCode = hookTrampoline->callOrigin->getCode();
if (hookTrampoline->callOrigin->isThumCode()) {
callOriginCode = hookTrampoline->callOrigin->getThumbCodePcAddress(callOriginCode);
}
SandHook::CastArtMethod::entryPointQuickCompiled->set(backupMethod, callOriginCode);
if (SDK_INT >= ANDROID_N) { if (SDK_INT >= ANDROID_N) {
disableCompilable(backupMethod); disableCompilable(backupMethod);
} }
if (SDK_INT >= ANDROID_O) { if (SDK_INT >= ANDROID_O) {
disableInterpreterForO(backupMethod); disableInterpreterForO(backupMethod);
} }
hookTrampoline->callOrigin->flushCache(reinterpret_cast<Size>(backupMethod), SandHook::CastArtMethod::size); hookTrampoline->callOrigin->flushCache(reinterpret_cast<Size>(backupMethod), SandHook::CastArtMethod::size);
} }
return true;
} }
extern "C" extern "C"
...@@ -134,19 +151,17 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or ...@@ -134,19 +151,17 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or
if (SDK_INT >= ANDROID_N) { if (SDK_INT >= ANDROID_N) {
Size threadId = getAddressFromJavaByCallMethod(env, "com/swift/sandhook/SandHook", "getThreadId"); Size threadId = getAddressFromJavaByCallMethod(env, "com/swift/sandhook/SandHook", "getThreadId");
if (compileMethod(origin, reinterpret_cast<void *>(threadId)) && SandHook::CastArtMethod::entryPointQuickCompiled->get(origin) != SandHook::CastArtMethod::quickToInterpreterBridge) { if (compileMethod(origin, reinterpret_cast<void *>(threadId)) && SandHook::CastArtMethod::entryPointQuickCompiled->get(origin) != SandHook::CastArtMethod::quickToInterpreterBridge) {
doHookWithInline(env, origin, hook, backup); return static_cast<jboolean>(doHookWithInline(env, origin, hook, backup));
} else { } else {
doHookWithReplacement(origin, hook, backup); return static_cast<jboolean>(doHookWithReplacement(origin, hook, backup));
} }
} else { } else {
doHookWithReplacement(origin, hook, backup); return static_cast<jboolean>(doHookWithReplacement(origin, hook, backup));
} }
} else { } else {
doHookWithInline(env, origin, hook, backup); return static_cast<jboolean>(doHookWithInline(env, origin, hook, backup));
} }
return JNI_TRUE;
} }
extern "C" extern "C"
......
...@@ -96,11 +96,11 @@ origin_code_t: ...@@ -96,11 +96,11 @@ origin_code_t:
//4 byte //4 byte
ldr RegT, addr_origin_art_method_t ldr RegT, addr_origin_art_method_t
//4 byte //4 byte
add RegT, RegT, #8 add RegT, RegT, #36
//4 byte //4 byte
ldr RegT, [RegT] ldr RegT, [RegT]
//4 byte //4 byte
add RegT, RegT, SIZE_JUMP add RegT, RegT, #8
//2 byte //2 byte
mov pc, RegT mov pc, RegT
nop nop
......
...@@ -73,7 +73,7 @@ namespace SandHook { ...@@ -73,7 +73,7 @@ namespace SandHook {
#if defined(__arm__) #if defined(__arm__)
Code32Bit offset32; Code32Bit offset32;
offset32.code = offSet; offset32.code = offSet;
unsigned char offsetOP = isBigEnd() ? offset32.op.op4 : offset32.op.op1; unsigned char offsetOP = isBigEnd() ? offset32.op.op2 : offset32.op.op1;
tweakOpImm(OFFSET_INLINE_OP_OFFSET_CODE, offsetOP); tweakOpImm(OFFSET_INLINE_OP_OFFSET_CODE, offsetOP);
#endif #endif
} }
......
...@@ -172,7 +172,7 @@ namespace SandHook { ...@@ -172,7 +172,7 @@ namespace SandHook {
if (isBigEnd()) { if (isBigEnd()) {
code32Bit.op.op4 = imm; code32Bit.op.op4 = imm;
} else { } else {
code32Bit.op.op1 = imm; code32Bit.op.op3 = imm;
} }
codeCopy(reinterpret_cast<Code>(&code32Bit.code), codeOffset, 4); codeCopy(reinterpret_cast<Code>(&code32Bit.code), codeOffset, 4);
} }
......
...@@ -120,8 +120,14 @@ namespace SandHook { ...@@ -120,8 +120,14 @@ namespace SandHook {
if (callOriginTrampolineSpace == 0) if (callOriginTrampolineSpace == 0)
goto label_error; goto label_error;
callOriginTrampoline->setExecuteSpace(callOriginTrampolineSpace); callOriginTrampoline->setExecuteSpace(callOriginTrampolineSpace);
callOriginTrampoline->setOriginMethod(reinterpret_cast<unsigned char *>(originMethod)); callOriginTrampoline->setOriginMethod(reinterpret_cast<Code>(originMethod));
callOriginTrampoline->setOriginCode(inlineHookTrampoline->getCallOriginCode()); Code originCode = nullptr;
if (callOriginTrampoline->isThumCode()) {
originCode = callOriginTrampoline->getThumbCodePcAddress(inlineHookTrampoline->getCallOriginCode());
} else {
originCode = inlineHookTrampoline->getCallOriginCode();
}
callOriginTrampoline->setOriginCode(originCode);
hookTrampoline->callOrigin = callOriginTrampoline; hookTrampoline->callOrigin = callOriginTrampoline;
} }
......
...@@ -16,7 +16,7 @@ public class ActivityHooker { ...@@ -16,7 +16,7 @@ public class ActivityHooker {
@MethodParams(Bundle.class) @MethodParams(Bundle.class)
public static void onCreate(Activity thiz, Bundle bundle) { public static void onCreate(Activity thiz, Bundle bundle) {
Log.e("ActivityHooker", "hooked success " + thiz); Log.e("ActivityHooker", "hooked success " + thiz);
//onCreateBackup(thiz, bundle); onCreateBackup(thiz, bundle);
} }
@HookMethodBackup("onCreate") @HookMethodBackup("onCreate")
......
...@@ -9,7 +9,7 @@ public class MyApp extends Application { ...@@ -9,7 +9,7 @@ public class MyApp extends Application {
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
try { try {
SandHook.addHookClass(ActivityHooker.class); SandHook.addHookClass(LogHooker.class, ActivityHooker.class, ObjectHooker.class);
} catch (HookErrorException e) { } catch (HookErrorException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
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