Commit 12e606a5 authored by swift_gan's avatar swift_gan Committed by swift_gan

add inst str unsign imm

parent 0283ee7b
...@@ -310,6 +310,10 @@ A64_STR_IMM::A64_STR_IMM(STRUCT_A64(STR_IMM) &inst) : InstructionA64(&inst) { ...@@ -310,6 +310,10 @@ A64_STR_IMM::A64_STR_IMM(STRUCT_A64(STR_IMM) &inst) : InstructionA64(&inst) {
decode(&inst); decode(&inst);
} }
A64_STR_IMM::A64_STR_IMM(RegisterA64 &rt, const MemOperand &operand) : rt(&rt), operand(operand) {
}
void A64_STR_IMM::decode(STRUCT_A64(STR_IMM) *inst) { void A64_STR_IMM::decode(STRUCT_A64(STR_IMM) *inst) {
regSize = Size(inst->size); regSize = Size(inst->size);
switch (regSize) { switch (regSize) {
...@@ -376,6 +380,48 @@ void A64_STR_IMM::assembler() { ...@@ -376,6 +380,48 @@ void A64_STR_IMM::assembler() {
} }
} }
A64_STR_IMM::A64_STR_IMM(RegisterA64 &rt, const MemOperand &operand) : rt(&rt), operand(operand) { A64_STR_UIMM::A64_STR_UIMM() {}
A64_STR_UIMM::A64_STR_UIMM(STRUCT_A64(STR_UIMM) &inst) : InstructionA64(&inst) {
decode(&inst);
} }
A64_STR_UIMM::A64_STR_UIMM(RegisterA64 &rt, const MemOperand &operand) : rt(&rt), operand(operand) {
}
void A64_STR_UIMM::decode(STRUCT_A64(STR_UIMM) *inst) {
regSize = Size(inst->size);
switch (regSize) {
case Size64:
rt = XReg(static_cast<U8>(inst->rt));
operand.base = XReg(static_cast<U8>(inst->rn));
break;
case Size32:
rt = WReg(static_cast<U8>(inst->rt));
operand.base = WReg(static_cast<U8>(inst->rn));
break;
default:
valid = false;
return;
}
operand.addr_mode = AddrMode::Offset;
scale = static_cast<U8>(inst->size);
offset = inst->imm12 << regSize;
operand.offset = offset;
}
void A64_STR_UIMM::assembler() {
SET_OPCODE(STR_IMM);
get()->rt = rt->getCode();
get()->rn = operand.base->getCode();
if (rt->isX()) {
get()->size = Size64;
} else if (rt->isW()) {
get()->size = Size32;
} else {
valid = false;
return;
}
get()->imm12 = operand.offset >> get()->size;
}
\ No newline at end of file
...@@ -543,6 +543,38 @@ namespace SandHook { ...@@ -543,6 +543,38 @@ namespace SandHook {
Off offset; Off offset;
}; };
class INST_A64(STR_UIMM) : public InstructionA64<STRUCT_A64(STR_UIMM)> {
public:
enum Size {
Size32 = 0b10,
Size64 = 0b11
};
A64_STR_UIMM();
A64_STR_UIMM(STRUCT_A64(STR_UIMM)& inst);
A64_STR_UIMM(RegisterA64 &rt, const MemOperand &operand);
DEFINE_IS(STR_UIMM)
void decode(STRUCT_A64(STR_UIMM) *inst) override;
void assembler() override;
public:
RegisterA64* rt;
MemOperand operand = MemOperand();
private:
Size regSize;
U8 scale;
bool wback = false;
bool postindex = false;
Off offset;
};
} }
} }
......
...@@ -177,5 +177,14 @@ DEFINE_STRUCT_A64(STR_IMM) { ...@@ -177,5 +177,14 @@ DEFINE_STRUCT_A64(STR_IMM) {
InstA64 size:2; InstA64 size:2;
}; };
DEFINE_OPCODE(STR_UIMM, 0b11100100)
DEFINE_STRUCT_A64(STR_UIMM) {
InstA64 rt:5;
InstA64 rn:5;
InstA64 imm12:12;
InstA64 opcode:8;
InstA64 size:2;
};
#endif //SANDHOOK_NH_INST_AARCH64_H #endif //SANDHOOK_NH_INST_AARCH64_H
...@@ -31,8 +31,8 @@ JNIEXPORT void JNICALL ...@@ -31,8 +31,8 @@ JNIEXPORT void JNICALL
Java_com_swift_sandhook_nativehook_NativeHook_test(JNIEnv *env, jclass jclass1) { Java_com_swift_sandhook_nativehook_NativeHook_test(JNIEnv *env, jclass jclass1) {
union { union {
InstA64 raw = 0xF8020C43; InstA64 raw = 0xF9001043;
STRUCT_A64(STR_IMM) str; STRUCT_A64(STR_UIMM) str;
} test; } test;
InstA64* codebl = reinterpret_cast<InstA64 *>((Addr)do1 + 8); InstA64* codebl = reinterpret_cast<InstA64 *>((Addr)do1 + 8);
...@@ -54,8 +54,9 @@ Java_com_swift_sandhook_nativehook_NativeHook_test(JNIEnv *env, jclass jclass1) ...@@ -54,8 +54,9 @@ Java_com_swift_sandhook_nativehook_NativeHook_test(JNIEnv *env, jclass jclass1)
} }
if (IS_OPCODE(test.raw, STR_IMM)) { if (IS_OPCODE(test.raw, STR_UIMM)) {
A64_STR_IMM str(test.str); A64_STR_UIMM str(test.str);
str.assembler();
str.get(); str.get();
} }
......
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