parent
e846560010
commit
856fa1815d
@ -1 +1 @@
|
|||||||
Subproject commit 16aeb2d6d48c4822b89497ad660911eb0f5e54bd
|
Subproject commit 1f5fe9cd7b16ad2edd17ee8e13c672b3feeb9c08
|
@ -0,0 +1,54 @@
|
|||||||
|
#include <vm_lifters.hpp>
|
||||||
|
|
||||||
|
namespace vm
|
||||||
|
{
|
||||||
|
lifters_t::lifter_callback_t lifters_t::jmp = [ & ]( 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 ) {
|
||||||
|
assert( vm_code_block.jcc.has_jcc, "[!] fatal error in vmemu... virtual block ending with jmp marked as"
|
||||||
|
" has_jcc = false... debug time!\n" );
|
||||||
|
|
||||||
|
if ( vm_code_block.jcc.type == vm::instrs::jcc_type::branching )
|
||||||
|
{
|
||||||
|
auto rva = rtn->pop( 8 );
|
||||||
|
auto b1 = vm_code_block.jcc.block_addr[ 0 ] & ~std::numeric_limits< std::uint32_t >::max();
|
||||||
|
auto _const_b1 = llvm::ConstantInt::get( ir_builder->getInt64Ty(), b1 );
|
||||||
|
auto cmp = ir_builder->CreateCmp( llvm::CmpInst::ICMP_EQ, rva, _const_b1 );
|
||||||
|
|
||||||
|
// find the first branch basic block...
|
||||||
|
auto bb1 = std::find_if(
|
||||||
|
rtn->llvm_code_blocks.begin(), rtn->llvm_code_blocks.end(),
|
||||||
|
[ & ]( const std::pair< std::uintptr_t, llvm_basic_block_t * > &block_data ) -> bool {
|
||||||
|
return block_data.first == ( vm_code_block.jcc.block_addr[ 0 ] - vinstr.trace_data.regs.r13 );
|
||||||
|
} );
|
||||||
|
|
||||||
|
assert( bb1 != rtn->llvm_code_blocks.end(),
|
||||||
|
"[!] fatal error... unable to locate basic block for branching...\n" );
|
||||||
|
|
||||||
|
// find the second branch basic block...
|
||||||
|
auto bb2 = std::find_if(
|
||||||
|
rtn->llvm_code_blocks.begin(), rtn->llvm_code_blocks.end(),
|
||||||
|
[ & ]( const std::pair< std::uintptr_t, llvm_basic_block_t * > &block_data ) -> bool {
|
||||||
|
return block_data.first == ( vm_code_block.jcc.block_addr[ 1 ] - vinstr.trace_data.regs.r13 );
|
||||||
|
} );
|
||||||
|
|
||||||
|
assert( bb2 != rtn->llvm_code_blocks.end(),
|
||||||
|
"[!] fatal error... unable to locate basic block for branching...\n" );
|
||||||
|
|
||||||
|
ir_builder->CreateCondBr( cmp, bb1->second, bb2->second );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto rva = rtn->pop( 8 );
|
||||||
|
auto bb_data = std::find_if(
|
||||||
|
rtn->llvm_code_blocks.begin(), rtn->llvm_code_blocks.end(),
|
||||||
|
[ & ]( const std::pair< std::uintptr_t, llvm_basic_block_t * > &block_data ) -> bool {
|
||||||
|
return block_data.first == vm_code_block.jcc.block_addr[ 0 ] - vinstr.trace_data.regs.r13;
|
||||||
|
} );
|
||||||
|
|
||||||
|
assert( bb_data != rtn->llvm_code_blocks.end(), "[!] fatal error... unable to locate basic block...\n" );
|
||||||
|
ir_builder->CreateBr( bb_data->second );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in new issue