Commit 76661ced authored by swift_gan's avatar swift_gan Committed by swift_gan

[Reconstitution]fix hook 32bit

parent a1112fb6
...@@ -17,7 +17,7 @@ android { ...@@ -17,7 +17,7 @@ android {
cmake { cmake {
arguments '-DBUILD_TESTING=OFF' arguments '-DBUILD_TESTING=OFF'
cppFlags "-frtti -fexceptions -Wpointer-arith" cppFlags "-frtti -fexceptions -Wpointer-arith"
abiFilters 'armeabi-v7a', 'arm64-v8a' abiFilters 'armeabi-v7a'
} }
} }
} }
......
...@@ -11,7 +11,7 @@ using namespace SandHook::AsmA32; ...@@ -11,7 +11,7 @@ using namespace SandHook::AsmA32;
#define CASE(T, X) \ #define CASE(T, X) \
if (IS_OPCODE_##T(*reinterpret_cast<Inst##T *>(pc), X)) { \ if (IS_OPCODE_##T(*reinterpret_cast<Inst##T *>(pc), X)) { \
unit = reinterpret_cast<Unit<Base> *>(new INST_##T(X)(pc)); \ unit = reinterpret_cast<BaseUnit*>(new INST_##T(X)(pc)); \
goto label_matched; \ goto label_matched; \
} }
...@@ -30,9 +30,9 @@ void Arm32Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visi ...@@ -30,9 +30,9 @@ void Arm32Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visi
} }
void *pc = codeStart; void *pc = codeStart;
Addr endAddr = (Addr) codeStart + codeLen; Addr endAddr = (Addr) codeStart + codeLen;
Unit<Base>* unit = nullptr; BaseUnit *unit = nullptr;
while((Addr) pc < endAddr) { while((Addr) pc < endAddr) {
bool thumb32 = IsThumb32(*reinterpret_cast<InstT16 *>(pc)); bool thumb32 = IsThumb32(*reinterpret_cast<InstT16*>(pc));
if (thumb && thumb32) { if (thumb && thumb32) {
CASE_T32(SUB_IMM) CASE_T32(SUB_IMM)
CASE_T32(B32) CASE_T32(B32)
...@@ -43,7 +43,7 @@ void Arm32Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visi ...@@ -43,7 +43,7 @@ void Arm32Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visi
CASE_T32(MOV_MOVT_IMM) CASE_T32(MOV_MOVT_IMM)
} }
if (unit == nullptr) { if (unit == nullptr) {
unit = reinterpret_cast<Unit<Base> *>(new INST_T32(UNKNOW)(pc)); unit = reinterpret_cast<BaseUnit*>(new INST_T32(UNKNOW)(pc));
} }
} else if (thumb) { } else if (thumb) {
CASE_T16(B) CASE_T16(B)
...@@ -63,18 +63,19 @@ void Arm32Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visi ...@@ -63,18 +63,19 @@ void Arm32Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visi
CASE_T16(PUSH) CASE_T16(PUSH)
} }
if (unit == nullptr) { if (unit == nullptr) {
unit = reinterpret_cast<Unit<Base> *>(new INST_T16(UNKNOW)(pc)); unit = reinterpret_cast<BaseUnit*>(new INST_T16(UNKNOW)(pc));
} }
} else { } else {
//TODO arm32 support //TODO arm32 support
unit = reinterpret_cast<Unit<Base> *>(new INST_T32(UNKNOW)(pc)); unit = reinterpret_cast<BaseUnit*>(new INST_T32(UNKNOW)(pc));
} }
label_matched: label_matched:
reinterpret_cast<BaseInst*>(unit)->Disassemble();
if (!visitor.Visit(unit, pc)) { if (!visitor.Visit(unit, pc)) {
break; break;
} }
pc = reinterpret_cast<InstA64 *>((Addr)pc + unit->Size()); pc = reinterpret_cast<void*>((Addr)pc + unit->Size());
unit = nullptr; unit = nullptr;
} }
} }
......
...@@ -60,8 +60,7 @@ void *InlineHookArm32Android::Hook(void *origin, void *replace) { ...@@ -60,8 +60,7 @@ void *InlineHookArm32Android::Hook(void *origin, void *replace) {
ALIGN_FOR_LDR ALIGN_FOR_LDR
__ Ldr(PC, origin_addr_label); __ Ldr(PC, origin_addr_label);
__ Emit(origin_addr_label); __ Emit(origin_addr_label);
__ Emit((Addr) GetThumbPC( __ Emit((Addr) GetThumbPC(reinterpret_cast<void *>(reinterpret_cast<Addr>(origin_code) + relocate.cur_offset)));
reinterpret_cast<void *>(reinterpret_cast<Addr>(origin_code) + relocate.cur_offset)));
__ Finish(); __ Finish();
#undef __ #undef __
......
...@@ -17,7 +17,7 @@ using namespace SandHook::RegistersA32; ...@@ -17,7 +17,7 @@ using namespace SandHook::RegistersA32;
//Unknow //Unknow
T16_UNKNOW::T16_UNKNOW(void *inst) : InstructionT16(&inst) { T16_UNKNOW::T16_UNKNOW(void *inst) : InstructionT16(inst) {
} }
//B //B
......
...@@ -20,7 +20,7 @@ void Arm64Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visi ...@@ -20,7 +20,7 @@ void Arm64Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visi
bool onlyPcRelInst) { bool onlyPcRelInst) {
InstA64 *pc = reinterpret_cast<InstA64 *>(codeStart); InstA64 *pc = reinterpret_cast<InstA64 *>(codeStart);
Addr end_addr = (Addr) codeStart + codeLen; Addr end_addr = (Addr) codeStart + codeLen;
Unit<Base>* unit = nullptr; BaseUnit* unit = nullptr;
while((Addr) pc < end_addr) { while((Addr) pc < end_addr) {
// pc relate insts // pc relate insts
CASE(B_BL) CASE(B_BL)
......
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