You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vmprofiler-cli/src/main.cpp

73 lines
2.7 KiB

#include <Windows.h>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <ZydisExportConfig.h>
#include <cli-parser.hpp>
#include <vmp2.hpp>
#include <vmprofiler.hpp>
#include <xtils.hpp>
int __cdecl main( int argc, const char *argv[] )
{
argparse::argument_parser_t parser( "vmprofiler-cli", "virtual instruction pseudo code generator" );
parser.add_argument()
.names( { "--bin", "--vmpbin" } )
.description( "unpacked binary protected with VMProtect 2" )
.required( true );
parser.add_argument()
.names( { "--vmentry", "--entry" } )
.description( "rva to push prior to a vm_entry" )
.required( true );
parser.add_argument().name( "--showhandlers" ).description( "show all vm handlers..." );
parser.add_argument().name( "--vmp2file" ).description( "path to .vmp2 file..." );
parser.add_argument().name( "--showblockinfo" ).description( "provide a block address to view its information..." );
parser.add_argument()
.name( "--showblockinstrs" )
.description( "show the virtual instructions of a specific code block..." );
parser.add_argument().name( "--showallblocks" ).description( "shows all information for all code blocks..." );
parser.enable_help();
auto err = parser.parse( argc, argv );
if ( err )
{
std::cout << err << std::endl;
return -1;
}
if ( parser.exists( "help" ) )
{
parser.print_help();
return 0;
}
const auto module_base = reinterpret_cast< std::uintptr_t >(
LoadLibraryExA( parser.get< std::string >( "bin" ).c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES ) );
const auto vm_entry_rva = std::strtoull( parser.get< std::string >( "vmentry" ).c_str(), nullptr, 16 );
const auto image_base = xtils::um_t::get_instance()->image_base( parser.get< std::string >( "bin" ).c_str() );
const auto image_size = NT_HEADER( module_base )->OptionalHeader.SizeOfImage;
std::printf( "> module base = 0x%p, image base = 0x%p, image size = 0x%p\n", module_base, image_base, image_size );
vm::ctx_t vmctx( module_base, image_base, image_size, vm_entry_rva );
if ( !vmctx.init() )
{
std::printf( "[!] failed to init vm::ctx_t... make sure all cli arguments are correct!\n" );
return -1;
}
std::puts( "======================== [vm entry] ========================\n" );
vm::util::print( vmctx.vm_entry );
std::puts( "======================== [calc jmp] ========================\n" );
vm::util::print( vmctx.calc_jmp );
std::puts( "============================================================\n" );
std::printf( "> vip advancement = %s\n", vmctx.exec_type == vmp2::exec_type_t::forward ? "forward" : "backward" );
}