forked from vmp3/vmprofiler
Compare commits
30 Commits
343c7b95a4
...
f65c84050d
Author | SHA1 | Date |
---|---|---|
xtremegamer1 | f65c84050d | 2 years ago |
xtremegamer1 | 1516e2a278 | 2 years ago |
xtremegamer1 | 80b5c20795 | 2 years ago |
xtremegamer1 | d63f9b1af1 | 2 years ago |
xtremegamer1 | 63c10f71dd | 2 years ago |
xtremegamer1 | e3abc955e1 | 2 years ago |
xtremegamer1 | 39a906f837 | 2 years ago |
xtremegamer1 | fcdc3866c6 | 2 years ago |
xtremegamer1 | f78333e3fe | 2 years ago |
xtremegamer1 | 1491e62d72 | 2 years ago |
xtremegamer1 | 9ae338e7d1 | 2 years ago |
xtremegamer1 | 0c9a67c6c0 | 2 years ago |
xtremegamer1 | 2a72cbffcd | 2 years ago |
xtremegamer1 | 2cc88f60ab | 2 years ago |
xtremegamer1 | bcf5c66643 | 2 years ago |
xtremegamer1 | 4de96fbaef | 2 years ago |
xtremegamer1 | 38754fc26b | 2 years ago |
xtremegamer1 | f8247a9487 | 2 years ago |
xtremegamer1 | 34c109f303 | 2 years ago |
xtremegamer1 | c9c5a7d11e | 2 years ago |
xtremegamer1 | 450ced9740 | 2 years ago |
xtremegamer1 | 9713d1b144 | 2 years ago |
xtremegamer1 | 4776d1e49f | 2 years ago |
xtremegamer1 | 1829b58cc6 | 2 years ago |
xtremegamer1 | e7c07c11d4 | 2 years ago |
xtremegamer1 | 0e1619b76e | 2 years ago |
xtremegamer1 | bed10c0c46 | 2 years ago |
xtremegamer1 | 8d42008427 | 2 years ago |
xtremegamer1 | 415150657d | 2 years ago |
xtremegamer1 | e14d4f67e8 | 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