Commit b8775fba authored by swift_gan's avatar swift_gan

fix thumb code offset

parent 6ad5dca1
......@@ -115,11 +115,7 @@ bool doHookWithInline(JNIEnv* env,
//backup
memcpy(backupMethod, originMethod, SandHook::CastArtMethod::size);
Code callOriginCode = hookTrampoline->callOrigin->getCode();
if (hookTrampoline->callOrigin->isThumbCode()) {
callOriginCode = hookTrampoline->callOrigin->getThumbCodePcAddress(callOriginCode);
}
SandHook::CastArtMethod::entryPointQuickCompiled->set(backupMethod, callOriginCode);
SandHook::CastArtMethod::entryPointQuickCompiled->set(backupMethod, hookTrampoline->callOrigin->getCode());
if (SDK_INT >= ANDROID_N) {
disableCompilable(backupMethod);
......
......@@ -106,6 +106,7 @@ namespace SandHook {
class Trampoline {
public:
Code code;
Trampoline() = default;
......@@ -152,7 +153,11 @@ namespace SandHook {
}
Code getCode() {
return code;
if (isThumbCode()) {
return getThumbCodePcAddress(code);
} else {
return code;
}
}
Size getCodeLen() {
......@@ -169,7 +174,7 @@ namespace SandHook {
//tweak imm of a 32bit asm code
void tweakOpImm(Size codeOffset, unsigned char imm) {
Code32Bit code32Bit;
code32Bit.code = *reinterpret_cast<uint32_t*>(((Size)getCode() + codeOffset));
code32Bit.code = *reinterpret_cast<uint32_t*>(((Size)code + codeOffset));
if (isBigEnd()) {
code32Bit.op.op4 = imm;
} else {
......@@ -193,7 +198,6 @@ namespace SandHook {
virtual Size codeLength() = 0;
virtual Code templateCode() = 0;
private:
Code code;
Code tempCode;
Size codeLen;
bool isThumb = false;
......
......@@ -91,7 +91,11 @@ namespace SandHook {
inlineHookTrampoline->setOriginMethod(reinterpret_cast<Code>(originMethod));
inlineHookTrampoline->setHookMethod(reinterpret_cast<Code>(hookMethod));
inlineHookTrampoline->setEntryCodeOffset(quickCompileOffset);
inlineHookTrampoline->setOriginCode(getEntryCode(originMethod));
if (inlineHookTrampoline->isThumbCode()) {
inlineHookTrampoline->setOriginCode(inlineHookTrampoline->getThumbCodeAddress(getEntryCode(originMethod)));
} else {
inlineHookTrampoline->setOriginCode(getEntryCode(originMethod));
}
hookTrampoline->inlineSecondory = inlineHookTrampoline;
//注入 EntryCode
......@@ -105,12 +109,10 @@ namespace SandHook {
if (directJumpTrampoline->isThumbCode()) {
originEntry = directJumpTrampoline->getThumbCodeAddress(originEntry);
directJumpTrampoline->setExecuteSpace(originEntry);
directJumpTrampoline->setJumpTarget(directJumpTrampoline->getThumbCodePcAddress(inlineHookTrampoline->getCode()));
} else {
directJumpTrampoline->setExecuteSpace(originEntry);
directJumpTrampoline->setJumpTarget(inlineHookTrampoline->getCode());
}
directJumpTrampoline->setExecuteSpace(originEntry);
directJumpTrampoline->setJumpTarget(inlineHookTrampoline->getCode());
hookTrampoline->inlineJump = directJumpTrampoline;
//备份原始方法
......
......@@ -74,10 +74,15 @@ public class MainActivity extends AppCompatActivity {
return true;
}
@Override
protected void onPause() {
super.onPause();
}
public static int methodBeHooked(int a, int b) {
a = a + 1 + 2;
b = b + a + 3;
//Toast.makeText(MyApp.context, "call origin!", Toast.LENGTH_SHORT).show();
Log.e("MainActivity", "call methodBeHooked origin");
return a + b;
}
......
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