|
|
|
@ -4,17 +4,19 @@ namespace vm
|
|
|
|
|
{
|
|
|
|
|
compiler_t::compiler_t( vm::ctx_t *vmctx ) : vmctx( vmctx )
|
|
|
|
|
{
|
|
|
|
|
if ( !parse_t::get_instance()->for_each( [ & ]( _vinstr_meta *vinstr ) -> bool {
|
|
|
|
|
std::printf( "> vinstr name = %s, has imm = %d, imm = 0x%p\n", vinstr->name.c_str(), vinstr->has_imm,
|
|
|
|
|
vinstr->imm );
|
|
|
|
|
|
|
|
|
|
for ( auto &vm_handler : vmctx->vm_handlers )
|
|
|
|
|
if ( vm_handler.profile && vm_handler.profile->name == vinstr->name )
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
std::printf( "[!] this vm protected file does not have the vm handler for: %s...\n",
|
|
|
|
|
vinstr->name.c_str() );
|
|
|
|
|
|
|
|
|
|
if ( !parse_t::get_instance()->for_each( [ & ]( _vlabel_meta *label_data ) -> bool {
|
|
|
|
|
for ( const auto &vinstr : label_data->vinstrs )
|
|
|
|
|
{
|
|
|
|
|
std::printf( "> vinstr name = %s, has imm = %d, imm = 0x%p\n", vinstr.name.c_str(), vinstr.has_imm,
|
|
|
|
|
vinstr.imm );
|
|
|
|
|
|
|
|
|
|
for ( auto &vm_handler : vmctx->vm_handlers )
|
|
|
|
|
if ( vm_handler.profile && vm_handler.profile->name == vinstr.name )
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
std::printf( "[!] this vm protected file does not have the vm handler for: %s...\n",
|
|
|
|
|
vinstr.name.c_str() );
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
} ) )
|
|
|
|
|
{
|
|
|
|
@ -41,25 +43,29 @@ namespace vm
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair< bool, std::vector< vinstr_data > * > compiler_t::encode()
|
|
|
|
|
std::vector< vlabel_data > *compiler_t::encode()
|
|
|
|
|
{
|
|
|
|
|
parse_t::get_instance()->for_each( [ & ]( _vinstr_meta *vinstr ) -> bool {
|
|
|
|
|
for ( auto itr = vmctx->vm_handlers.begin(); itr != vmctx->vm_handlers.end(); ++itr )
|
|
|
|
|
parse_t::get_instance()->for_each( [ & ]( _vlabel_meta *label_data ) -> bool {
|
|
|
|
|
for ( const auto &vinstr : label_data->vinstrs )
|
|
|
|
|
{
|
|
|
|
|
if ( itr->profile && itr->profile->name == vinstr->name )
|
|
|
|
|
for ( auto itr = vmctx->vm_handlers.begin(); itr != vmctx->vm_handlers.end(); ++itr )
|
|
|
|
|
{
|
|
|
|
|
vinstrs.push_back(
|
|
|
|
|
{ ( std::uint8_t )( itr - vmctx->vm_handlers.begin() ), vinstr->imm, itr->profile->imm_size } );
|
|
|
|
|
break;
|
|
|
|
|
vinstrs.push_back( { label_data->label_name } );
|
|
|
|
|
if ( itr->profile && itr->profile->name == vinstr.name )
|
|
|
|
|
{
|
|
|
|
|
vinstrs.back().vinstrs.push_back( { ( std::uint8_t )( itr - vmctx->vm_handlers.begin() ),
|
|
|
|
|
vinstr.imm, itr->profile->imm_size } );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
return { true, &vinstrs };
|
|
|
|
|
return &vinstrs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair< std::uint64_t, std::vector< std::uint8_t > * > compiler_t::encrypt()
|
|
|
|
|
std::vector< compiled_label_data > compiler_t::encrypt()
|
|
|
|
|
{
|
|
|
|
|
const auto end_of_module = vmctx->image_size + vmctx->image_base;
|
|
|
|
|
|
|
|
|
|