|
|
|
#pragma once
|
|
|
|
#include <vmp2.hpp>
|
|
|
|
#include <vmprofiles.hpp>
|
|
|
|
#include <vtil/vtil>
|
|
|
|
|
|
|
|
namespace vm::lifters
|
|
|
|
{
|
|
|
|
using lifter_callback_t = std::function< void( vtil::basic_block *, vm::instrs::virt_instr_t *, vmp2::v3::code_block_t* ) >;
|
|
|
|
using lifter_t = std::pair< vm::handler::mnemonic_t, lifter_callback_t >;
|
|
|
|
|
|
|
|
// taken from
|
|
|
|
// https://github.com/can1357/NoVmp/blob/6c23c9a335f70e8d5ed6299668fd802f2314c896/NoVmp/vmprotect/il2vtil.cpp#L66
|
|
|
|
inline constexpr vtil::register_desc make_virtual_register( uint8_t context_offset, uint8_t size )
|
|
|
|
{
|
|
|
|
fassert( ( ( context_offset & 7 ) + size ) <= 8 && size );
|
|
|
|
|
|
|
|
return { vtil::register_virtual, ( size_t )context_offset / 8, size * 8, ( context_offset % 8 ) * 8 };
|
|
|
|
}
|
|
|
|
|
|
|
|
extern vm::lifters::lifter_t lregq, lregdw;
|
|
|
|
extern vm::lifters::lifter_t addq, adddw, addw;
|
|
|
|
extern vm::lifters::lifter_t sregq, sregdw, sregw;
|
|
|
|
extern vm::lifters::lifter_t lconstq, lconstdw, lconstw, lconstbzxw, lconstbsxdw, lconstbsxq, lconstdwsxq,
|
|
|
|
lconstwsxq, lconstwsxdw;
|
|
|
|
extern vm::lifters::lifter_t nandq, nanddw, nandw;
|
|
|
|
extern vm::lifters::lifter_t readq, readdw, readw;
|
|
|
|
extern vm::lifters::lifter_t shrq, shrw;
|
|
|
|
|
|
|
|
extern vm::lifters::lifter_t jmp;
|
|
|
|
extern vm::lifters::lifter_t vmexit;
|
|
|
|
extern vm::lifters::lifter_t pushvsp;
|
|
|
|
extern vm::lifters::lifter_t lrflags;
|
|
|
|
extern vm::lifters::lifter_t lvsp;
|
|
|
|
|
|
|
|
inline std::vector< vm::lifters::lifter_t * > all = {
|
|
|
|
// lreg lifters...
|
|
|
|
&lregq, &lregdw,
|
|
|
|
|
|
|
|
// add lifters...
|
|
|
|
&addq, &adddw, &addw,
|
|
|
|
|
|
|
|
// sreg lifters...
|
|
|
|
&sregq, &sregdw, &sregw,
|
|
|
|
|
|
|
|
// lconst lifters...
|
|
|
|
&lconstq, &lconstdw, &lconstw, &lconstbzxw, &lconstbsxdw, &lconstbsxq, &lconstdwsxq, &lconstwsxq, &lconstwsxdw,
|
|
|
|
|
|
|
|
// nand lifters...
|
|
|
|
&nandq, &nanddw, &nandw,
|
|
|
|
|
|
|
|
// read lifters....
|
|
|
|
&readq, &readdw, &readw,
|
|
|
|
|
|
|
|
// shr lifters...
|
|
|
|
&shrq, &shrw,
|
|
|
|
|
|
|
|
// pushvsp lifter...
|
|
|
|
&pushvsp,
|
|
|
|
|
|
|
|
// jmp lifter...
|
|
|
|
&jmp,
|
|
|
|
|
|
|
|
// lflags lifter...
|
|
|
|
&lrflags,
|
|
|
|
|
|
|
|
// lvsp lifter...
|
|
|
|
&lvsp,
|
|
|
|
|
|
|
|
// vmexit lifter...
|
|
|
|
&vmexit };
|
|
|
|
} // namespace vm::lifters
|