_xeroxz into master See merge request vmp2/vmdevirt!12master v0.1
commit
680edc4faf
@ -1 +1 @@
|
|||||||
Subproject commit 7b1f815a73096ac33f41133b63d991019622de49
|
Subproject commit 1b6875d18825529907289bc87990fed5d99e7f96
|
@ -0,0 +1,34 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::divq =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 8 );
|
||||||
|
auto t2 = rtn->pop( 8 );
|
||||||
|
auto t3 = rtn->pop( 8 );
|
||||||
|
ir_builder->CreateUDiv( t2, t3 );
|
||||||
|
rtn->push( 8, t1 );
|
||||||
|
rtn->push( 8, t2 );
|
||||||
|
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
// TODO: compute flags...
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
|
||||||
|
lifters_t::lifter_callback_t lifters_t::divdw =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 4 );
|
||||||
|
auto t2 = rtn->pop( 4 );
|
||||||
|
auto t3 = rtn->pop( 4 );
|
||||||
|
ir_builder->CreateUDiv( t2, t3 );
|
||||||
|
rtn->push( 4, t1 );
|
||||||
|
rtn->push( 4, t2 );
|
||||||
|
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
// TODO: compute flags...
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
} // namespace vm
|
@ -0,0 +1,20 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::idivdw =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 4 );
|
||||||
|
auto t2 = rtn->pop( 4 );
|
||||||
|
|
||||||
|
// TODO: this is wrong...
|
||||||
|
ir_builder->CreateUDiv( t1, t2 );
|
||||||
|
rtn->push( 4, t1 );
|
||||||
|
rtn->push( 4, t2 );
|
||||||
|
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
// TODO: compute flags...
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
// https://lists.llvm.org/pipermail/llvm-dev/2014-July/074685.html
|
||||||
|
// credit to James Courtier-Dutton for asking this question in 2014...
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::imulq =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 8 );
|
||||||
|
auto t2 = rtn->pop( 8 );
|
||||||
|
|
||||||
|
// TODO: this is wrong... still need to do some more research into this...
|
||||||
|
auto t3 = ir_builder->CreateMul( t1, t2 );
|
||||||
|
auto t4 = ir_builder->CreateAShr( t3, llvm::APInt( 64, 32 ) );
|
||||||
|
auto t5 = ir_builder->CreateAnd( t3, 0xFFFFFFFF00000000 );
|
||||||
|
rtn->push( 8, t4 );
|
||||||
|
rtn->push( 8, t5 );
|
||||||
|
|
||||||
|
// TODO: compute flags for IMULQ
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
|
||||||
|
lifters_t::lifter_callback_t lifters_t::imuldw =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 4 );
|
||||||
|
auto t2 = rtn->pop( 4 );
|
||||||
|
|
||||||
|
auto t3 = ir_builder->CreateIntCast( t1, ir_builder->getInt64Ty(), false );
|
||||||
|
auto t4 = ir_builder->CreateIntCast( t2, ir_builder->getInt64Ty(), false );
|
||||||
|
|
||||||
|
auto t5 = ir_builder->CreateMul( t3, t4 );
|
||||||
|
auto t6 = ir_builder->CreateAShr( t5, llvm::APInt( 64, 32 ) );
|
||||||
|
auto t7 = ir_builder->CreateAnd( t5, 0xFFFFFFFF00000000 );
|
||||||
|
|
||||||
|
rtn->push( 8, t6 );
|
||||||
|
rtn->push( 8, t7 );
|
||||||
|
|
||||||
|
// TODO: compute flags for IMULQ
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
} // namespace vm
|
@ -0,0 +1,40 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::mulq =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 8 );
|
||||||
|
auto t2 = rtn->pop( 8 );
|
||||||
|
|
||||||
|
// TODO: this is wrong... still need to do some more research into this...
|
||||||
|
auto t3 = ir_builder->CreateMul( t1, t2 );
|
||||||
|
auto t4 = ir_builder->CreateAShr( t3, llvm::APInt( 64, 32 ) );
|
||||||
|
auto t5 = ir_builder->CreateAnd( t3, 0xFFFFFFFF00000000 );
|
||||||
|
rtn->push( 8, t4 );
|
||||||
|
rtn->push( 8, t5 );
|
||||||
|
|
||||||
|
// TODO: compute flags for IMULQ
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
|
||||||
|
lifters_t::lifter_callback_t lifters_t::muldw =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 4 );
|
||||||
|
auto t2 = rtn->pop( 4 );
|
||||||
|
|
||||||
|
// TODO: this is wrong... still need to do some more research into this...
|
||||||
|
auto t3 = ir_builder->CreateMul( t1, t2 );
|
||||||
|
auto t4 = ir_builder->CreateAShr( t3, llvm::APInt( 32, 16 ) );
|
||||||
|
auto t5 = ir_builder->CreateAnd( t3, 0xFFFF0000 );
|
||||||
|
rtn->push( 4, t4 );
|
||||||
|
rtn->push( 4, t5 );
|
||||||
|
|
||||||
|
// TODO: compute flags for IMULQ
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::rdtsc =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
llvm::Function *rdtsc_intrin = nullptr;
|
||||||
|
if ( !( rdtsc_intrin = rtn->llvm_module->getFunction( "rdtsc" ) ) )
|
||||||
|
{
|
||||||
|
rdtsc_intrin = llvm::Function::Create( llvm::FunctionType::get( ir_builder->getVoidTy(), false ),
|
||||||
|
llvm::GlobalValue::LinkageTypes::ExternalLinkage, "rdtsc",
|
||||||
|
*rtn->llvm_module );
|
||||||
|
|
||||||
|
auto entry_block = llvm::BasicBlock::Create( ir_builder->getContext(), "", rdtsc_intrin );
|
||||||
|
auto ib = ir_builder->GetInsertBlock();
|
||||||
|
ir_builder->SetInsertPoint( entry_block );
|
||||||
|
|
||||||
|
// TODO: put RDTSC code here...
|
||||||
|
|
||||||
|
ir_builder->CreateRetVoid();
|
||||||
|
ir_builder->SetInsertPoint( ib );
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
ir_builder->CreateCall( rdtsc_intrin );
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::readcr3 =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
llvm::Function *readcr3_intrin = nullptr;
|
||||||
|
if ( !( readcr3_intrin = rtn->llvm_module->getFunction( "readcr3" ) ) )
|
||||||
|
{
|
||||||
|
readcr3_intrin = llvm::Function::Create( llvm::FunctionType::get( ir_builder->getInt64Ty(), false ),
|
||||||
|
llvm::GlobalValue::LinkageTypes::ExternalLinkage, "readcr3",
|
||||||
|
*rtn->llvm_module );
|
||||||
|
|
||||||
|
auto entry_block = llvm::BasicBlock::Create( ir_builder->getContext(), "", readcr3_intrin );
|
||||||
|
auto ib = ir_builder->GetInsertBlock();
|
||||||
|
ir_builder->SetInsertPoint( entry_block );
|
||||||
|
|
||||||
|
std::string asm_str( "mov rax, cr3; ret" );
|
||||||
|
auto intrin = llvm::InlineAsm::get( llvm::FunctionType::get( ir_builder->getVoidTy(), false ), asm_str,
|
||||||
|
"", false, false, llvm::InlineAsm::AD_Intel );
|
||||||
|
|
||||||
|
ir_builder->CreateCall( intrin );
|
||||||
|
ir_builder->CreateRet( llvm::ConstantInt::get( *rtn->llvm_ctx, llvm::APInt( 64, 0 ) ) );
|
||||||
|
ir_builder->SetInsertPoint( ib );
|
||||||
|
}
|
||||||
|
auto t1 = ir_builder->CreateCall( readcr3_intrin );
|
||||||
|
rtn->push( 8, t1 );
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::readcr8 =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
llvm::Function *readcr8_intrin = nullptr;
|
||||||
|
if ( !( readcr8_intrin = rtn->llvm_module->getFunction( "readcr8" ) ) )
|
||||||
|
{
|
||||||
|
readcr8_intrin = llvm::Function::Create( llvm::FunctionType::get( ir_builder->getInt64Ty(), false ),
|
||||||
|
llvm::GlobalValue::LinkageTypes::ExternalLinkage, "readcr8",
|
||||||
|
*rtn->llvm_module );
|
||||||
|
|
||||||
|
auto entry_block = llvm::BasicBlock::Create( ir_builder->getContext(), "", readcr8_intrin );
|
||||||
|
auto ib = ir_builder->GetInsertBlock();
|
||||||
|
ir_builder->SetInsertPoint( entry_block );
|
||||||
|
|
||||||
|
std::string asm_str( "mov rax, cr8; ret" );
|
||||||
|
auto intrin = llvm::InlineAsm::get( llvm::FunctionType::get( ir_builder->getVoidTy(), false ), asm_str,
|
||||||
|
"", false, false, llvm::InlineAsm::AD_Intel );
|
||||||
|
|
||||||
|
ir_builder->CreateCall( intrin );
|
||||||
|
ir_builder->CreateRet( llvm::ConstantInt::get( *rtn->llvm_ctx, llvm::APInt( 64, 0 ) ) );
|
||||||
|
ir_builder->SetInsertPoint( ib );
|
||||||
|
}
|
||||||
|
auto t1 = ir_builder->CreateCall( readcr8_intrin );
|
||||||
|
rtn->push( 8, t1 );
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::readgsq =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
llvm::Function *readgs_intrin = nullptr;
|
||||||
|
if ( !( readgs_intrin = rtn->llvm_module->getFunction( "readgs" ) ) )
|
||||||
|
{
|
||||||
|
readgs_intrin = llvm::Function::Create(
|
||||||
|
llvm::FunctionType::get( ir_builder->getInt64Ty(), { ir_builder->getInt64Ty() }, false ),
|
||||||
|
llvm::GlobalValue::LinkageTypes::ExternalLinkage, "readgs", *rtn->llvm_module );
|
||||||
|
|
||||||
|
auto entry_block = llvm::BasicBlock::Create( ir_builder->getContext(), "", readgs_intrin );
|
||||||
|
auto ib = ir_builder->GetInsertBlock();
|
||||||
|
ir_builder->SetInsertPoint( entry_block );
|
||||||
|
|
||||||
|
std::string asm_str( "mov rax, gs:[rcx]; ret" );
|
||||||
|
auto intrin = llvm::InlineAsm::get( llvm::FunctionType::get( ir_builder->getVoidTy(), false ), asm_str,
|
||||||
|
"", false, false, llvm::InlineAsm::AD_Intel );
|
||||||
|
|
||||||
|
ir_builder->CreateCall( intrin );
|
||||||
|
ir_builder->CreateRet( llvm::ConstantInt::get( *rtn->llvm_ctx, llvm::APInt( 64, 0 ) ) );
|
||||||
|
ir_builder->SetInsertPoint( ib );
|
||||||
|
}
|
||||||
|
|
||||||
|
auto t1 = rtn->pop( 8 );
|
||||||
|
auto t2 = ir_builder->CreateCall( readgs_intrin, { t1 } );
|
||||||
|
rtn->push( 8, t2 );
|
||||||
|
};
|
||||||
|
} // namespace vm
|
@ -0,0 +1,50 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::shlq =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 8 );
|
||||||
|
auto t2 = rtn->pop( 2 );
|
||||||
|
auto t3 = ir_builder->CreateIntCast( t2, llvm::IntegerType::get( *rtn->llvm_ctx, 64 ), false );
|
||||||
|
auto t4 = ir_builder->CreateShl( t1, t3 );
|
||||||
|
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
// TODO: update rflags...
|
||||||
|
|
||||||
|
rtn->push( 8, t4 );
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
|
||||||
|
lifters_t::lifter_callback_t lifters_t::shldw =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 4 );
|
||||||
|
auto t2 = rtn->pop( 2 );
|
||||||
|
auto t3 = ir_builder->CreateIntCast( t2, llvm::IntegerType::get( *rtn->llvm_ctx, 32 ), false );
|
||||||
|
auto t4 = ir_builder->CreateShl( t1, t3 );
|
||||||
|
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
// TODO: update rflags...
|
||||||
|
|
||||||
|
rtn->push( 4, t4 );
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
|
||||||
|
lifters_t::lifter_callback_t lifters_t::shlb =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 2 );
|
||||||
|
auto t2 = rtn->pop( 2 );
|
||||||
|
auto t3 = ir_builder->CreateIntCast( t1, ir_builder->getInt8Ty(), false );
|
||||||
|
auto t4 = ir_builder->CreateIntCast( t2, ir_builder->getInt8Ty(), false );
|
||||||
|
auto t5 = ir_builder->CreateShl( t3, t4 );
|
||||||
|
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
// TODO: update rflags...
|
||||||
|
|
||||||
|
rtn->push( 2, ir_builder->CreateIntCast( t5, ir_builder->getInt16Ty(), false ) );
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
} // namespace vm
|
@ -0,0 +1,38 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::shldq =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 8 );
|
||||||
|
auto t2 = rtn->pop( 8 );
|
||||||
|
auto t3 = rtn->pop( 2 );
|
||||||
|
|
||||||
|
// TODO: this is wrong - replace with more logic!
|
||||||
|
auto t4 = ir_builder->CreateShl( t1, ir_builder->CreateIntCast( t3, ir_builder->getInt64Ty(), false ) );
|
||||||
|
|
||||||
|
rtn->push( 8, t4 );
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
|
||||||
|
// TODO: update rflags...
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
|
||||||
|
lifters_t::lifter_callback_t lifters_t::shlddw =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 4 );
|
||||||
|
auto t2 = rtn->pop( 4 );
|
||||||
|
auto t3 = rtn->pop( 2 );
|
||||||
|
|
||||||
|
// TODO: this is wrong - replace with more logic!
|
||||||
|
auto t4 = ir_builder->CreateShl( t1, ir_builder->CreateIntCast( t3, ir_builder->getInt32Ty(), false ) );
|
||||||
|
|
||||||
|
rtn->push( 4, t4 );
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
|
||||||
|
// TODO: update rflags...
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
} // namespace vm
|
@ -0,0 +1,38 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::shrdq =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 8 );
|
||||||
|
auto t2 = rtn->pop( 8 );
|
||||||
|
auto t3 = rtn->pop( 2 );
|
||||||
|
|
||||||
|
// TODO: this is wrong - replace with more logic!
|
||||||
|
auto t4 = ir_builder->CreateLShr( t1, ir_builder->CreateIntCast( t3, ir_builder->getInt64Ty(), false ) );
|
||||||
|
|
||||||
|
rtn->push( 8, t4 );
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
|
||||||
|
// TODO: update rflags...
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
|
||||||
|
lifters_t::lifter_callback_t lifters_t::shrddw =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
auto t1 = rtn->pop( 4 );
|
||||||
|
auto t2 = rtn->pop( 4 );
|
||||||
|
auto t3 = rtn->pop( 2 );
|
||||||
|
|
||||||
|
// TODO: this is wrong - replace with more logic!
|
||||||
|
auto t4 = ir_builder->CreateLShr( t1, ir_builder->CreateIntCast( t3, ir_builder->getInt32Ty(), false ) );
|
||||||
|
|
||||||
|
rtn->push( 4, t4 );
|
||||||
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||||
|
|
||||||
|
// TODO: update rflags...
|
||||||
|
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||||
|
};
|
||||||
|
} // namespace vm
|
@ -0,0 +1,31 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::writecr3 =
|
||||||
|
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||||
|
llvm::IRBuilder<> *ir_builder ) {
|
||||||
|
llvm::Function *writecr3_intrin = nullptr;
|
||||||
|
if ( !( writecr3_intrin = rtn->llvm_module->getFunction( "writecr3" ) ) )
|
||||||
|
{
|
||||||
|
writecr3_intrin = llvm::Function::Create(
|
||||||
|
llvm::FunctionType::get( ir_builder->getVoidTy(), { ir_builder->getInt64Ty() }, false ),
|
||||||
|
llvm::GlobalValue::LinkageTypes::ExternalLinkage, "writecr3", *rtn->llvm_module );
|
||||||
|
|
||||||
|
auto entry_block = llvm::BasicBlock::Create( ir_builder->getContext(), "", writecr3_intrin );
|
||||||
|
auto ib = ir_builder->GetInsertBlock();
|
||||||
|
ir_builder->SetInsertPoint( entry_block );
|
||||||
|
|
||||||
|
std::string asm_str( "mov cr3, rcx; ret" );
|
||||||
|
auto intrin = llvm::InlineAsm::get(
|
||||||
|
llvm::FunctionType::get( ir_builder->getVoidTy(), false ), asm_str,
|
||||||
|
"", false, false, llvm::InlineAsm::AD_Intel );
|
||||||
|
|
||||||
|
ir_builder->CreateCall( intrin );
|
||||||
|
ir_builder->CreateRetVoid();
|
||||||
|
ir_builder->SetInsertPoint( ib );
|
||||||
|
}
|
||||||
|
auto t1 = rtn->pop( 8 );
|
||||||
|
ir_builder->CreateCall( writecr3_intrin, { t1 } );
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in new issue