Commit d714cd48 authored by swift_gan's avatar swift_gan

fix some bugs

parent 4e3ca8e8
...@@ -31,6 +31,9 @@ void Arm64Decoder::Disassemble(void *codeStart, Addr codeLen, InstVisitor &visit ...@@ -31,6 +31,9 @@ void Arm64Decoder::Disassemble(void *codeStart, Addr codeLen, InstVisitor &visit
CASE(ADR_ADRP) CASE(ADR_ADRP)
if (onlyPcRelInst) if (onlyPcRelInst)
goto label_matched; goto label_matched;
CASE(BR_BLR_RET)
CASE(EXCEPTION_GEN)
CASE(MSR_MRS)
CASE(MOV_WIDE) CASE(MOV_WIDE)
CASE(MOV_REG) CASE(MOV_REG)
CASE(LDR_IMM) CASE(LDR_IMM)
...@@ -39,10 +42,7 @@ void Arm64Decoder::Disassemble(void *codeStart, Addr codeLen, InstVisitor &visit ...@@ -39,10 +42,7 @@ void Arm64Decoder::Disassemble(void *codeStart, Addr codeLen, InstVisitor &visit
CASE(LDRSW_UIMM) CASE(LDRSW_UIMM)
CASE(STR_UIMM) CASE(STR_UIMM)
CASE(STR_IMM) CASE(STR_IMM)
CASE(BR_BLR_RET)
CASE(SUB_EXT_REG) CASE(SUB_EXT_REG)
CASE(SVC)
CASE(EXCEPTION_GEN)
CASE(STP_LDP) CASE(STP_LDP)
CASE(ADD_SUB_IMM) CASE(ADD_SUB_IMM)
......
...@@ -141,11 +141,11 @@ void A64_B_BL::Assemble() { ...@@ -141,11 +141,11 @@ void A64_B_BL::Assemble() {
A64_CBZ_CBNZ::A64_CBZ_CBNZ(void *inst) : A64_INST_PC_REL(inst) {} A64_CBZ_CBNZ::A64_CBZ_CBNZ(void *inst) : A64_INST_PC_REL(inst) {}
A64_CBZ_CBNZ::A64_CBZ_CBNZ(A64_CBZ_CBNZ::OP op, Off offset, RegisterA64 &rt) : op(op), A64_CBZ_CBNZ::A64_CBZ_CBNZ(A64_CBZ_CBNZ::OP op, Off offset, RegisterA64 &rt) : op(op),
offset(offset), offset(offset),
rt(&rt) {} rt(&rt) {}
A64_CBZ_CBNZ::A64_CBZ_CBNZ(A64_CBZ_CBNZ::OP op, Label *label, RegisterA64 &rt) : op(op), A64_CBZ_CBNZ::A64_CBZ_CBNZ(A64_CBZ_CBNZ::OP op, Label *label, RegisterA64 &rt) : op(op),
rt(&rt) { rt(&rt) {
BindLabel(label); BindLabel(label);
} }
...@@ -216,13 +216,13 @@ void A64_B_COND::OnOffsetApply(Off offset) { ...@@ -216,13 +216,13 @@ void A64_B_COND::OnOffsetApply(Off offset) {
A64_TBZ_TBNZ::A64_TBZ_TBNZ(void *inst) : A64_INST_PC_REL(inst) {} A64_TBZ_TBNZ::A64_TBZ_TBNZ(void *inst) : A64_INST_PC_REL(inst) {}
A64_TBZ_TBNZ::A64_TBZ_TBNZ(A64_TBZ_TBNZ::OP op, RegisterA64 &rt, U32 bit, Off offset) : op(op), A64_TBZ_TBNZ::A64_TBZ_TBNZ(A64_TBZ_TBNZ::OP op, RegisterA64 &rt, U32 bit, Off offset) : op(op),
rt(&rt), rt(&rt),
bit(bit), bit(bit),
offset(offset) {} offset(offset) {}
A64_TBZ_TBNZ::A64_TBZ_TBNZ(A64_TBZ_TBNZ::OP op, RegisterA64 &rt, U32 bit, Label *label) : op(op), A64_TBZ_TBNZ::A64_TBZ_TBNZ(A64_TBZ_TBNZ::OP op, RegisterA64 &rt, U32 bit, Label *label) : op(op),
rt(&rt), rt(&rt),
bit(bit) { bit(bit) {
BindLabel(label); BindLabel(label);
} }
...@@ -262,7 +262,7 @@ void A64_TBZ_TBNZ::OnOffsetApply(Off offset) { ...@@ -262,7 +262,7 @@ void A64_TBZ_TBNZ::OnOffsetApply(Off offset) {
A64_LDR_LIT::A64_LDR_LIT(void *inst) : A64_INST_PC_REL(inst) {} A64_LDR_LIT::A64_LDR_LIT(void *inst) : A64_INST_PC_REL(inst) {}
A64_LDR_LIT::A64_LDR_LIT(A64_LDR_LIT::OP op, RegisterA64 &rt, Off offset) : op(op), rt(&rt), A64_LDR_LIT::A64_LDR_LIT(A64_LDR_LIT::OP op, RegisterA64 &rt, Off offset) : op(op), rt(&rt),
offset(offset) {} offset(offset) {}
A64_LDR_LIT::A64_LDR_LIT(A64_LDR_LIT::OP op, RegisterA64 &rt, Label *label) : op(op), rt(&rt) { A64_LDR_LIT::A64_LDR_LIT(A64_LDR_LIT::OP op, RegisterA64 &rt, Label *label) : op(op), rt(&rt) {
BindLabel(label); BindLabel(label);
...@@ -459,8 +459,8 @@ void A64_MOV_REG::Assemble() { ...@@ -459,8 +459,8 @@ void A64_MOV_REG::Assemble() {
A64_SUB_EXT_REG::A64_SUB_EXT_REG(void *inst) : InstructionA64(inst) {} A64_SUB_EXT_REG::A64_SUB_EXT_REG(void *inst) : InstructionA64(inst) {}
A64_SUB_EXT_REG::A64_SUB_EXT_REG(RegisterA64 &rd, RegisterA64 &rn, const Operand &operand, A64_SUB_EXT_REG::A64_SUB_EXT_REG(RegisterA64 &rd, RegisterA64 &rn, const Operand &operand,
FlagsUpdate flagsUpdate) : rd(&rd), rn(&rn), operand(operand), FlagsUpdate flagsUpdate) : rd(&rd), rn(&rn), operand(operand),
flagsUpdate(flagsUpdate) {} flagsUpdate(flagsUpdate) {}
void A64_SUB_EXT_REG::Disassemble() { void A64_SUB_EXT_REG::Disassemble() {
flagsUpdate = FlagsUpdate(Get()->S); flagsUpdate = FlagsUpdate(Get()->S);
...@@ -598,7 +598,7 @@ A64_LDR_UIMM::A64_LDR_UIMM(void *inst) : A64LoadAndStoreImm(inst) { ...@@ -598,7 +598,7 @@ A64_LDR_UIMM::A64_LDR_UIMM(void *inst) : A64LoadAndStoreImm(inst) {
} }
A64_LDR_UIMM::A64_LDR_UIMM(RegisterA64 &rt, const MemOperand &operand) : A64LoadAndStoreImm(&rt, A64_LDR_UIMM::A64_LDR_UIMM(RegisterA64 &rt, const MemOperand &operand) : A64LoadAndStoreImm(&rt,
operand) {} operand) {}
void A64_LDR_UIMM::Disassemble() { void A64_LDR_UIMM::Disassemble() {
regSize = RegSize(Get()->size); regSize = RegSize(Get()->size);
...@@ -696,7 +696,7 @@ void A64_LDRSW_IMM::Assemble() { ...@@ -696,7 +696,7 @@ void A64_LDRSW_IMM::Assemble() {
A64_LDRSW_UIMM::A64_LDRSW_UIMM(void *inst) : A64_LDR_UIMM(inst) {} A64_LDRSW_UIMM::A64_LDRSW_UIMM(void *inst) : A64_LDR_UIMM(inst) {}
A64_LDRSW_UIMM::A64_LDRSW_UIMM(XRegister &rt, const MemOperand &operand) : A64_LDR_UIMM(rt, A64_LDRSW_UIMM::A64_LDRSW_UIMM(XRegister &rt, const MemOperand &operand) : A64_LDR_UIMM(rt,
operand) {} operand) {}
void A64_LDRSW_UIMM::Disassemble() { void A64_LDRSW_UIMM::Disassemble() {
DECODE_RT(XReg); DECODE_RT(XReg);
...@@ -721,8 +721,8 @@ A64_STP_LDP::A64_STP_LDP(void *inst) : InstructionA64(inst) { ...@@ -721,8 +721,8 @@ A64_STP_LDP::A64_STP_LDP(void *inst) : InstructionA64(inst) {
} }
A64_STP_LDP::A64_STP_LDP(OP op, RegisterA64 &rt1, RegisterA64 &rt2, const MemOperand &operand) : op(op), rt1(&rt1), A64_STP_LDP::A64_STP_LDP(OP op, RegisterA64 &rt1, RegisterA64 &rt2, const MemOperand &operand) : op(op), rt1(&rt1),
rt2(&rt2), rt2(&rt2),
operand(operand) {} operand(operand) {}
void A64_STP_LDP::Disassemble() { void A64_STP_LDP::Disassemble() {
DECODE_OP; DECODE_OP;
...@@ -779,7 +779,7 @@ A64_ADD_SUB_IMM::A64_ADD_SUB_IMM(void *inst) : InstructionA64(inst) { ...@@ -779,7 +779,7 @@ A64_ADD_SUB_IMM::A64_ADD_SUB_IMM(void *inst) : InstructionA64(inst) {
} }
A64_ADD_SUB_IMM::A64_ADD_SUB_IMM(A64_ADD_SUB_IMM::OP op, A64_ADD_SUB_IMM::S sign, RegisterA64 &rd, A64_ADD_SUB_IMM::A64_ADD_SUB_IMM(A64_ADD_SUB_IMM::OP op, A64_ADD_SUB_IMM::S sign, RegisterA64 &rd,
const Operand &operand) : op(op), sign(sign), rd(&rd), operand(operand) {} const Operand &operand) : op(op), sign(sign), rd(&rd), operand(operand) {}
void A64_ADD_SUB_IMM::Disassemble() { void A64_ADD_SUB_IMM::Disassemble() {
DECODE_OP; DECODE_OP;
...@@ -822,17 +822,17 @@ A64_MSR_MRS::A64_MSR_MRS(void *inst) : InstructionA64(inst) { ...@@ -822,17 +822,17 @@ A64_MSR_MRS::A64_MSR_MRS(void *inst) : InstructionA64(inst) {
} }
A64_MSR_MRS::A64_MSR_MRS(OP op, SystemRegister &systemRegister, RegisterA64 &rt) : op(op), system_reg( A64_MSR_MRS::A64_MSR_MRS(OP op, SystemRegister &systemRegister, RegisterA64 &rt) : op(op), system_reg(
&systemRegister), rt(&rt) {} systemRegister), rt(&rt) {}
void A64_MSR_MRS::Disassemble() { void A64_MSR_MRS::Disassemble() {
DECODE_OP; DECODE_OP;
DECODE_RT(XReg); DECODE_RT(XReg);
system_reg->value = static_cast<U16>(Get()->sysreg); system_reg.value = static_cast<U16>(Get()->sysreg);
} }
void A64_MSR_MRS::Assemble() { void A64_MSR_MRS::Assemble() {
SET_OPCODE(MSR_MRS); SET_OPCODE(MSR_MRS);
ENCODE_OP; ENCODE_OP;
ENCODE_RT; ENCODE_RT;
Get()->sysreg = system_reg->value; Get()->sysreg = system_reg.value;
} }
...@@ -753,7 +753,7 @@ namespace SandHook { ...@@ -753,7 +753,7 @@ namespace SandHook {
public: public:
OP op; OP op;
SystemRegister* system_reg; SystemRegister system_reg{};
RegisterA64* rt; RegisterA64* rt;
}; };
......
...@@ -28,7 +28,7 @@ namespace SandHook { ...@@ -28,7 +28,7 @@ namespace SandHook {
enum RegisterType { enum RegisterType {
// The kInvalid value is used to detect uninitialized static instances, // The kInvalid value is used to detect uninitialized static instances,
// which are always zero-initialized before any constructors are called. // which are always zero-initialized before any constructors are called.
kInvalid = 0, kInvalid = 0,
kRegister, kRegister,
kVRegister, kVRegister,
kFPRegister = kVRegister, kFPRegister = kVRegister,
...@@ -99,6 +99,8 @@ namespace SandHook { ...@@ -99,6 +99,8 @@ namespace SandHook {
U16 op0:2; U16 op0:2;
}; };
SystemRegister() {}
SystemRegister(U16 value) : value(value) {} SystemRegister(U16 value) : value(value) {}
SystemRegister(U16 op0, U16 op1, U16 crn, U16 crm, U16 op2) { SystemRegister(U16 op0, U16 op1, U16 crn, U16 crm, U16 op2) {
...@@ -115,7 +117,7 @@ namespace SandHook { ...@@ -115,7 +117,7 @@ namespace SandHook {
} }
bool operator!=(const SystemRegister &rhs) const { bool operator!=(const SystemRegister &rhs) const {
return !(rhs == *this); return value != rhs.value;
} }
public: public:
......
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
using namespace SandHook::Decoder; using namespace SandHook::Decoder;
bool DefaultVisitor::Visit(BaseUnit *unit, void *pc) { bool DefaultVisitor::Visit(BaseUnit *unit, void *pc) {
bool res = visitor(unit, pc); bool res = visitor_(reinterpret_cast<BaseInst*>(unit), pc);
delete unit; delete unit;
return res; return res;
} }
DefaultVisitor::DefaultVisitor(bool (*visitor)(BaseUnit *, void *)) : visitor(visitor) {} DefaultVisitor::DefaultVisitor(std::function<bool(BaseInst *inst, void *pc)> visitor) : visitor_(visitor) {}
//do not support now //do not support now
InstDecoder* Disassembler::Get(Arch arch) { InstDecoder* Disassembler::Get(Arch arch) {
......
...@@ -23,21 +23,21 @@ namespace SandHook { ...@@ -23,21 +23,21 @@ namespace SandHook {
class DefaultVisitor : public InstVisitor { class DefaultVisitor : public InstVisitor {
public: public:
DefaultVisitor(bool (*visitor)(BaseUnit *, void *)); DefaultVisitor(std::function<bool(BaseInst *inst, void *pc)> visitor);
bool Visit(BaseUnit *unit, void *pc) override; bool Visit(BaseUnit *unit, void *pc) override;
private: private:
bool (*visitor)(BaseUnit*, void*); std::function<bool(BaseInst *inst, void *pc)> visitor_;
}; };
class InstDecoder { class InstDecoder {
public: public:
virtual void Disassemble(void *code_start, Addr code_len, InstVisitor &visitor, virtual void Disassemble(void *code_start, Addr code_len, InstVisitor &visitor,
bool only_pc_rel = false) = 0; bool only_pc_rel = false) = 0;
inline void Disassemble(void *codeStart, Addr codeLen, inline void Disassemble(void *code_start, Addr codeLen,
bool (*visitor)(BaseUnit *, void *), bool only_pc_rel = false) { std::function<bool(BaseInst *inst, void *pc)> visitor, bool only_pc_rel = false) {
InstVisitor vis = DefaultVisitor(visitor); DefaultVisitor vis = DefaultVisitor(visitor);
Disassemble(codeStart, codeLen, vis, only_pc_rel); Disassemble(code_start, codeLen, vis, only_pc_rel);
}; };
}; };
......
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