### Installing Executable Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case6/CMakeLists.txt Installs the built executable to a specified destination with a component name. ```cmake INSTALL( TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT ${PROJECT_NAME} ) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/CMakeLists.txt Sets the minimum CMake version and project name for the run_pe executable. ```cmake cmake_minimum_required ( VERSION 3.12 ) project (run_pe) ``` -------------------------------- ### Installing the Shared Library Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case5/test_case5_dll/CMakeLists.txt Installs the built shared library to the specified destination directory and component. This ensures the library is available after installation. ```cmake #install INSTALL( TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT ${PROJECT_NAME} ) ``` -------------------------------- ### Installation Rules Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/CMakeLists.txt Installs the run_pe executable to the runtime directory if PECONV_LIB_INSTALL is enabled. ```cmake if(PECONV_LIB_INSTALL) include(GNUInstallDirs) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case6/CMakeLists.txt Sets the minimum required CMake version and defines the project name. ```cmake cmake_minimum_required ( VERSION 3.12 ) project (test_case6) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case5/test_case5_dll/CMakeLists.txt Initializes CMake version and project name. Sets C++ release compiler flags to /MT for multi-threaded runtime. ```cmake cmake_minimum_required ( VERSION 3.12 ) project (test_case5_dll) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") include_directories ( include ) ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case5/CMakeLists.txt Defines the build configuration for the test_case5_exe project, including dependencies and installation rules. ```cmake cmake_minimum_required ( VERSION 3.12 ) project (test_case5_exe) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") set (srcs main.cpp ) set (hdrs ) # libs add_subdirectory (test_case5_dll) include_directories ( test_case5_dll/include ) add_executable ( ${PROJECT_NAME} ${hdrs} ${srcs} ) target_link_libraries(${PROJECT_NAME} "test_case5_dll" ) #install INSTALL( TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT ${PROJECT_NAME} ) ``` -------------------------------- ### Clone LibPeConv Repository Source: https://github.com/hasherezade/libpeconv/wiki/Building-the-library Use Git to clone the official LibPeConv repository from GitHub. Ensure Git is installed on your system. ```console git clone https://github.com/hasherezade/libpeconv.git ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case1/CMakeLists.txt Defines the minimum CMake version, project name, release build flags, source files, and executable target. It also specifies installation rules for the executable. ```cmake cmake_minimum_required ( VERSION 3.12 ) project (test_case1) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") set (srcs main.cpp ) set (hdrs ) add_executable ( ${PROJECT_NAME} ${hdrs} ${srcs}) #install INSTALL( TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT ${PROJECT_NAME} ) ``` -------------------------------- ### Basic PE File Loading and Execution Source: https://github.com/hasherezade/libpeconv/blob/master/README.md Demonstrates the simplest use case of libPeConv: manually loading and running an executable file. It shows how to load a PE from a file path or a memory buffer, set up the PEB, load delayed imports, run TLS callbacks, and finally execute the PE's entry point. ```cpp #include #include #include // include libPeConv header int main(int argc, char *argv[]) { if (argc < 2) { std::cout << "Args: " << std::endl; return 0; } LPCSTR pe_path = argv[1]; // manually load the PE file using libPeConv: size_t v_size = 0; #ifdef LOAD_FROM_PATH //if the PE is dropped on the disk, you can load it from the file: BYTE* my_pe = peconv::load_pe_executable(pe_path, v_size); #else size_t bufsize = 0; BYTE *buffer = peconv::load_file(pe_path, bufsize); // if the file is NOT dropped on the disk, you can load it directly from a memory buffer: BYTE* my_pe = peconv::load_pe_executable(buffer, bufsize, v_size); #endif if (!my_pe) { return -1; } // if the loaded PE needs to access resources, you may need to connect it to the PEB: peconv::set_main_module_in_peb((HMODULE)my_pe); // load delayed imports (if present): const ULONGLONG load_base = (ULONGLONG)my_pe; peconv::load_delayed_imports(my_pe, load_base); // if needed, you can run TLS callbacks before the Entry Point: peconv::run_tls_callbacks(my_pe, v_size); //calculate the Entry Point of the manually loaded module DWORD ep_rva = peconv::get_entry_point_rva(my_pe); if (!ep_rva) { return -2; } ULONG_PTR ep_va = ep_rva + (ULONG_PTR) my_pe; //assuming that the payload is an EXE file (not DLL) this will be the simplest prototype of the main: int (*new_main)() = (int(*)())ep_va; //call the Entry Point of the manually loaded PE: return new_main(); } ``` -------------------------------- ### Add Executable and Link Libraries Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case4/CMakeLists.txt Creates an executable from the specified sources and links it with delayimp.lib. ```cmake add_executable ( ${PROJECT_NAME} ${hdrs} ${srcs} ) target_link_libraries(${PROJECT_NAME} "delayimp.lib" ) ``` -------------------------------- ### Define Source and Header Files Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case4/CMakeLists.txt Lists the source and header files for the project. ```cmake set (srcs main.cpp ) set (hdrs ) ``` -------------------------------- ### Source and Header Files Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/CMakeLists.txt Defines the source and header files for the run_pe executable. ```cmake set ( srcs main.cpp run_pe.cpp patch_ntdll.cpp ) set ( hdrs run_pe.h patch_ntdll.h ) ``` -------------------------------- ### Defining Source and Header Files Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case6/CMakeLists.txt Lists the source and header files to be compiled for the project. ```cmake set (srcs main.cpp sockets.cpp ) set (hdrs callback.h main.h sockets.h ) ``` -------------------------------- ### Displaying Build Information Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/CMakeLists.txt Prints the configured paths for PECONV_DIR and PECONV_LIB during the build process. ```cmake message (STATUS "parser_dir='${PECONV_DIR}'") message (STATUS "parser_lib='${PECONV_LIB}'") ``` -------------------------------- ### RunPE Command-Line Usage Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/README.md Supply the paths to the payload PE and the target PE as command-line arguments. The payload will impersonate the target process. ```text [payload_path] [target_path] ``` -------------------------------- ### Defining Source and Header Files Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case3/CMakeLists.txt Lists the source files (main.cpp, checksum.cpp) and header files (checksum.h) for the project. These are used to build the executable. ```cmake set (srcs main.cpp checksum.cpp ) set (hdrs checksum.h ) ``` -------------------------------- ### Creating a Shared Library (DLL) Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case5/test_case5_dll/CMakeLists.txt Builds a shared library (DLL) using the specified project name, header files, source files, and a module definition file. ```cmake add_library ( ${PROJECT_NAME} SHARED ${dll_hdrs} ${srcs} main.def) ``` -------------------------------- ### Defining Library Sources and Headers Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case5/test_case5_dll/CMakeLists.txt Defines the source files and header files for the library. This includes main.cpp and api.h. ```cmake set (srcs main.cpp ) set (dll_hdrs include/api.h ) ``` -------------------------------- ### Include LibPEConv Header Source: https://github.com/hasherezade/libpeconv/wiki/How-to-add-LibPEConv-to-your-Visual-Studio-project Include the main libpeconv header file and use the peconv namespace in your C++ project. ```cpp #include using namespace peconv; ``` -------------------------------- ### Creating an Executable Target Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case3/CMakeLists.txt Defines the executable target named 'test_case3' using the specified source and header files. This command instructs CMake to build an executable. ```cmake add_executable ( ${PROJECT_NAME} ${hdrs} ${srcs}) ``` -------------------------------- ### 64-bit Loader Injections Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/README.md When the loader is built as 64-bit, both 64-bit and 32-bit payloads can be injected into compatible targets. ```text 64 bit payload -> 64 bit target 32 bit payload -> 32 bit target ``` -------------------------------- ### Add Test for Exception Handling (64-bit) Source: https://github.com/hasherezade/libpeconv/blob/master/tests/CMakeLists.txt Conditionally configures a test for exception handling on 64-bit systems. It sets properties for passing and failing regular expressions. ```cmake if(CMAKE_SIZEOF_VOID_P EQUAL 8) add_test (TestExceptionTbl tests 18 ${CMAKE_INSTALL_PREFIX}/test_case7.exe ) set_tests_properties (TestExceptionTbl PROPERTIES PASS_REGULAR_EXPRESSION "Exception handled:") set_tests_properties (TestExceptionTbl PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") endif() ``` -------------------------------- ### Executable Target Definition Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/CMakeLists.txt Defines the run_pe executable using the specified source and header files. ```cmake add_executable ( ${PROJECT_NAME} ${hdrs} ${srcs} ) ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case4/CMakeLists.txt Specifies the minimum required CMake version and defines the project name. ```cmake cmake_minimum_required ( VERSION 3.12 ) project (test_case4) ``` -------------------------------- ### Include Directories Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/CMakeLists.txt Adds the PECONV_DIR/include directory to the project's include paths. ```cmake include_directories ( ${PECONV_DIR}/include ) ``` -------------------------------- ### Linking Libraries Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/CMakeLists.txt Links the run_pe executable against the PECONV_LIB library. ```cmake target_link_libraries ( ${PROJECT_NAME} ${PECONV_LIB} ) ``` -------------------------------- ### Build Dependencies Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/CMakeLists.txt Adds a dependency on the libpeconv target. ```cmake add_dependencies( ${PROJECT_NAME} libpeconv) ``` -------------------------------- ### Add Test for Running TLS Callbacks Source: https://github.com/hasherezade/libpeconv/blob/master/tests/CMakeLists.txt Configures a test to run TLS callbacks and checks for a specific password pattern in the output. It sets properties for passing and failing regular expressions. ```cmake add_test (TestTLSCallbacks tests 17 ${CMAKE_INSTALL_PREFIX}/test_case6.exe ) set_tests_properties (TestTLSCallbacks PROPERTIES PASS_REGULAR_EXPRESSION "Password: NR7YcqGFUn0") set_tests_properties (TestTLSCallbacks PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") ``` -------------------------------- ### Add Test for Detecting 64-bit Virtual/Raw Mode Source: https://github.com/hasherezade/libpeconv/blob/master/tests/CMakeLists.txt Configures a test to detect the virtual/raw mode for a 64-bit executable. It sets properties for passing and failing regular expressions. ```cmake add_test (TestDetectMode64 tests 16 ${CMAKE_INSTALL_PREFIX}/test_case3_64.exe ) set_tests_properties (TestDetectMode64 PROPERTIES PASS_REGULAR_EXPRESSION "Test passed") set_tests_properties (TestDetectMode64 PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") ``` -------------------------------- ### 32-bit Payload to 32-bit Target Injection Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/README.md This injection is supported when the loader is built as 32-bit. ```text 32 bit payload -> 32 bit target ``` -------------------------------- ### Add Test for Replacing Functions (64-bit) Source: https://github.com/hasherezade/libpeconv/blob/master/tests/CMakeLists.txt Adds a test case for replacing functions in a 64-bit executable. This snippet is executed when the build system detects a 64-bit architecture. ```cmake if(CMAKE_SIZEOF_VOID_P EQUAL 8) add_test (TestReplaceFunc64 ${CMAKE_INSTALL_PREFIX}/tests 8 ${CMAKE_INSTALL_PREFIX}/test_case3_64.exe ) set_tests_properties (TestReplaceFunc64 PROPERTIES PASS_REGULAR_EXPRESSION "Passed!") set_tests_properties (TestReplaceFunc64 PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") else() add_test (TestReplaceFunc32 tests 8 ${CMAKE_INSTALL_PREFIX}/test_case3_32.exe ) set_tests_properties (TestReplaceFunc32 PROPERTIES PASS_REGULAR_EXPRESSION "Passed!") set_tests_properties (TestReplaceFunc32 PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") endif() ``` -------------------------------- ### Define Delay-Load Flag for user32.dll Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case4/CMakeLists.txt Sets a variable for the delay-load flag targeting user32.dll. ```cmake set(DELAYLOAD_FLAG "/DELAYLOAD:\"user32.dll\"" ) ``` -------------------------------- ### Add Test for Detecting 32-bit Virtual/Raw Mode Source: https://github.com/hasherezade/libpeconv/blob/master/tests/CMakeLists.txt Configures a test to detect the virtual/raw mode for a 32-bit executable. It sets properties for passing and failing regular expressions. ```cmake add_test (TestDetectMode32 tests 16 ${CMAKE_INSTALL_PREFIX}/test_case3_32.exe ) set_tests_properties (TestDetectMode32 PROPERTIES PASS_REGULAR_EXPRESSION "Test passed") set_tests_properties (TestDetectMode32 PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") ``` -------------------------------- ### Setting Release C++ Flags Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case6/CMakeLists.txt Configures the C++ compiler flags for the release build to use the multi-threaded DLL runtime library. ```cmake set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD") ``` -------------------------------- ### Add Test for PEB Lookup Source: https://github.com/hasherezade/libpeconv/blob/master/tests/CMakeLists.txt Adds a test case to verify the library's ability to perform lookups within the Process Environment Block (PEB). This test ensures correct access to process-specific information. ```cmake add_test (TestPEBLookup ${CMAKE_INSTALL_PREFIX}/tests 12 ) set_tests_properties (TestPEBLookup PROPERTIES PASS_REGULAR_EXPRESSION "Test passed") set_tests_properties (TestPEBLookup PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") ``` -------------------------------- ### Add Test for Finding Base Address Source: https://github.com/hasherezade/libpeconv/blob/master/tests/CMakeLists.txt Configures a test to find the base address of an executable. It sets properties for passing and failing regular expressions. ```cmake add_test (TestFindBase ${CMAKE_INSTALL_PREFIX}/tests 14 ${CMAKE_INSTALL_PREFIX}/test_case5_exe.exe ) set_tests_properties (TestFindBase PROPERTIES PASS_REGULAR_EXPRESSION "Test passed") set_tests_properties (TestFindBase PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") ``` -------------------------------- ### Add Test for Finding Jumps Source: https://github.com/hasherezade/libpeconv/blob/master/tests/CMakeLists.txt Configures a test to find jumps within an executable. It sets properties for passing and failing regular expressions. ```cmake add_test (TestFindJumpToDotNet ${CMAKE_INSTALL_PREFIX}/tests 15 ) set_tests_properties (TestFindJumpToDotNet PROPERTIES PASS_REGULAR_EXPRESSION "Test passed") set_tests_properties (TestFindJumpToDotNet PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") ``` -------------------------------- ### Add Test for Redirecting Local Functions Source: https://github.com/hasherezade/libpeconv/blob/master/tests/CMakeLists.txt Adds a test case to validate the redirection of local functions within an executable, including the mechanism for undoing such redirections. This ensures the library can dynamically alter function behavior and revert changes. ```cmake add_test (TestLocalRedirect tests 11 ) set_tests_properties (TestLocalRedirect PROPERTIES PASS_REGULAR_EXPRESSION "Test passed") set_tests_properties (TestLocalRedirect PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") ``` -------------------------------- ### Add Test for Mixed Imports Source: https://github.com/hasherezade/libpeconv/blob/master/tests/CMakeLists.txt Adds a test case to check the handling of mixed import types within an executable. This test verifies the library's robustness when dealing with various import configurations. ```cmake add_test (TestMixImp ${CMAKE_INSTALL_PREFIX}/tests 13 ${CMAKE_INSTALL_PREFIX}/test_case5_exe.exe ) set_tests_properties (TestMixImp PROPERTIES PASS_REGULAR_EXPRESSION "Test Case 5 finished, checks: a0caa919") set_tests_properties (TestMixImp PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") ``` -------------------------------- ### Add Test for Replacing Delay-Load Imports Source: https://github.com/hasherezade/libpeconv/blob/master/tests/CMakeLists.txt Adds a test case to verify the functionality of replacing delay-load imports in an executable. This test checks if the hooking mechanism correctly intercepts and redirects these imports. ```cmake add_test (TestDelayedImps ${CMAKE_INSTALL_PREFIX}/tests 9 ${CMAKE_INSTALL_PREFIX}/test_case4.exe ) set_tests_properties (TestDelayedImps PROPERTIES PASS_REGULAR_EXPRESSION "Hooking test passed") set_tests_properties (TestDelayedImps PROPERTIES FAIL_REGULAR_EXPRESSION "Failed") ``` -------------------------------- ### MSVC Release C++ Flags Source: https://github.com/hasherezade/libpeconv/blob/master/run_pe/CMakeLists.txt Configures the C++ release flags for MSVC to use the multi-threaded runtime. ```cmake if (MSVC) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") endif() ``` -------------------------------- ### Set Release C++ Compiler Flags Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case4/CMakeLists.txt Appends the /MT flag to CMAKE_CXX_FLAGS_RELEASE for release builds, ensuring static linking of the C runtime. ```cmake set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") ``` -------------------------------- ### Append Delay-Load Flag to Linker Flags Source: https://github.com/hasherezade/libpeconv/blob/master/tests/test_case4/CMakeLists.txt Appends the defined DELAYLOAD_FLAG to the linker flags for the target project. ```cmake set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${DELAYLOAD_FLAG}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.