#include "qvminspector.h" qvminspector_t::qvminspector_t( qwidget_t *parent ) : qmain_window_t( parent ), file_header( nullptr ), vmctx( nullptr ) { ui.setupUi( this ); ui.virt_instrs->setColumnWidth( 0, 100 ); ui.virt_instrs->setColumnWidth( 1, 125 ); ui.virt_instrs->setColumnWidth( 2, 250 ); ui.virt_instrs->setColumnWidth( 3, 200 ); connect( ui.action_open, &QAction::triggered, this, &qvminspector_t::on_open ); connect( ui.action_close, &QAction::triggered, this, &qvminspector_t::on_close ); } void qvminspector_t::on_close() { exit( 0 ); } void qvminspector_t::on_open() { if ( file_header && vmctx ) { free( file_header ); delete vmctx; } file_header = nullptr; image_base = 0u, vm_entry_rva = 0u, module_base = 0u; file_path = QFileDialog::getOpenFileName( this, tr( "open vmp2 file" ), std::filesystem::current_path().string().c_str(), tr( "vmp2 file (*.vmp2)" ) ); const auto &_file_path = file_path.toStdString(); if ( file_path.isEmpty() ) { dbg_msg( "invalid vmp2 file... no file selected..." ); return; } if ( !std::filesystem::exists( _file_path ) ) { dbg_msg( "vmp2 file does not exist..." ); return; } const auto file_size = std::filesystem::file_size( _file_path ); if ( !file_size ) { dbg_msg( "invalid vmp2 file size..." ); return; } qfile_t open_file( file_path ); file_header = reinterpret_cast< vmp2::v3::file_header * >( malloc( file_size ) ); dbg_msg( QString( "loading vmp2 file %1..." ).arg( file_path ) ); if ( !open_file.open( QIODevice::ReadOnly ) ) { dbg_msg( "failed to open vmp2 file..." ); return; } memcpy( file_header, open_file.readAll().data(), file_size ); if ( !init_data() ) { dbg_msg( "failed to init vmp2 file data..." ); return; } update_ui(); } void qvminspector_t::dbg_print( qstring_t dbg_output ) { ui.dbg_output_window->appendPlainText( dbg_output ); } void qvminspector_t::dbg_msg( qstring_t dbg_output ) { QMessageBox MsgBox; MsgBox.setText( dbg_output ); MsgBox.exec(); dbg_print( dbg_output ); } bool qvminspector_t::init_data() { if ( file_header->magic != VMP_MAGIC ) { dbg_msg( "invalid magic bytes for vmp2 file...\n" ); return false; } dbg_print( "valid magic bytes for vmp2 file...\n" ); if ( file_header->version != vmp2::version_t::v3 ) { dbg_msg( "invalid vmp2 file version... " "this vminspector is compiled for version 3...\n" ); return false; } vm_entry_rva = file_header->vm_entry_rva; image_base = file_header->image_base; module_base = reinterpret_cast< std::uintptr_t >( file_header ) + file_header->module_offset; vmctx = new vm::ctx_t( module_base, image_base, image_base, vm_entry_rva ); first_block = reinterpret_cast< vmp2::v3::code_block_t * >( reinterpret_cast< std::uintptr_t >( file_header ) + file_header->code_block_offset ); dbg_print( "> vm entry displayed below...\n" ); vm::util::print( vmctx->vm_entry ); return true; } void qvminspector_t::update_ui() { const auto end_code_blocks = reinterpret_cast< std::uintptr_t >( first_block ) + ( file_header->code_block_count * sizeof vmp2::v3::code_block_t ) + file_header->module_size + sizeof vmp2::v3::file_header; // for each code block insert their virtual instructions // into the virtual instruction tree... also put meta data about the code // block above the virtual instructions... if the code block has a JCC (with two branches) // then make a child repeating this for loop... for ( auto [ code_block, idx ] = std::tuple{ first_block, 0u }; idx < 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 ), ++idx) { auto blank_entry1 = new qtree_widget_item_t(), blank_entry2 = new qtree_widget_item_t(), meta_data_entry = new qtree_widget_item_t(); dbg_msg( QString( "> number of vinstrs = %1...\n" ).arg( code_block->vinstr_count ) ); // ui.virt_instrs->addTopLevelItem( blank_entry1 ); // meta_data_entry->setText() } }