added cli parser to deps... added vmp2 file parsing...

colton
_xeroxz 3 years ago
parent 2c85ccae65
commit 8841661c3b

3
.gitmodules vendored

@ -4,3 +4,6 @@
[submodule "dependencies/vmprofiler"] [submodule "dependencies/vmprofiler"]
path = dependencies/vmprofiler path = dependencies/vmprofiler
url = https://githacks.org/vmp2/vmprofiler.git url = https://githacks.org/vmp2/vmprofiler.git
[submodule "dependencies/cli-parser"]
path = dependencies/cli-parser
url = https://githacks.org/_xeroxz/cli-parser.git

@ -72,6 +72,7 @@ target_include_directories(vmdevirt PRIVATE
) )
target_link_libraries(vmdevirt PRIVATE target_link_libraries(vmdevirt PRIVATE
cli-parser
vmprofiler vmprofiler
LLVMCore LLVMCore
LLVMCodeGen LLVMCodeGen

@ -15,6 +15,7 @@ include-directories = [
"build/dependencies/llvm/llvm/include/", "build/dependencies/llvm/llvm/include/",
] ]
link-libraries = [ link-libraries = [
"cli-parser",
"vmprofiler", "vmprofiler",
"LLVMCore", "LLVMCore",
"LLVMCodeGen", "LLVMCodeGen",

@ -26,3 +26,21 @@ endif()
add_subdirectory(vmprofiler) add_subdirectory(vmprofiler)
set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER}) set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER})
# Target cli-parser
set(CMKR_TARGET cli-parser)
set(cli-parser_SOURCES "")
set(CMKR_SOURCES ${cli-parser_SOURCES})
add_library(cli-parser INTERFACE)
if(cli-parser_SOURCES)
target_sources(cli-parser INTERFACE ${cli-parser_SOURCES})
endif()
target_include_directories(cli-parser INTERFACE
cli-parser
)
unset(CMKR_TARGET)
unset(CMKR_SOURCES)

@ -0,0 +1 @@
Subproject commit 1aedaf8bb7f383f54b7cd498767611535526da85

@ -1,2 +1,6 @@
[subdir."llvm/llvm"] [subdir."llvm/llvm"]
[subdir.vmprofiler] [subdir.vmprofiler]
[target.cli-parser]
type = "interface"
include-directories = ["cli-parser"]

@ -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 );

Loading…
Cancel
Save