Commit 0ac2a058 authored by swift_gan's avatar swift_gan Committed by swift_gan

fix MOV_WIDE

parent 01661bfa
......@@ -58,7 +58,6 @@ A64_ADR_ADRP::A64_ADR_ADRP(STRUCT_A64(ADR_ADRP) &inst) : A64_INST_PC_REL(&inst)
A64_ADR_ADRP::A64_ADR_ADRP(A64_ADR_ADRP::OP op, XRegister &rd, S64 offset) : op(op), rd(&rd),
offset(offset) {
assembler();
}
A64_ADR_ADRP::A64_ADR_ADRP(A64_ADR_ADRP::OP op, XRegister &rd, Label &label) {
......@@ -99,9 +98,7 @@ A64_MOV_WIDE::A64_MOV_WIDE(STRUCT_A64(MOV_WIDE) &inst) : InstructionA64(&inst) {
}
A64_MOV_WIDE::A64_MOV_WIDE(A64_MOV_WIDE::OP op,RegisterA64* rd, U16 imme, U8 shift)
: shift(shift), op(op), imme(imme), rd(rd) {
assembler();
}
: shift(shift), op(op), imme(imme), rd(rd) {}
void A64_MOV_WIDE::assembler() {
SET_OPCODE(MOV_WIDE);
......
......@@ -256,11 +256,11 @@ namespace SandHook {
enum OP {
// Move and keep.
MOV_WideOp_K = 0b00,
MOV_WideOp_K = 0b11,
// Move with zero.
MOV_WideOp_Z = 0b10,
// Move with non-zero.
MOV_WideOp_N = 0b11,
MOV_WideOp_N = 0b00,
};
enum Shift {
......
......@@ -52,7 +52,7 @@ void* CodeRelocateA64::relocate(Instruction<Base> *instruction, void *toPc) thro
IMPL_RELOCATE(B_BL) {
Addr targetAddr = inst->getImmPCOffsetTarget();
if (inst->op == inst->BL) {
__ Mov(LR, targetAddr + inst->size());
__ Mov(LR, (Addr)inst->getPC() + inst->size());
}
__ Mov(IP1, targetAddr);
__ Br(IP1);
......
......@@ -188,20 +188,20 @@ inline int32_t ExtractSignedBitfield32(int msb, int lsb, U32 x) {
}
inline int16_t BITS16L(int32_t value) {
return static_cast<int16_t>(value);
inline U16 BITS16L(U32 value) {
return static_cast<U16>(value & 0xffff);
}
inline int16_t BITS16H(int32_t value) {
return static_cast<int16_t>(value >> 16);
inline U16 BITS16H(U32 value) {
return static_cast<U16>(value >> 16);
}
inline int32_t BITS32L(int64_t value) {
return static_cast<int32_t>(value);
inline U32 BITS32L(U64 value) {
return static_cast<U32>(value);
}
inline int32_t BITS32H(int64_t value) {
return static_cast<int32_t>(value >> 32);
inline U32 BITS32H(U64 value) {
return static_cast<U32>(value >> 32);
}
#define COMBINE(hi, lo, lowide) (hi << lowide) | lo
......
......@@ -14,7 +14,9 @@ using namespace SandHook::Asm;
using namespace SandHook::Decoder;
using namespace SandHook::Hook;
void (*dosth3Backup)(int) = nullptr;
void (*dosth3Backup)(int, int) = nullptr;
void (*dosth4Backup)() = nullptr;
bool memUnprotect(Addr addr, Addr len) {
long pagesize = 4096;
......@@ -34,10 +36,8 @@ void do2() {
int d = 1 + 1;
}
void do3(int x) {
if (x > 0) {
return;
}
void do3(int x, int y) {
do2();
int a = 1 + 1;
int b = 1 + 1;
int c = 1 + 1;
......@@ -45,12 +45,30 @@ void do3(int x) {
LOGE("x = %d", x);
}
void do3replace(int x) {
void do5() {
LOGE("x = %d", 5);
}
void do4() {
do5();
LOGE("x = %d", 6);
LOGE("x = %d", 7);
}
void do4replace() {
int a = 1 + 1;
int b = 1 + 1;
int c = 1 + 1;
int d = 1 + 1;
dosth3Backup(x);
dosth4Backup();
}
void do3replace(int x, int y) {
int a = 1 + 1;
int b = 1 + 1;
int c = 1 + 1;
int d = 1 + 1;
dosth3Backup(x, y);
}
void do1() {
......@@ -105,10 +123,12 @@ Java_com_swift_sandhook_nativehook_NativeHook_test(JNIEnv *env, jclass jclass1)
InlineHookArm64Android inlineHookArm64Android = InlineHookArm64Android();
dosth3Backup = reinterpret_cast<void (*)(int)>(inlineHookArm64Android.inlineHook(
reinterpret_cast<void *>(do3),
reinterpret_cast<void *>(do3replace)));
do4();
dosth4Backup = reinterpret_cast<void (*)()>(inlineHookArm64Android.inlineHook(
reinterpret_cast<void *>(do4),
reinterpret_cast<void *>(do4replace)));
do3(3);
do4();
}
\ No newline at end of file
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