Commit 1ca0a145 authored by swift_gan's avatar swift_gan Committed by swift_gan

[NativeHook]fix LR store

parent 7012c124
...@@ -34,6 +34,10 @@ void AssemblerA32::Emit(U32 data32) { ...@@ -34,6 +34,10 @@ void AssemblerA32::Emit(U32 data32) {
Emit(reinterpret_cast<Unit<Base>*>(new Data32(data32))); Emit(reinterpret_cast<Unit<Base>*>(new Data32(data32)));
} }
void AssemblerA32::Emit(U16 data16) {
Emit(reinterpret_cast<Unit<Base>*>(new Data16(data16)));
}
void AssemblerA32::Emit(Unit<Base> *unit) { void AssemblerA32::Emit(Unit<Base> *unit) {
codeContainer.append(unit); codeContainer.append(unit);
} }
......
...@@ -25,6 +25,7 @@ namespace SandHook { ...@@ -25,6 +25,7 @@ namespace SandHook {
void* finish(); void* finish();
void Emit(U32 data32); void Emit(U32 data32);
void Emit(U16 data16);
void Emit(Unit<Base>* unit); void Emit(Unit<Base>* unit);
......
...@@ -213,7 +213,12 @@ IMPL_RELOCATE(T32, B32) { ...@@ -213,7 +213,12 @@ IMPL_RELOCATE(T32, B32) {
if (inst->x == T32_B32::thumb) { if (inst->x == T32_B32::thumb) {
//Thumb mode //Thumb mode
if (inst->op == T32_B32::BL) { if (inst->op == T32_B32::BL) {
__ Mov(LR, U32((Addr) toPc + inst->size() + 2 * 2)); Addr lr = reinterpret_cast<Addr>(toPc);
lr += 2 * 2; // 2级流水线
lr += 2 * 4; // Mov + Movt 长度
lr += 4; // Ldr Lit 长度
lr += 4; // targetAddr 长度
__ Mov(LR, lr);
} }
targetAddr = reinterpret_cast<Addr>(getThumbPC(reinterpret_cast<void *>(targetAddr))); targetAddr = reinterpret_cast<Addr>(getThumbPC(reinterpret_cast<void *>(targetAddr)));
Label* target_label = new Label(); Label* target_label = new Label();
......
...@@ -85,7 +85,11 @@ IMPL_RELOCATE(B_BL) { ...@@ -85,7 +85,11 @@ IMPL_RELOCATE(B_BL) {
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->getImmPCOffsetTarget();
if (inst->op == inst->BL) { if (inst->op == inst->BL) {
__ Mov(LR, (Addr)inst->getPC() + inst->size()); Addr lr = reinterpret_cast<Addr>(toPc);
lr += 4 * 4; // MovWide * 4;
lr += 4 * 4; // MovWide * 4;
lr += 4; // Br
__ Mov(LR, lr);
} }
__ Mov(IP1, targetAddr); __ Mov(IP1, targetAddr);
__ Br(IP1); __ Br(IP1);
......
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