From 11d7421e3eff4140bfc5c0b8deb4be9444ed6b6c Mon Sep 17 00:00:00 2001 From: _xeroxz Date: Fri, 11 Jun 2021 01:01:52 -0700 Subject: [PATCH] fixed an issue with optimizing and dumping... --- src/main.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6f3310f..624393c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -187,17 +187,25 @@ int __cdecl main( int argc, const char *argv[] ) if ( parser.exists( "devirt" ) ) { - vtil::basic_block *rtn = nullptr; + vtil::basic_block *rtn = nullptr, *first = nullptr; for ( auto [ code_block, code_block_num ] = std::tuple{ first_block, 0u }; code_block_num < file_header->code_block_count; code_block = reinterpret_cast< vmp2::v3::code_block_t * >( reinterpret_cast< std::uintptr_t >( code_block ) + code_block->next_block_offset ), ++code_block_num ) { - rtn = rtn ? rtn->fork( - ABS_TO_IMG( code_block->vip_begin, file_header->module_base, file_header->image_base ) ) - : vtil::basic_block::begin( - ABS_TO_IMG( code_block->vip_begin, file_header->module_base, file_header->image_base ) ); + if ( !rtn ) + { + rtn = vtil::basic_block::begin( + ABS_TO_IMG( code_block->vip_begin, file_header->module_base, file_header->image_base ) ); + } + else + { + first = rtn; + + rtn = + rtn->fork( ABS_TO_IMG( code_block->vip_begin, file_header->module_base, file_header->image_base ) ); + } for ( auto idx = 0u; idx < code_block->vinstr_count; ++idx ) { @@ -235,8 +243,8 @@ int __cdecl main( int argc, const char *argv[] ) } } - vtil::optimizer::apply_all( rtn ); - vtil::debug::dump( rtn ); + vtil::optimizer::apply_all( first ); + vtil::debug::dump( first ); return {}; }