Commit f6c7aa65 authored by swift_gan's avatar swift_gan Committed by swift_gan

[NativeHook]fix adrp decode & update test case

parent e85c7f8d
......@@ -71,16 +71,17 @@ A64_ADR_ADRP::A64_ADR_ADRP(A64_ADR_ADRP::OP op, XRegister &rd, Label &label) {
Off A64_ADR_ADRP::getImmPCOffset() {
U32 hi = get()->immhi;
U32 lo = get()->immlo;
Off offset = signExtend64(IMM_LO_W + IMM_HI_W, COMBINE(hi, lo, IMM_LO_W));
U64 imm = COMBINE(hi, lo, IMM_LO_W);
if (isADRP()) {
offset *= P_SIZE;
return signExtend64(IMM_HI_W + IMM_LO_W + PAGE_OFFSET, imm << PAGE_OFFSET);
} else {
return signExtend64(IMM_HI_W + IMM_LO_W, imm);
}
return offset;
}
Addr A64_ADR_ADRP::getImmPCOffsetTarget() {
void* base = AlignDown(getPC(), P_SIZE);
return getImmPCOffset() + reinterpret_cast<Addr>(base);
return offset + reinterpret_cast<Addr>(base);
}
void A64_ADR_ADRP::assembler() {
......@@ -90,7 +91,7 @@ void A64_ADR_ADRP::assembler() {
void A64_ADR_ADRP::decode(STRUCT_A64(ADR_ADRP) *inst) {
offset = getImmPCOffset();
DECODE_RD(XReg);
op = OP(get()->op);
DECODE_OP;
}
//Mov Wide
......
......@@ -15,6 +15,12 @@ using namespace SandHook::Decoder;
using namespace SandHook::Hook;
using namespace SandHook::AsmA64;
int m1 = 5;
int m3 = 5;
int m2 = 4;
int m4 = 5;
void (*dosth3Backup)(int, int) = nullptr;
void (*dosth4Backup)() = nullptr;
void (*dosth4Backup2)() = nullptr;
......@@ -51,6 +57,9 @@ void do5() {
}
void do4() {
if (m2 > m3) {
return;
}
int a = 1 + 1;
int b = a + 1;
int d = a + 1;
......@@ -134,8 +143,6 @@ Java_com_swift_sandhook_nativehook_NativeHook_test(JNIEnv *env, jclass jclass1)
InlineHookArm64Android inlineHookArm64Android = InlineHookArm64Android();
do4();
dosth4Backup = reinterpret_cast<void (*)()>(inlineHookArm64Android.inlineHook(
reinterpret_cast<void *>(do4),
reinterpret_cast<void *>(do4replace)));
......
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