|
|
@ -1,4 +1,7 @@
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
#include <cli-parser.hpp>
|
|
|
|
|
|
|
|
#include <vmprofiler.hpp>
|
|
|
|
|
|
|
|
#include <xtils.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#include "llvm/IR/BasicBlock.h"
|
|
|
|
#include "llvm/IR/BasicBlock.h"
|
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
@ -16,9 +19,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
int main( int argc, const char *argv[] )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// test for now...
|
|
|
|
argparse::argument_parser_t parser( "vmdevirt", "virtual instruction pseudo code generator" );
|
|
|
|
|
|
|
|
parser.add_argument().name( "--vmp2file" ).required( true ).description( "path to .vmp2 file..." );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector< std::uint8_t > vmp2file;
|
|
|
|
|
|
|
|
const auto umtils = xtils::um_t::get_instance();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !umtils->open_binary_file( parser.get< std::string >( "vmp2file" ), vmp2file ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::printf( "[!] failed to open vmp2 file...\n" );
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto file_header = reinterpret_cast< vmp2::v3::file_header * >( vmp2file.data() );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( file_header->version != vmp2::version_t::v3 )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::printf( "[!] invalid vmp2 file version... this build uses v3...\n" );
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto first_block = reinterpret_cast< vmp2::v3::code_block_t * >( reinterpret_cast< std::uintptr_t >( file_header ) +
|
|
|
|
|
|
|
|
file_header->code_block_offset );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ( auto [ code_block, code_block_num ] = std::tuple{ first_block, 0u };
|
|
|
|
|
|
|
|
code_block_num < 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 ),
|
|
|
|
|
|
|
|
++code_block_num )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::printf( "[code block #%d] begin = 0x%p, virtual instruction count = %d\n", code_block_num,
|
|
|
|
|
|
|
|
ABS_TO_IMG( code_block->vip_begin, file_header->module_base, file_header->image_base ),
|
|
|
|
|
|
|
|
code_block->vinstr_count );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( code_block->jcc.has_jcc )
|
|
|
|
|
|
|
|
std::printf(
|
|
|
|
|
|
|
|
"\tcode block branches to 0x%p and 0x%p\n",
|
|
|
|
|
|
|
|
ABS_TO_IMG( code_block->jcc.block_addr[ 0 ], file_header->module_base, file_header->image_base ),
|
|
|
|
|
|
|
|
ABS_TO_IMG( code_block->jcc.block_addr[ 1 ], file_header->module_base, file_header->image_base ) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LLVMContext llvm_ctx;
|
|
|
|
LLVMContext llvm_ctx;
|
|
|
|
Module llvm_module( "VMProtect 2 Static Devirtualizer", llvm_ctx );
|
|
|
|
Module llvm_module( "VMProtect 2 Static Devirtualizer", llvm_ctx );
|
|
|
|
IRBuilder<> ir_builder( llvm_ctx );
|
|
|
|
IRBuilder<> ir_builder( llvm_ctx );
|
|
|
|