|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
#include "QVMInspector.h"
|
|
|
|
|
#include "qvm_inspector.h"
|
|
|
|
|
|
|
|
|
|
QVMInspector::QVMInspector( QWidget *parent ) : QMainWindow( parent ), FileHeader( nullptr ), g_vm_ctx( nullptr )
|
|
|
|
|
qvm_inspector::qvm_inspector( QWidget *parent ) : QMainWindow( parent ), file_header( nullptr ), g_vm_ctx( nullptr )
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi( this );
|
|
|
|
|
ui.virt_instrs->setColumnWidth( 0, 180 );
|
|
|
|
@ -9,120 +9,118 @@ QVMInspector::QVMInspector( QWidget *parent ) : QMainWindow( parent ), FileHeade
|
|
|
|
|
ui.virt_instrs->setColumnWidth( 3, 200 );
|
|
|
|
|
ui.virtual_machine_enters->setColumnWidth( 0, 180 );
|
|
|
|
|
|
|
|
|
|
connect( ui.action_open, &QAction::triggered, this, &QVMInspector::OnOpen );
|
|
|
|
|
connect( ui.action_close, &QAction::triggered, this, &QVMInspector::OnClose );
|
|
|
|
|
connect( ui.action_open, &QAction::triggered, this, &qvm_inspector::on_open );
|
|
|
|
|
connect( ui.action_close, &QAction::triggered, this, &qvm_inspector::on_close );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QVMInspector::OnClose()
|
|
|
|
|
void qvm_inspector::on_close()
|
|
|
|
|
{
|
|
|
|
|
exit( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QVMInspector::OnOpen()
|
|
|
|
|
void qvm_inspector::on_open()
|
|
|
|
|
{
|
|
|
|
|
if ( FileHeader )
|
|
|
|
|
free( FileHeader );
|
|
|
|
|
if ( file_header )
|
|
|
|
|
free( file_header );
|
|
|
|
|
|
|
|
|
|
FileHeader = nullptr;
|
|
|
|
|
ImgBase = 0u, ModuleBase = 0u;
|
|
|
|
|
file_header = nullptr;
|
|
|
|
|
img_base = 0u, module_base = 0u;
|
|
|
|
|
|
|
|
|
|
file_path = QFileDialog::getOpenFileName(
|
|
|
|
|
auto 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() )
|
|
|
|
|
{
|
|
|
|
|
DbgMsg( "invalid vmp2 file... no file selected..." );
|
|
|
|
|
dbg_msg( "invalid vmp2 file... no file selected..." );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !std::filesystem::exists( _file_path ) )
|
|
|
|
|
if ( !std::filesystem::exists( file_path.toStdString() ) )
|
|
|
|
|
{
|
|
|
|
|
DbgMsg( "vmp2 file does not exist..." );
|
|
|
|
|
dbg_msg( "vmp2 file does not exist..." );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto file_size = std::filesystem::file_size( _file_path );
|
|
|
|
|
const auto file_size = std::filesystem::file_size( file_path.toStdString() );
|
|
|
|
|
|
|
|
|
|
if ( !file_size )
|
|
|
|
|
{
|
|
|
|
|
DbgMsg( "invalid vmp2 file size..." );
|
|
|
|
|
dbg_msg( "invalid vmp2 file size..." );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFile open_file( file_path );
|
|
|
|
|
FileHeader = reinterpret_cast< vmp2::v4::FileHeader * >( malloc( file_size ) );
|
|
|
|
|
file_header = reinterpret_cast< vmp2::v4::file_header * >( malloc( file_size ) );
|
|
|
|
|
|
|
|
|
|
if ( !open_file.open( QIODevice::ReadOnly ) )
|
|
|
|
|
{
|
|
|
|
|
DbgMsg( "failed to open vmp2 file..." );
|
|
|
|
|
dbg_msg( "failed to open vmp2 file..." );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy( FileHeader, open_file.readAll().data(), file_size );
|
|
|
|
|
memcpy( file_header, open_file.readAll().data(), file_size );
|
|
|
|
|
|
|
|
|
|
if ( !InitData() )
|
|
|
|
|
if ( !init_data() )
|
|
|
|
|
{
|
|
|
|
|
DbgMsg( "failed to init vmp2 file data..." );
|
|
|
|
|
dbg_msg( "failed to init vmp2 file data..." );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QVMInspector::DbgPrint( QString dbg_output )
|
|
|
|
|
void qvm_inspector::dbg_print( QString dbg_output )
|
|
|
|
|
{
|
|
|
|
|
ui.dbg_output_window->appendPlainText( dbg_output );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QVMInspector::DbgMsg( QString dbg_output )
|
|
|
|
|
void qvm_inspector::dbg_msg( QString dbg_output )
|
|
|
|
|
{
|
|
|
|
|
QMessageBox msg_box;
|
|
|
|
|
msg_box.setText( dbg_output );
|
|
|
|
|
msg_box.exec();
|
|
|
|
|
DbgPrint( dbg_output );
|
|
|
|
|
dbg_print( dbg_output );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QVMInspector::InitData()
|
|
|
|
|
bool qvm_inspector::init_data()
|
|
|
|
|
{
|
|
|
|
|
if ( FileHeader->magic != VMP_MAGIC )
|
|
|
|
|
if ( file_header->magic != VMP_MAGIC )
|
|
|
|
|
{
|
|
|
|
|
DbgMsg( "invalid magic bytes for vmp2 file..." );
|
|
|
|
|
dbg_msg( "invalid magic bytes for vmp2 file..." );
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DbgPrint( "valid magic bytes for vmp2 file..." );
|
|
|
|
|
dbg_print( "valid magic bytes for vmp2 file..." );
|
|
|
|
|
|
|
|
|
|
if ( FileHeader->version != vmp2::version_t::v4 )
|
|
|
|
|
if ( file_header->version != vmp2::version_t::v4 )
|
|
|
|
|
{
|
|
|
|
|
DbgMsg( "invalid vmp2 file version... "
|
|
|
|
|
"this vminspector is compiled for version 4...\n" );
|
|
|
|
|
dbg_msg( "invalid vmp2 file version... "
|
|
|
|
|
"this vminspector is compiled for version 4...\n" );
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImgBase = FileHeader->ImgBase;
|
|
|
|
|
ImgSize = FileHeader->module_size;
|
|
|
|
|
ModuleBase = reinterpret_cast< std::uintptr_t >( FileHeader ) + FileHeader->module_offset;
|
|
|
|
|
img_base = file_header->image_base;
|
|
|
|
|
img_size = file_header->module_size;
|
|
|
|
|
module_base = reinterpret_cast< std::uintptr_t >( file_header ) + file_header->module_offset;
|
|
|
|
|
|
|
|
|
|
if ( !SerializeVmp2( VirtRtns ) )
|
|
|
|
|
if ( !serialize_vmp2( virt_rtns ) )
|
|
|
|
|
{
|
|
|
|
|
DbgMsg( "failed to serialize vmp2 file format...\n" );
|
|
|
|
|
dbg_msg( "failed to serialize vmp2 file format...\n" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateUI();
|
|
|
|
|
update_ui();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QVMInspector::UpdateUI()
|
|
|
|
|
void qvm_inspector::update_ui()
|
|
|
|
|
{
|
|
|
|
|
ui.virtual_machine_enters->clear();
|
|
|
|
|
for ( auto &[ rtn_rva, rtn_blks ] : VirtRtns )
|
|
|
|
|
for ( auto &[ rtn_rva, rtn_blks ] : virt_rtns )
|
|
|
|
|
{
|
|
|
|
|
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( 0, QString( "rtn_%1" ).arg( rtn_rva + file_header->image_base, 0, 16 ) );
|
|
|
|
|
new_item->setText( 1, QString( "%1" ).arg( rtn_rva + file_header->image_base, 0, 16 ) );
|
|
|
|
|
new_item->setText( 2, QString( "%1" ).arg( rtn_blks.size() ) );
|
|
|
|
|
new_item->setData( 0, Qt::UserRole, QVariant( rtn_rva ) );
|
|
|
|
|
|
|
|
|
@ -138,22 +136,22 @@ void QVMInspector::UpdateUI()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QVMInspector::SerializeVmp2( std::vector< rtn_data_t > &VirtRtns )
|
|
|
|
|
bool qvm_inspector::serialize_vmp2( std::vector< rtn_data_t > &virt_rtns )
|
|
|
|
|
{
|
|
|
|
|
if ( FileHeader->version != vmp2::version_t::v4 )
|
|
|
|
|
if ( file_header->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 >( FileHeader ) +
|
|
|
|
|
FileHeader->rtn_offset );
|
|
|
|
|
auto first_rtn = reinterpret_cast< vmp2::v4::rtn_t * >( reinterpret_cast< std::uintptr_t >( file_header ) +
|
|
|
|
|
file_header->rtn_offset );
|
|
|
|
|
|
|
|
|
|
for ( auto [ rtn_block, rtn_idx ] = std::pair{ first_rtn, 0ull }; rtn_idx < FileHeader->rtn_count;
|
|
|
|
|
for ( auto [ rtn_block, rtn_idx ] = std::pair{ first_rtn, 0ull }; rtn_idx < file_header->rtn_count;
|
|
|
|
|
++rtn_idx, rtn_block = reinterpret_cast< vmp2::v4::rtn_t * >(
|
|
|
|
|
reinterpret_cast< std::uintptr_t >( rtn_block ) + rtn_block->size ) )
|
|
|
|
|
{
|
|
|
|
|
VirtRtns.push_back( { rtn_block->vm_enter_offset, {} } );
|
|
|
|
|
virt_rtns.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 * >(
|
|
|
|
@ -173,9 +171,14 @@ bool QVMInspector::SerializeVmp2( std::vector< rtn_data_t > &VirtRtns )
|
|
|
|
|
for ( auto idx = 0u; idx < code_block->vinstr_count; ++idx )
|
|
|
|
|
_code_block.vinstrs.push_back( block_vinstrs[ idx ] );
|
|
|
|
|
|
|
|
|
|
VirtRtns.back().rtn_blks.push_back( _code_block );
|
|
|
|
|
virt_rtns.back().rtn_blks.push_back( _code_block );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void qvm_inspector::update_virtual_instructions( std::uintptr_t rtn_addr, QTreeWidgetItem *parent )
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|