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)
......
...@@ -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;
}; };
......
...@@ -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