From 3dbefbe1c3fb03011e1b1f198a7466c3a61304dc Mon Sep 17 00:00:00 2001 From: xerox Date: Sun, 19 Dec 2021 20:53:53 -0800 Subject: [PATCH] added cli parser, compiles, cmkr finished... --- .gitignore | 1 + .gitmodules | 3 ++ CMakeLists.txt | 80 +++++++++++++++++++++++++++++++++++++++++++++ deps/CMakeLists.txt | 46 ++++++++++++++++++++++++++ deps/cli-parser | 1 + src/main.cpp | 45 +++++++++++++++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 deps/CMakeLists.txt create mode 160000 deps/cli-parser create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore index 984df86..d8c5a70 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *.user *.userosscache *.sln.docstates +*.o # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/.gitmodules b/.gitmodules index b7495c3..598137b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "deps/unicorn"] path = deps/unicorn url = https://github.com/unicorn-engine/unicorn.git +[submodule "deps/cli-parser"] + path = deps/cli-parser + url = https://githacks.org/_xeroxz/cli-parser.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b87323b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,80 @@ +# This file is automatically generated from cmake.toml - DO NOT EDIT +# See https://github.com/build-cpp/cmkr for more information + +cmake_minimum_required(VERSION 3.15) + +# Regenerate CMakeLists.txt automatically in the root project +set(CMKR_ROOT_PROJECT OFF) +if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(CMKR_ROOT_PROJECT ON) + + # Bootstrap cmkr + include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT) + if(CMKR_INCLUDE_RESULT) + cmkr() + endif() + + # Enable folder support + set_property(GLOBAL PROPERTY USE_FOLDERS ON) +endif() + +# Create a configure-time dependency on cmake.toml to improve IDE support +if(CMKR_ROOT_PROJECT) + configure_file(cmake.toml cmake.toml COPYONLY) +endif() + +project(vmemu) + +# deps +set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER}) +if(CMAKE_FOLDER) + set(CMAKE_FOLDER "${CMAKE_FOLDER}/deps") +else() + set(CMAKE_FOLDER deps) +endif() +add_subdirectory(deps) +set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER}) + +# Target vmemu +set(CMKR_TARGET vmemu) +set(vmemu_SOURCES "") + +list(APPEND vmemu_SOURCES + "src/main.cpp" +) + +list(APPEND vmemu_SOURCES + cmake.toml +) + +set(CMKR_SOURCES ${vmemu_SOURCES}) +add_executable(vmemu) + +if(vmemu_SOURCES) + target_sources(vmemu PRIVATE ${vmemu_SOURCES}) +endif() + +get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT) +if(NOT CMKR_VS_STARTUP_PROJECT) + set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT vmemu) +endif() + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${vmemu_SOURCES}) + +target_compile_definitions(vmemu PRIVATE + NOMINMAX +) + +target_include_directories(vmemu PRIVATE + include +) + +target_link_libraries(vmemu PRIVATE + vmprofiler + unicorn + cli-parser +) + +unset(CMKR_TARGET) +unset(CMKR_SOURCES) + diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt new file mode 100644 index 0000000..0586732 --- /dev/null +++ b/deps/CMakeLists.txt @@ -0,0 +1,46 @@ +# This file is automatically generated from cmake.toml - DO NOT EDIT +# See https://github.com/build-cpp/cmkr for more information + +# Create a configure-time dependency on cmake.toml to improve IDE support +if(CMKR_ROOT_PROJECT) + configure_file(cmake.toml cmake.toml COPYONLY) +endif() + +# vmprofiler +set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER}) +if(CMAKE_FOLDER) + set(CMAKE_FOLDER "${CMAKE_FOLDER}/vmprofiler") +else() + set(CMAKE_FOLDER vmprofiler) +endif() +add_subdirectory(vmprofiler) +set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER}) + +# unicorn +set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER}) +if(CMAKE_FOLDER) + set(CMAKE_FOLDER "${CMAKE_FOLDER}/unicorn") +else() + set(CMAKE_FOLDER unicorn) +endif() +add_subdirectory(unicorn) +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) + diff --git a/deps/cli-parser b/deps/cli-parser new file mode 160000 index 0000000..1aedaf8 --- /dev/null +++ b/deps/cli-parser @@ -0,0 +1 @@ +Subproject commit 1aedaf8bb7f383f54b7cd498767611535526da85 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..32f3e1c --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +#define NUM_THREADS 20 + +int __cdecl main(int argc, const char* argv[]) { + argparse::argument_parser_t parser("VMEmu", + "VMProtect 3 VM Handler Emulator"); + parser.add_argument() + .name("--vmentry") + .description("relative virtual address to a vm entry..."); + parser.add_argument() + .name("--bin") + .description("path to unpacked virtualized binary...") + .required(true); + parser.add_argument() + .name("--out") + .description("output file name...") + .required(true); + parser.add_argument().name("--unpack").description("unpack a vmp2 binary..."); + parser.add_argument() + .names({"-f", "--force"}) + .description("force emulation of unknown vm handlers..."); + parser.add_argument() + .name("--emuall") + .description( + "scan for all vm enters and trace all of them... this may take a few " + "minutes..."); + + parser.enable_help(); + auto result = parser.parse(argc, argv); + + if (result) { + std::printf("[!] error parsing commandline arguments... reason = %s\n", + result.what().c_str()); + return -1; + } + + if (parser.exists("help")) { + parser.print_help(); + return 0; + } +} \ No newline at end of file