forked from vmp3/vmprofiler
Compare commits
29 Commits
f65c84050d
...
343c7b95a4
Author | SHA1 | Date |
---|---|---|
xtremegamer1 | 343c7b95a4 | 2 years ago |
xtremegamer1 | f35a70749f | 2 years ago |
xtremegamer1 | e62c872fbe | 2 years ago |
xtremegamer1 | adff58848c | 2 years ago |
xtremegamer1 | 09b4e52f3a | 2 years ago |
xtremegamer1 | b6aaaaeef4 | 2 years ago |
xtremegamer1 | 0c1b62b2ca | 2 years ago |
xtremegamer1 | 8d124ec828 | 2 years ago |
xtremegamer1 | c8695100e6 | 2 years ago |
xtremegamer1 | 1d685efa0c | 2 years ago |
xtremegamer1 | f40579dc0c | 2 years ago |
xtremegamer1 | 462157b22c | 2 years ago |
xtremegamer1 | e74f291d56 | 2 years ago |
xtremegamer1 | 885f987d04 | 2 years ago |
xtremegamer1 | dd3aeabbb0 | 2 years ago |
xtremegamer1 | ff1790ae22 | 2 years ago |
xtremegamer1 | 25c3008dc2 | 2 years ago |
xtremegamer1 | 512b19292c | 2 years ago |
xtremegamer1 | 10c39981cc | 2 years ago |
xtremegamer1 | da7292eb31 | 2 years ago |
xtremegamer1 | 88c167bb67 | 2 years ago |
xtremegamer1 | b0126f6f48 | 2 years ago |
xtremegamer1 | f253e88ec1 | 2 years ago |
xtremegamer1 | 70d797420c | 2 years ago |
xtremegamer1 | 7b13df4bf6 | 2 years ago |
xtremegamer1 | 0be31ec977 | 2 years ago |
xtremegamer1 | ddd58c2a98 | 2 years ago |
xtremegamer1 | 0a8964d3ab | 2 years ago |
xtremegamer1 | c39b783af8 | 2 years ago |
@ -1 +1 @@
|
||||
Subproject commit 2a9f9c66775a4ac3d56bb163c85563df3cea7547
|
||||
Subproject commit ce4a42ffaffe4a5ff615665e05177c4c69eb4683
|
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <unicorn\unicorn.h>
|
||||
|
||||
extern int g_allocation_tracker;
|
||||
|
||||
uc_err uct_context_alloc(uc_engine *uc, uc_context **context);
|
||||
uc_err uct_context_free(uc_context *context);
|
||||
void print_allocation_number();
|
@ -0,0 +1,22 @@
|
||||
#include <uc_allocation_tracker.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
int g_allocation_tracker;
|
||||
|
||||
uc_err uct_context_alloc(uc_engine *uc, uc_context **context)
|
||||
{
|
||||
++g_allocation_tracker;
|
||||
//std::printf("Allocations: %p\n", g_allocation_tracker);
|
||||
return uc_context_alloc(uc, context);
|
||||
}
|
||||
uc_err uct_context_free(uc_context *context)
|
||||
{
|
||||
--g_allocation_tracker;
|
||||
//std::printf("Allocations: %p\n", g_allocation_tracker);
|
||||
return uc_context_free(context);
|
||||
}
|
||||
|
||||
void print_allocation_number()
|
||||
{
|
||||
std::printf("uc_context allocations: %p\n", g_allocation_tracker);
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
// Loads an address and value from the stack, ands the derefed address with the value
|
||||
namespace vm::instrs {
|
||||
profiler_t _and = {
|
||||
"AND",
|
||||
mnemonic_t::_and,
|
||||
{{// MOV REG, [VSP] This is the address
|
||||
LOAD_VALUE,
|
||||
// MOV REG, [VSP+8]
|
||||
[](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,
|
||||
instr.operands[1].mem.disp.value == 8;
|
||||
},
|
||||
// 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_MEMORY &&
|
||||
instr.operands[0].mem.base != ZYDIS_REGISTER_NONE &&
|
||||
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::_and};
|
||||
res.imm.has_imm = false;
|
||||
|
||||
// MOV REG [VSP+OFFSET]
|
||||
const auto mov_vsp_offset = 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 &&
|
||||
i.operands[1].mem.disp.has_displacement;
|
||||
});
|
||||
if (mov_vsp_offset == hndlr.m_instrs.end())
|
||||
return std::nullopt;
|
||||
|
||||
res.stack_size = mov_vsp_offset->m_instr.operands[0].size;
|
||||
return res;
|
||||
}};
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
//Loads CR0 onto the stack
|
||||
namespace vm::instrs {
|
||||
profiler_t lcr0 = {
|
||||
"LCR0",
|
||||
mnemonic_t::lcr0,
|
||||
{
|
||||
// MOV REG, CR0
|
||||
[](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 == ZYDIS_REGISTER_CR0;
|
||||
},
|
||||
// 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.index == ZYDIS_REGISTER_NONE &&
|
||||
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::lcr0};
|
||||
res.imm.has_imm = false;
|
||||
res.stack_size = 64;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
namespace vm::instrs {
|
||||
profiler_t _or = {
|
||||
"OR",
|
||||
mnemonic_t::_or,
|
||||
{{// 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;
|
||||
},
|
||||
// OR [REG], REG
|
||||
[](const zydis_reg_t vip, const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_OR &&
|
||||
instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY &&
|
||||
instr.operands[0].mem.base != ZYDIS_REGISTER_NONE &&
|
||||
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::_or};
|
||||
res.imm.has_imm = false;
|
||||
|
||||
// MOV REG [VSP+OFFSET]
|
||||
const auto reg_vsp_offset = 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 &&
|
||||
i.operands[1].mem.disp.has_displacement;
|
||||
});
|
||||
if (reg_vsp_offset == hndlr.m_instrs.end())
|
||||
return std::nullopt;
|
||||
res.stack_size = reg_vsp_offset->m_instr.operands[0].size;
|
||||
return res;
|
||||
}};
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
namespace vm::instrs {
|
||||
profiler_t shl = {
|
||||
"SHL",
|
||||
mnemonic_t::shl,
|
||||
{{// 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;
|
||||
},
|
||||
// SHL REG, REG
|
||||
[](const zydis_reg_t vip, const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_SHL &&
|
||||
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::shl};
|
||||
res.imm.has_imm = false;
|
||||
|
||||
const auto shl_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_SHL &&
|
||||
i.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
i.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER;
|
||||
});
|
||||
|
||||
res.stack_size = shl_reg->m_instr.operands[0].size;
|
||||
return res;
|
||||
}};
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
namespace vm::instrs {
|
||||
profiler_t shld = {
|
||||
"SHLD",
|
||||
mnemonic_t::shld,
|
||||
{{// 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;
|
||||
},
|
||||
// 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;
|
||||
},
|
||||
// SHLD REG, REG
|
||||
[](const zydis_reg_t vip, const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_SHLD &&
|
||||
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::shld};
|
||||
res.imm.has_imm = false;
|
||||
|
||||
const auto shld_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_SHLD &&
|
||||
i.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
i.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER;
|
||||
});
|
||||
|
||||
res.stack_size = shld_reg->m_instr.operands[0].size;
|
||||
return res;
|
||||
}};
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
namespace vm::instrs {
|
||||
profiler_t shrd = {
|
||||
"SHRD",
|
||||
mnemonic_t::shrd,
|
||||
{{// 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;
|
||||
},
|
||||
// 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;
|
||||
},
|
||||
// SHRD REG, REG
|
||||
[](const zydis_reg_t vip, const zydis_reg_t vsp,
|
||||
const zydis_decoded_instr_t& instr) -> bool {
|
||||
return instr.mnemonic == ZYDIS_MNEMONIC_SHRD &&
|
||||
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::shrd};
|
||||
res.imm.has_imm = false;
|
||||
|
||||
const auto shrd_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_SHRD &&
|
||||
i.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER &&
|
||||
i.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER;
|
||||
});
|
||||
|
||||
res.stack_size = shrd_reg->m_instr.operands[0].size;
|
||||
return res;
|
||||
}};
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
#include <vminstrs.hpp>
|
||||
|
||||
//Write value on top of stack to dr7
|
||||
namespace vm::instrs {
|
||||
profiler_t writedr7 = {
|
||||
"WRITEDR7",
|
||||
mnemonic_t::writedr7,
|
||||
{
|
||||
// MOV REG, [VSP+OFFSET]
|
||||
LOAD_VALUE,
|
||||
// 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 DR7, 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[0].reg.value == ZYDIS_REGISTER_DR7 &&
|
||||
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::writedr7};
|
||||
res.stack_size == 64;
|
||||
res.imm.has_imm = false;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in new issue