forked from vmp3/vmprofiler
parent
dcb8e1c96a
commit
9ad92bc50e
@ -0,0 +1,37 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
namespace vm::instrs {
|
||||
profiler_t lvsp = {
|
||||
"LVSP",
|
||||
mnemonic_t::lvsp,
|
||||
{{// MOV VSP, [VSP]
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
instr.operands[0].reg.value == vsp &&
|
||||
instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
instr.operands[1].mem.base == vsp;
|
||||
}}},
|
||||
[&](zydis_reg_t& vip,
|
||||
zydis_reg_t& vsp,
|
||||
hndlr_trace_t& hndlr) -> std::optional<vinstr_t> {
|
||||
vinstr_t res{mnemonic_t::svsp};
|
||||
res.imm.has_imm = false;
|
||||
|
||||
const auto load_vsp = std::find_if(
|
||||
hndlr.m_instrs.begin(), hndlr.m_instrs.end(),
|
||||
[&](emu_instr_t& instr) -> bool {
|
||||
const auto& i = instr.m_instr;
|
||||
return i.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
i.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
i.operands[0].reg.value == vsp &&
|
||||
i.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
i.operands[1].mem.base == vsp;
|
||||
});
|
||||
|
||||
res.stack_size = load_vsp->m_instr.operands[0].size;
|
||||
return res;
|
||||
}};
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
namespace vm::instrs {
|
||||
profiler_t nand = {
|
||||
"NAND",
|
||||
mnemonic_t::nand,
|
||||
{{// MOV REG, [VSP]
|
||||
LOAD_VALUE,
|
||||
// MOV REG, [VSP+OFFSET]
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
instr.operands[1].mem.base == vsp &&
|
||||
instr.operands[1].mem.disp.has_displacement;
|
||||
},
|
||||
// NOT REG
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_NOT &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER;
|
||||
},
|
||||
// AND REG, REG
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_AND &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER;
|
||||
},
|
||||
// MOV [VSP+OFFSET], REG
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
instr.operands[0].mem.base == vsp &&
|
||||
instr.operands[0].mem.disp.has_displacement &&
|
||||
instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER;
|
||||
},
|
||||
// PUSHFQ
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ;
|
||||
},
|
||||
// POP [VSP]
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_POP &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
instr.operands[0].mem.base == vsp;
|
||||
}}},
|
||||
[&](zydis_reg_t& vip,
|
||||
zydis_reg_t& vsp,
|
||||
hndlr_trace_t& hndlr) -> std::optional<vinstr_t> {
|
||||
vinstr_t res{mnemonic_t::nand};
|
||||
res.imm.has_imm = false;
|
||||
|
||||
// MOV [VSP+OFFSET], REG
|
||||
const auto mov_vsp_reg = std::find_if(
|
||||
hndlr.m_instrs.begin(), hndlr.m_instrs.end(),
|
||||
[&](emu_instr_t& instr) -> bool {
|
||||
const auto& i = instr.m_instr;
|
||||
return i.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
i.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
i.operands[0].mem.base == vsp &&
|
||||
i.operands[0].mem.disp.has_displacement &&
|
||||
i.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER;
|
||||
});
|
||||
|
||||
res.stack_size = mov_vsp_reg->m_instr.operands[1].size;
|
||||
return res;
|
||||
}};
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
namespace vm::instrs {
|
||||
profiler_t read = {
|
||||
"READ",
|
||||
mnemonic_t::read,
|
||||
{{// MOV REG, [VSP]
|
||||
LOAD_VALUE,
|
||||
// MOV REG, [REG]
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
instr.operands[1].mem.base != vsp;
|
||||
},
|
||||
// MOV [VSP], REG
|
||||
STR_VALUE}},
|
||||
[&](zydis_reg_t& vip,
|
||||
zydis_reg_t& vsp,
|
||||
hndlr_trace_t& hndlr) -> std::optional<vinstr_t> {
|
||||
vinstr_t res{mnemonic_t::read};
|
||||
res.imm.has_imm = false;
|
||||
|
||||
// MOV REG, [REG]
|
||||
const auto mov_reg_reg = std::find_if(
|
||||
hndlr.m_instrs.begin(), hndlr.m_instrs.end(),
|
||||
[&](emu_instr_t& instr) -> bool {
|
||||
const auto& i = instr.m_instr;
|
||||
return i.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
i.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
i.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
i.operands[1].mem.base != vsp;
|
||||
});
|
||||
|
||||
res.stack_size = mov_reg_reg->m_instr.operands[0].size;
|
||||
return res;
|
||||
}};
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
namespace vm::instrs {
|
||||
profiler_t svsp = {
|
||||
"SVSP",
|
||||
mnemonic_t::svsp,
|
||||
{{// MOV REG, VSP
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
instr.operands[1].reg.value == vsp;
|
||||
},
|
||||
// SUB VSP, OFFSET
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_SUB &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
instr.operands[0].reg.value == vsp &&
|
||||
instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE;
|
||||
},
|
||||
// MOV [VSP], REG
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
instr.operands[0].mem.base == vsp &&
|
||||
instr.operands[0].mem.disp.has_displacement == false &&
|
||||
instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER;
|
||||
}}},
|
||||
[&](zydis_reg_t& vip,
|
||||
zydis_reg_t& vsp,
|
||||
hndlr_trace_t& hndlr) -> std::optional<vinstr_t> {
|
||||
vinstr_t res{mnemonic_t::lvsp};
|
||||
const auto sub_vsp = std::find_if(
|
||||
hndlr.m_instrs.begin(), hndlr.m_instrs.end(),
|
||||
[&](emu_instr_t& instr) -> bool {
|
||||
const auto& i = instr.m_instr;
|
||||
return i.mnemonic == ZYDIS_MNEMONIC_SUB &&
|
||||
i.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
i.operands[0].reg.value == vsp &&
|
||||
i.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE;
|
||||
});
|
||||
|
||||
res.imm.has_imm = false;
|
||||
res.stack_size = sub_vsp->m_instr.operands[1].imm.value.u;
|
||||
return res;
|
||||
}};
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
namespace vm::instrs {
|
||||
profiler_t write = {
|
||||
"WRITE",
|
||||
mnemonic_t::write,
|
||||
{{// MOV REG, [VSP]
|
||||
LOAD_VALUE,
|
||||
// MOV REG, [VSP+OFFSET]
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
instr.operands[1].mem.base == vsp &&
|
||||
instr.operands[1].mem.disp.has_displacement;
|
||||
},
|
||||
// ADD VSP, OFFSET
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_ADD &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
instr.operands[0].reg.value == vsp &&
|
||||
instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE;
|
||||
},
|
||||
// MOV [REG], REG
|
||||
[&](const zydis_reg_t vip,
|
||||
const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
instr.operands[0].mem.base != vsp &&
|
||||
instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
instr.operands[1].reg.value != vsp;
|
||||
}}},
|
||||
[&](zydis_reg_t& vip,
|
||||
zydis_reg_t& vsp,
|
||||
hndlr_trace_t& hndlr) -> std::optional<vinstr_t> {
|
||||
vinstr_t res{mnemonic_t::write};
|
||||
res.imm.has_imm = false;
|
||||
|
||||
const auto mov_reg_reg = std::find_if(
|
||||
hndlr.m_instrs.begin(), hndlr.m_instrs.end(),
|
||||
[&](emu_instr_t& instr) -> bool {
|
||||
const auto& i = instr.m_instr;
|
||||
return i.mnemonic == ZYDIS_MNEMONIC_MOV &&
|
||||
i.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
i.operands[0].mem.base != vsp &&
|
||||
i.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
i.operands[1].reg.value != vsp;
|
||||
});
|
||||
|
||||
res.stack_size = mov_reg_reg->m_instr.operands[1].size;
|
||||
return res;
|
||||
}};
|
||||
}
|
Loading…
Reference in new issue