diff --git a/src/qvm_inspector.cpp b/src/qvm_inspector.cpp index 3de0d22..45b73a2 100644 --- a/src/qvm_inspector.cpp +++ b/src/qvm_inspector.cpp @@ -180,5 +180,46 @@ bool qvm_inspector::serialize_vmp2( std::vector< rtn_data_t > &virt_rtns ) void qvm_inspector::update_virtual_instructions( std::uintptr_t rtn_addr, QTreeWidgetItem *parent ) { + auto _rtn = std::find_if( virt_rtns.begin(), virt_rtns.end(), + [ & ]( rtn_data_t &rtn ) -> bool { return rtn.rtn_rva == rtn_addr; } ); + if ( _rtn == virt_rtns.end() ) + return; + + for ( const auto &vinstr : _rtn->rtn_blks[ 0 ].vinstrs ) + { + const auto profile = vm::handler::get_profile( vinstr.mnemonic_t ); + auto virt_instr_entry = new QTreeWidgetItem(); + + // virtual instruction operand bytes... (column 2)... + QString operand_bytes; + operand_bytes.append( QString( "%1" ).arg( vinstr.opcode, 0, 16 ) ); + + // if virt instruction has an imm... grab its bytes... + if ( vinstr.operand.has_imm ) + { + operand_bytes.append( " - " ); + for ( auto _idx = 0u; _idx < vinstr.operand.imm.imm_size / 8; ++_idx ) + operand_bytes.append( QString( "%1 " ).arg( + reinterpret_cast< const std::uint8_t * >( &vinstr.operand.imm.u )[ _idx ], 0, 16 ) ); + } + + virt_instr_entry->setText( 1, operand_bytes ); + + // virtual instruction string, includes imm... (colume 3)... + QString decoded_instr( + QString( "%1" ).arg( profile ? profile->name : QString( "UNK(%1)" ).arg( vinstr.opcode, 0, 16 ) ) ); + + if ( vinstr.operand.has_imm ) // if there is a second operand (imm) put its value... + decoded_instr.append( QString( " %1" ).arg( vinstr.operand.imm.u, 0, 16 ) ); + + virt_instr_entry->setText( 2, decoded_instr ); + + // add comments to the virtual instruction... (colume 4)... + if ( vinstr.mnemonic_t == vm::handler::LREGQ || vinstr.mnemonic_t == vm::handler::SREGQ ) + virt_instr_entry->setText( + 3, QString( "; vreg%1" ).arg( vinstr.operand.imm.u ? ( vinstr.operand.imm.u / 8 ) : 0u ) ); + + ui.virt_instrs->addTopLevelItem( virt_instr_entry ); + } } diff --git a/src/qvm_virtual_routines.cpp b/src/qvm_virtual_routines.cpp index 4c3e8be..efab1d3 100644 --- a/src/qvm_virtual_routines.cpp +++ b/src/qvm_virtual_routines.cpp @@ -101,5 +101,5 @@ void qvm_virtual_routines::on_select() update_vm_enter( g_main_window->g_vm_ctx ); update_calc_jmp( g_main_window->g_vm_ctx ); update_vm_handlers( g_main_window->g_vm_ctx ); - g_main_window->update_virtual_instructions( g_main_window->img_base + entry_rva ); + g_main_window->update_virtual_instructions( entry_rva ); } \ No newline at end of file