From 2a24bfc125b2a216e10174c6046949171a410d56 Mon Sep 17 00:00:00 2001 From: _xeroxz Date: Sun, 8 Aug 2021 23:48:04 -0700 Subject: [PATCH] added some more lifters... --- CMakeLists.txt | 2 ++ include/vm_lifters.hpp | 8 ++++++-- src/lifters/lconst.cpp | 6 ++++++ src/lifters/lflags.cpp | 11 +++++++++++ src/lifters/read.cpp | 11 ++++++++++- src/lifters/sflags.cpp | 0 src/vmp_rtn.cpp | 2 ++ 7 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/lifters/lflags.cpp create mode 100644 src/lifters/sflags.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 21c35b2..f0c3847 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,11 +44,13 @@ list(APPEND vmdevirt_SOURCES "src/lifters/div.cpp" "src/lifters/jmp.cpp" "src/lifters/lconst.cpp" + "src/lifters/lflags.cpp" "src/lifters/lreg.cpp" "src/lifters/mul.cpp" "src/lifters/nand.cpp" "src/lifters/pushvsp.cpp" "src/lifters/read.cpp" + "src/lifters/sflags.cpp" "src/lifters/shl.cpp" "src/lifters/shr.cpp" "src/lifters/sreg.cpp" diff --git a/include/vm_lifters.hpp b/include/vm_lifters.hpp index fedbd35..289d274 100644 --- a/include/vm_lifters.hpp +++ b/include/vm_lifters.hpp @@ -30,16 +30,17 @@ namespace vm std::function< void( vm::vmp_rtn_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr, llvm::IRBuilder<> *ir_builder ) >; - static lifter_callback_t lconstq, lconstdwsxq, lconstwsxq, lconstbzxw, lconstbsxq, lconstdw; + static lifter_callback_t lconstq, lconstdwsxq, lconstwsxq, lconstbzxw, lconstbsxq, lconstwsxdw, lconstdw; static lifter_callback_t addq, adddw, addw; static lifter_callback_t sregq, sregdw; static lifter_callback_t lregq, lregdw; static lifter_callback_t pushvsp; - static lifter_callback_t readq; + static lifter_callback_t readq, readdw; static lifter_callback_t nandq, nanddw; static lifter_callback_t shrq; static lifter_callback_t jmp; + static lifter_callback_t lflagsq; std::map< vm::handler::mnemonic_t, lifter_callback_t * > lifters = { { vm::handler::LCONSTQ, &lconstq }, { vm::handler::LCONSTDW, &lconstdw }, @@ -47,6 +48,7 @@ namespace vm { vm::handler::LCONSTWSXQ, &lconstwsxq }, { vm::handler::LCONSTBZXW, &lconstbzxw }, { vm::handler::LCONSTBSXQ, &lconstbsxq }, + { vm::handler::LCONSTWSXDW, &lconstwsxdw }, { vm::handler::ADDQ, &addq }, { vm::handler::ADDDW, &adddw }, { vm::handler::ADDW, &addw }, @@ -57,8 +59,10 @@ namespace vm { vm::handler::LREGQ, &lregq }, { vm::handler::LREGDW, &lregdw }, { vm::handler::READQ, &readq }, + { vm::handler::READDW, &readdw }, { vm::handler::NANDQ, &nandq }, { vm::handler::NANDDW, &nanddw }, + { vm::handler::LFLAGSQ, &lflagsq }, { vm::handler::JMP, &jmp } }; static vm::llvm_value_t *add_flags( vm::vmp_rtn_t *rtn, std::uint8_t byte_size, vm::llvm_value_t *lhs, diff --git a/src/lifters/lconst.cpp b/src/lifters/lconst.cpp index 8617061..e6a8815 100644 --- a/src/lifters/lconst.cpp +++ b/src/lifters/lconst.cpp @@ -32,6 +32,12 @@ namespace vm rtn->push( 4, llvm::ConstantInt::get( ir_builder->getInt32Ty(), vinstr.operand.imm.u ) ); }; + lifters_t::lifter_callback_t lifters_t::lconstwsxdw = + [ & ]( vm::vmp_rtn_t *rtn, const vm::instrs::code_block_t &vm_code_block, + const vm::instrs::virt_instr_t &vinstr, llvm::IRBuilder<> *ir_builder ) { + rtn->push( 4, llvm::ConstantInt::get( ir_builder->getInt32Ty(), vinstr.operand.imm.u ) ); + }; + lifters_t::lifter_callback_t lifters_t::lconstbzxw = [ & ]( vm::vmp_rtn_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr, llvm::IRBuilder<> *ir_builder ) { diff --git a/src/lifters/lflags.cpp b/src/lifters/lflags.cpp new file mode 100644 index 0000000..576ee8b --- /dev/null +++ b/src/lifters/lflags.cpp @@ -0,0 +1,11 @@ +#include + +namespace vm +{ + lifters_t::lifter_callback_t lifters_t::lflagsq = + [ & ]( vm::vmp_rtn_t *rtn, const vm::instrs::code_block_t &vm_code_block, + const vm::instrs::virt_instr_t &vinstr, llvm::IRBuilder<> *ir_builder ) { + auto flags = rtn->pop( 8 ); + ir_builder->CreateStore( flags, rtn->flags ); + }; +} \ No newline at end of file diff --git a/src/lifters/read.cpp b/src/lifters/read.cpp index bbee6f9..011fe81 100644 --- a/src/lifters/read.cpp +++ b/src/lifters/read.cpp @@ -10,4 +10,13 @@ namespace vm auto t3 = ir_builder->CreateLoad( ir_builder->getInt64Ty(), t2 ); rtn->push( 8, t3 ); }; -} \ No newline at end of file + + lifters_t::lifter_callback_t lifters_t::readdw = + [ & ]( vm::vmp_rtn_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 = ir_builder->CreateIntToPtr( t1, llvm::PointerType::get( ir_builder->getInt32Ty(), 0ull ) ); + auto t3 = ir_builder->CreateLoad( ir_builder->getInt32Ty(), t2 ); + rtn->push( 4, t3 ); + }; +} // namespace vm \ No newline at end of file diff --git a/src/lifters/sflags.cpp b/src/lifters/sflags.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/vmp_rtn.cpp b/src/vmp_rtn.cpp index 17bf48b..78ac013 100644 --- a/src/vmp_rtn.cpp +++ b/src/vmp_rtn.cpp @@ -254,6 +254,8 @@ namespace vm for ( auto idx = 0u; idx < code_blocks.size(); ++idx ) { + ir_builder->SetInsertPoint( llvm_code_blocks[ idx ].second ); + for ( auto &vinstr : vmp2_code_blocks[ idx ].vinstrs ) { if ( !lifters->lift( this, vmp2_code_blocks[ idx ], vinstr, ir_builder.get() ) )