|
|
|
@ -1,29 +1,30 @@
|
|
|
|
|
#include "qvminspector.h"
|
|
|
|
|
|
|
|
|
|
qvminspector_t::qvminspector_t( qwidget_t *parent ) : qmain_window_t( parent ), file_header( nullptr ), vmctx( nullptr )
|
|
|
|
|
QVMInspector::QVMInspector( QWidget *parent ) : QMainWindow( parent ), FileHeader( nullptr ), vmctx( nullptr )
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi( this );
|
|
|
|
|
ui.virt_instrs->setColumnWidth( 0, 180 );
|
|
|
|
|
ui.virt_instrs->setColumnWidth( 1, 150 );
|
|
|
|
|
ui.virt_instrs->setColumnWidth( 2, 190 );
|
|
|
|
|
ui.virt_instrs->setColumnWidth( 3, 200 );
|
|
|
|
|
ui.virtual_machine_enters->setColumnWidth( 0, 180 );
|
|
|
|
|
|
|
|
|
|
connect( ui.action_open, &QAction::triggered, this, &qvminspector_t::on_open );
|
|
|
|
|
connect( ui.action_close, &QAction::triggered, this, &qvminspector_t::on_close );
|
|
|
|
|
connect( ui.action_open, &QAction::triggered, this, &QVMInspector::OnOpen );
|
|
|
|
|
connect( ui.action_close, &QAction::triggered, this, &QVMInspector::OnClose );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void qvminspector_t::on_close()
|
|
|
|
|
void QVMInspector::OnClose()
|
|
|
|
|
{
|
|
|
|
|
exit( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void qvminspector_t::on_open()
|
|
|
|
|
void QVMInspector::OnOpen()
|
|
|
|
|
{
|
|
|
|
|
if ( file_header )
|
|
|
|
|
free( file_header );
|
|
|
|
|
if ( FileHeader )
|
|
|
|
|
free( FileHeader );
|
|
|
|
|
|
|
|
|
|
file_header = nullptr;
|
|
|
|
|
image_base = 0u, vm_entry_rva = 0u, module_base = 0u;
|
|
|
|
|
FileHeader = nullptr;
|
|
|
|
|
ImgBase = 0u, ModuleBase = 0u;
|
|
|
|
|
|
|
|
|
|
file_path = QFileDialog::getOpenFileName(
|
|
|
|
|
this, tr( "open vmp2 file" ), std::filesystem::current_path().string().c_str(), tr( "vmp2 file (*.vmp2)" ) );
|
|
|
|
@ -32,13 +33,13 @@ void qvminspector_t::on_open()
|
|
|
|
|
|
|
|
|
|
if ( file_path.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
dbg_msg( "invalid vmp2 file... no file selected..." );
|
|
|
|
|
DbgMsg( "invalid vmp2 file... no file selected..." );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !std::filesystem::exists( _file_path ) )
|
|
|
|
|
{
|
|
|
|
|
dbg_msg( "vmp2 file does not exist..." );
|
|
|
|
|
DbgMsg( "vmp2 file does not exist..." );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -46,96 +47,112 @@ void qvminspector_t::on_open()
|
|
|
|
|
|
|
|
|
|
if ( !file_size )
|
|
|
|
|
{
|
|
|
|
|
dbg_msg( "invalid vmp2 file size..." );
|
|
|
|
|
DbgMsg( "invalid vmp2 file size..." );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qfile_t open_file( file_path );
|
|
|
|
|
file_header = reinterpret_cast< vmp2::v4::file_header * >( malloc( file_size ) );
|
|
|
|
|
QFile open_file( file_path );
|
|
|
|
|
FileHeader = reinterpret_cast< vmp2::v4::FileHeader * >( malloc( file_size ) );
|
|
|
|
|
|
|
|
|
|
if ( !open_file.open( QIODevice::ReadOnly ) )
|
|
|
|
|
{
|
|
|
|
|
dbg_msg( "failed to open vmp2 file..." );
|
|
|
|
|
DbgMsg( "failed to open vmp2 file..." );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy( file_header, open_file.readAll().data(), file_size );
|
|
|
|
|
memcpy( FileHeader, open_file.readAll().data(), file_size );
|
|
|
|
|
|
|
|
|
|
if ( !init_data() )
|
|
|
|
|
if ( !InitData() )
|
|
|
|
|
{
|
|
|
|
|
dbg_msg( "failed to init vmp2 file data..." );
|
|
|
|
|
DbgMsg( "failed to init vmp2 file data..." );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void qvminspector_t::dbg_print( qstring_t dbg_output )
|
|
|
|
|
void QVMInspector::DbgPrint( QString dbg_output )
|
|
|
|
|
{
|
|
|
|
|
ui.dbg_output_window->appendPlainText( dbg_output );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void qvminspector_t::dbg_msg( qstring_t dbg_output )
|
|
|
|
|
void QVMInspector::DbgMsg( QString dbg_output )
|
|
|
|
|
{
|
|
|
|
|
qmsg_box_t msg_box;
|
|
|
|
|
QMessageBox msg_box;
|
|
|
|
|
msg_box.setText( dbg_output );
|
|
|
|
|
msg_box.exec();
|
|
|
|
|
dbg_print( dbg_output );
|
|
|
|
|
DbgPrint( dbg_output );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool qvminspector_t::init_data()
|
|
|
|
|
bool QVMInspector::InitData()
|
|
|
|
|
{
|
|
|
|
|
if ( file_header->magic != VMP_MAGIC )
|
|
|
|
|
if ( FileHeader->magic != VMP_MAGIC )
|
|
|
|
|
{
|
|
|
|
|
dbg_msg( "invalid magic bytes for vmp2 file..." );
|
|
|
|
|
DbgMsg( "invalid magic bytes for vmp2 file..." );
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbg_print( "valid magic bytes for vmp2 file..." );
|
|
|
|
|
DbgPrint( "valid magic bytes for vmp2 file..." );
|
|
|
|
|
|
|
|
|
|
if ( file_header->version != vmp2::version_t::v4 )
|
|
|
|
|
if ( FileHeader->version != vmp2::version_t::v4 )
|
|
|
|
|
{
|
|
|
|
|
dbg_msg( "invalid vmp2 file version... "
|
|
|
|
|
DbgMsg( "invalid vmp2 file version... "
|
|
|
|
|
"this vminspector is compiled for version 4...\n" );
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vm_entry_rva = file_header->vm_entry_rva;
|
|
|
|
|
image_base = file_header->image_base;
|
|
|
|
|
image_size = file_header->module_size;
|
|
|
|
|
ImgBase = FileHeader->ImgBase;
|
|
|
|
|
ImgSize = FileHeader->module_size;
|
|
|
|
|
ModuleBase = reinterpret_cast< std::uintptr_t >( FileHeader ) + FileHeader->module_offset;
|
|
|
|
|
|
|
|
|
|
module_base = reinterpret_cast< std::uintptr_t >( file_header ) + file_header->module_offset;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void qvminspector_t::add_branch_children( qtree_widget_item_t *item, std::uintptr_t branch_addr )
|
|
|
|
|
{
|
|
|
|
|
if ( !SerializeVmp2( VirtRtns ) )
|
|
|
|
|
{
|
|
|
|
|
DbgMsg( "failed to serialize vmp2 file format...\n" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateUI();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void qvminspector_t::update_ui()
|
|
|
|
|
void QVMInspector::UpdateUI()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ui.virtual_machine_enters->clear();
|
|
|
|
|
for ( auto &[ rtn_rva, rtn_blks ] : VirtRtns )
|
|
|
|
|
{
|
|
|
|
|
auto new_item = new QTreeWidgetItem();
|
|
|
|
|
new_item->setText( 0, QString( "rtn_%1" ).arg( rtn_rva + FileHeader->ImgBase, 0, 16 ) );
|
|
|
|
|
new_item->setText( 1, QString( "%1" ).arg( rtn_rva + FileHeader->ImgBase, 0, 16 ) );
|
|
|
|
|
new_item->setText( 2, QString( "%1" ).arg( rtn_blks.size() ) );
|
|
|
|
|
|
|
|
|
|
std::for_each( rtn_blks.begin(), rtn_blks.end(), [ & ]( vm::instrs::code_block_t &code_blk ) {
|
|
|
|
|
auto new_child = new QTreeWidgetItem();
|
|
|
|
|
new_child->setText( 0, QString( "blk_%1" ).arg( code_blk.vip_begin, 0, 16 ) );
|
|
|
|
|
new_child->setText( 1, QString( "%1" ).arg( code_blk.vip_begin, 0, 16 ) );
|
|
|
|
|
new_child->setText( 2, QString( "%1" ).arg( code_blk.vinstrs.size() ) );
|
|
|
|
|
new_item->addChild( new_child );
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
ui.virtual_machine_enters->addTopLevelItem( new_item );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool qvminspector_t::serialize_vmp2( std::vector< rtn_data_t > &virt_rtns, std::vector< std::uint8_t > &vmp2file )
|
|
|
|
|
bool QVMInspector::SerializeVmp2( std::vector< rtn_data_t > &VirtRtns )
|
|
|
|
|
{
|
|
|
|
|
const auto file_header = reinterpret_cast< vmp2::v4::file_header * >( vmp2file.data() );
|
|
|
|
|
|
|
|
|
|
if ( file_header->version != vmp2::version_t::v4 )
|
|
|
|
|
if ( FileHeader->version != vmp2::version_t::v4 )
|
|
|
|
|
{
|
|
|
|
|
std::printf( "[!] invalid vmp2 file version... this build uses v3...\n" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto first_rtn = reinterpret_cast< vmp2::v4::rtn_t * >( reinterpret_cast< std::uintptr_t >( file_header ) +
|
|
|
|
|
file_header->rtn_offset );
|
|
|
|
|
auto first_rtn = reinterpret_cast< vmp2::v4::rtn_t * >( reinterpret_cast< std::uintptr_t >( FileHeader ) +
|
|
|
|
|
FileHeader->rtn_offset );
|
|
|
|
|
|
|
|
|
|
for ( auto [ rtn_block, rtn_idx ] = std::pair{ first_rtn, 0ull }; rtn_idx < file_header->rtn_count;
|
|
|
|
|
for ( auto [ rtn_block, rtn_idx ] = std::pair{ first_rtn, 0ull }; rtn_idx < FileHeader->rtn_count;
|
|
|
|
|
++rtn_idx, rtn_block = reinterpret_cast< vmp2::v4::rtn_t * >(
|
|
|
|
|
reinterpret_cast< std::uintptr_t >( rtn_block ) + rtn_block->size ) )
|
|
|
|
|
{
|
|
|
|
|
virt_rtns.push_back( { rtn_block->vm_enter_offset, {} } );
|
|
|
|
|
VirtRtns.push_back( { rtn_block->vm_enter_offset, {} } );
|
|
|
|
|
for ( auto [ code_block, block_idx ] = std::pair{ &rtn_block->code_blocks[ 0 ], 0ull };
|
|
|
|
|
block_idx < rtn_block->code_block_count;
|
|
|
|
|
++block_idx, code_block = reinterpret_cast< vmp2::v4::code_block_t * >(
|
|
|
|
@ -155,7 +172,7 @@ bool qvminspector_t::serialize_vmp2( std::vector< rtn_data_t > &virt_rtns, std::
|
|
|
|
|
for ( auto idx = 0u; idx < code_block->vinstr_count; ++idx )
|
|
|
|
|
_code_block.vinstrs.push_back( block_vinstrs[ idx ] );
|
|
|
|
|
|
|
|
|
|
virt_rtns.back().rtn_blks.push_back( _code_block );
|
|
|
|
|
VirtRtns.back().rtn_blks.push_back( _code_block );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|