added shr profile

master
John Doe 3 years ago
parent 2b4bb0ebed
commit fc310689a5

@ -62,6 +62,7 @@ list(APPEND vmprofiler_SOURCES
"src/vmprofiles/nand.cpp" "src/vmprofiles/nand.cpp"
"src/vmprofiles/nor.cpp" "src/vmprofiles/nor.cpp"
"src/vmprofiles/read.cpp" "src/vmprofiles/read.cpp"
"src/vmprofiles/shr.cpp"
"src/vmprofiles/sreg.cpp" "src/vmprofiles/sreg.cpp"
"src/vmprofiles/svsp.cpp" "src/vmprofiles/svsp.cpp"
"src/vmprofiles/write.cpp" "src/vmprofiles/write.cpp"

@ -149,13 +149,14 @@ extern profiler_t nor;
extern profiler_t read; extern profiler_t read;
extern profiler_t write; extern profiler_t write;
extern profiler_t imul; extern profiler_t imul;
extern profiler_t shr;
/// <summary> /// <summary>
/// unsorted vector of profiles... they get sorted once at runtime... /// unsorted vector of profiles... they get sorted once at runtime...
/// </summary> /// </summary>
inline std::vector<profiler_t*> profiles = {&imul, &nor, &write, &svsp, inline std::vector<profiler_t*> profiles = {&shr, &imul, &nor, &write, &svsp,
&read, &nand, &lvsp, &add, &read, &nand, &lvsp, &add, &jmp,
&jmp, &sreg, &lreg, &lconst}; &sreg, &lreg, &lconst};
/// <summary> /// <summary>
/// no i did not make this by hand, you cannot clown upon me! /// no i did not make this by hand, you cannot clown upon me!

@ -0,0 +1,69 @@
#include <vminstrs.hpp>
namespace vm::instrs {
profiler_t shr = {
"SHR",
mnemonic_t::shr,
{{// 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;
},
// SHR REG, REG
[&](const zydis_reg_t vip,
const zydis_reg_t vsp,
const zydis_decoded_instr_t& instr) -> bool {
return instr.mnemonic == ZYDIS_MNEMONIC_SHR &&
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::shr};
res.imm.has_imm = false;
const auto shr_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_SHR &&
i.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
i.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER;
});
res.stack_size = shr_reg->m_instr.operands[0].size;
return res;
}};
}
Loading…
Cancel
Save