### Build and Install libmem from Source Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Instructions for building and installing the libmem Python package from its source code. This involves navigating to the source directory and running configuration and installation scripts. ```bash cd libmem-py python configure.py python setup.py install ``` -------------------------------- ### Build and Install libmem from Source Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Instructions for building and installing the libmem Python package from its source code. This involves navigating to the source directory and running configuration and installation scripts. ```bash cd libmem-py python configure.py python setup.py install ``` -------------------------------- ### Install Dependencies on FreeBSD Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Details the steps to install necessary tools like Git, CMake, and Python on FreeBSD, along with configuring the procfs filesystem. ```bash pkg install git cmake python3 ``` -------------------------------- ### libmem CMake Installation Script Source: https://github.com/rdbo/libmem/blob/master/CMakeLists.txt This script defines the installation logic for the libmem library. It sets the installation prefix, creates necessary directories, and specifies the installation locations for the library targets and header files. ```cmake set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/libmem") execute_process(COMMAND mkdir "${CMAKE_INSTALL_PREFIX}") else() set(CMAKE_INSTALL_PREFIX "/usr") endif() install(TARGETS libmem LIBRARY DESTINATION lib) install(TARGETS libmem RUNTIME DESTINATION lib) install(DIRECTORY ${LIBMEM_INC}/libmem DESTINATION include) ``` -------------------------------- ### Install libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Commands to install the compiled libmem library, typically requiring administrator privileges. Uses 'nmake install' on Windows and 'make install' on Unix-like systems. ```bash # Windows: nmake install # Unix-like: make install ``` -------------------------------- ### Build and Install libmem from Source Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Instructions for building and installing the libmem Python package from its source code. This involves navigating to the source directory and running configuration and installation scripts. ```bash cd libmem-py python configure.py python setup.py install ``` -------------------------------- ### Build and Install libmem from Source Source: https://github.com/rdbo/libmem/blob/master/README.md Instructions for building and installing the libmem Python package from its source code. This involves navigating to the source directory and running configuration and installation scripts. ```bash cd libmem-py python configure.py python setup.py install ``` -------------------------------- ### Install libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Commands to install the compiled libmem library, typically requiring administrator privileges. Uses 'nmake install' on Windows and 'make install' on Unix-like systems. ```bash # Windows: nmake install # Unix-like: make install ``` -------------------------------- ### Install Dependencies on FreeBSD Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Details the steps to install necessary tools like Git, CMake, and Python on FreeBSD, along with configuring the procfs filesystem. ```bash pkg install git cmake python3 ``` -------------------------------- ### Install Dependencies on FreeBSD Source: https://github.com/rdbo/libmem/blob/master/README.md Details the steps to install necessary tools like Git, CMake, and Python on FreeBSD, along with configuring the procfs filesystem. ```bash pkg install git cmake python3 ``` -------------------------------- ### Installation Prefix Configuration Source: https://github.com/rdbo/libmem/blob/master/CMakeLists.txt Sets the installation prefix for the project on Windows systems, typically to `$ENV{ProgramFiles}` or its Cygwin equivalent. ```cmake if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN) if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN) cmake_path(SET CMAKE_INSTALL_PREFIX "$ENV{ProgramFiles}") else() execute_process(COMMAND cygpath -u "$PROGRAMFILES" OUTPUT_VARIABLE CMAKE_INSTALL_PREFIX) endif() endif() ``` -------------------------------- ### Install Dependencies on FreeBSD Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Details the steps to install necessary tools like Git, CMake, and Python on FreeBSD, along with configuring the procfs filesystem. ```bash pkg install git cmake python3 ``` -------------------------------- ### Install libmem Source: https://github.com/rdbo/libmem/blob/master/README.md Commands to install the compiled libmem library, typically requiring administrator privileges. Uses 'nmake install' on Windows and 'make install' on Unix-like systems. ```bash # Windows: nmake install # Unix-like: make install ``` -------------------------------- ### Project Setup and Directory Definitions Source: https://github.com/rdbo/libmem/blob/master/CMakeLists.txt Initializes the CMake project and defines key directories for source files, headers, and internal modules. These variables are used throughout the build configuration. ```cmake set(LIBMEM_DIR "${PROJECT_SOURCE_DIR}") set(LIBMEM_INC "${LIBMEM_DIR}/include") set(INTERNAL_DIR "${LIBMEM_DIR}/internal") set(COMMON_DIR "${LIBMEM_DIR}/src/common") ``` -------------------------------- ### Install libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Commands to install the compiled libmem library, typically requiring administrator privileges. Uses 'nmake install' on Windows and 'make install' on Unix-like systems. ```bash # Windows: nmake install # Unix-like: make install ``` -------------------------------- ### Project Setup and Build Options Source: https://github.com/rdbo/libmem/blob/master/CMakeLists.txt Initializes the CMake project, sets the project name and languages (C, CXX, ASM). It defines boolean options for building tests, enabling deep tests, and building a static library, controlling project features. ```CMake cmake_minimum_required(VERSION 3.22.1) include(ExternalProject) project(libmem LANGUAGES C CXX ASM ) message(STATUS "[*] Platform: ${CMAKE_SYSTEM_NAME}" ) option(LIBMEM_BUILD_TESTS "Build tests" OFF ) option(LIBMEM_DEEP_TESTS "Enable extra testing features for deep testing" OFF ) option(LIBMEM_BUILD_STATIC "Build a static library" OFF ) ``` -------------------------------- ### Install libmem with vcpkg Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Provides the command to install the libmem package using the vcpkg package manager. This is a common method for managing C/C++ dependencies. ```bash vcpkg install libmem ``` -------------------------------- ### Configure Windows PATH for libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Adds libmem's include and library directories to the system's PATH environment variable on Windows. This is a crucial step for binary installations. ```bash setx PATH "%PATH%;%ProgramFiles%\libmem\include;%ProgramFiles%\libmem\lib" ``` -------------------------------- ### Configure Windows PATH for libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Adds libmem's include and library directories to the system's PATH environment variable on Windows. This is a crucial step for binary installations. ```bash setx PATH "%PATH%;%ProgramFiles%\libmem\include;%ProgramFiles%\libmem\lib" ``` -------------------------------- ### Install libmem with vcpkg Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Provides the command to install the libmem package using the vcpkg package manager. This is a common method for managing C/C++ dependencies. ```bash vcpkg install libmem ``` -------------------------------- ### Install libmem with vcpkg Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Provides the command to install the libmem package using the vcpkg package manager. This is a common method for managing C/C++ dependencies. ```bash vcpkg install libmem ``` -------------------------------- ### Install libmem with vcpkg Source: https://github.com/rdbo/libmem/blob/master/README.md Provides the command to install the libmem package using the vcpkg package manager. This is a common method for managing C/C++ dependencies. ```bash vcpkg install libmem ``` -------------------------------- ### Install libmem via Pip Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Installs or upgrades the libmem Python package from PyPI. This is the recommended method for Python users. ```bash pip install --upgrade libmem ``` -------------------------------- ### CMake Setup for libmem Source: https://github.com/rdbo/libmem/blob/master/README.md Configures libmem using CMake's FetchContent module. It declares the libmem-config.cmake file, makes it available, sets the CMAKE_PREFIX_PATH, and finds the libmem package. ```cmake FetchContent_Declare(libmem-config URL "https://raw.githubusercontent.com/rdbo/libmem/config-v1/libmem-config.cmake" DOWNLOAD_NO_EXTRACT TRUE) FetchContent_MakeAvailable(libmem-config) set(CMAKE_PREFIX_PATH "${libmem-config_SOURCE_DIR}" "${CMAKE_PREFIX_PATH}") set(LIBMEM_DOWNLOAD_VERSION "5.0.2") find_package(libmem CONFIG REQUIRED) ``` -------------------------------- ### Install libmem via Pip Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Installs or upgrades the libmem Python package from PyPI. This is the recommended method for Python users. ```bash pip install --upgrade libmem ``` -------------------------------- ### External Dependencies Path Setup Source: https://github.com/rdbo/libmem/blob/master/CMakeLists.txt Defines the directory structure for external dependencies, including Capstone, Keystone, and LLVM. It sets variables for include paths and import directories required for linking these libraries. ```CMake # External dependencies set(EXTERNAL_DEPENDENCIES_DIR "${PROJECT_SOURCE_DIR}/external") set(CAPSTONE_DIR "${EXTERNAL_DEPENDENCIES_DIR}/capstone") set(CAPSTONE_INC "${CAPSTONE_DIR}/include") set(CAPSTONE_IMPORT_DIR "${PROJECT_BINARY_DIR}/external/capstone-engine-prefix/src/capstone-engine-build") set(KEYSTONE_DIR "${EXTERNAL_DEPENDENCIES_DIR}/keystone") set(KEYSTONE_INC "${KEYSTONE_DIR}/include") set(KEYSTONE_IMPORT_DIR "${PROJECT_BINARY_DIR}/external/keystone-engine-prefix/src/keystone-engine-build/llvm/lib") set(LLVM_DIR "${EXTERNAL_DEPENDENCIES_DIR}/llvm") set(LLVM_INC "${LLVM_DIR}/include") ``` -------------------------------- ### Configure Windows PATH for libmem Source: https://github.com/rdbo/libmem/blob/master/README.md Adds libmem's include and library directories to the system's PATH environment variable on Windows. This is a crucial step for binary installations. ```bash setx PATH "%PATH%;%ProgramFiles%\libmem\include;%ProgramFiles%\libmem\lib" ``` -------------------------------- ### CMake Setup for libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Configures libmem using CMake's FetchContent module. It declares the libmem-config.cmake file, makes it available, sets the CMAKE_PREFIX_PATH, and finds the libmem package. ```cmake FetchContent_Declare(libmem-config URL "https://raw.githubusercontent.com/rdbo/libmem/config-v1/libmem-config.cmake" DOWNLOAD_NO_EXTRACT TRUE) FetchContent_MakeAvailable(libmem-config) set(CMAKE_PREFIX_PATH "${libmem-config_SOURCE_DIR}" "${CMAKE_PREFIX_PATH}") set(LIBMEM_DOWNLOAD_VERSION "5.0.2") find_package(libmem CONFIG REQUIRED) ``` -------------------------------- ### Configure Windows PATH for libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Adds libmem's include and library directories to the system's PATH environment variable on Windows. This is a crucial step for binary installations. ```bash setx PATH "%PATH%;%ProgramFiles%\libmem\include;%ProgramFiles%\libmem\lib" ``` -------------------------------- ### Install Dependencies on Debian/Ubuntu Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Lists the essential packages required for building libmem on Debian/Ubuntu-based Linux distributions, including GCC, Git, CMake, Make, and Python. ```bash sudo apt install gcc g++ git cmake make python3 linux-headers ``` -------------------------------- ### Install libmem via Pip Source: https://github.com/rdbo/libmem/blob/master/README.md Installs or upgrades the libmem Python package from PyPI. This is the recommended method for Python users. ```bash pip install --upgrade libmem ``` -------------------------------- ### Install libmem via Pip Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Installs or upgrades the libmem Python package from PyPI. This is the recommended method for Python users. ```bash pip install --upgrade libmem ``` -------------------------------- ### CMake Setup for libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Configures libmem using CMake's FetchContent module. It declares the libmem-config.cmake file, makes it available, sets the CMAKE_PREFIX_PATH, and finds the libmem package. ```cmake FetchContent_Declare(libmem-config URL "https://raw.githubusercontent.com/rdbo/libmem/config-v1/libmem-config.cmake" DOWNLOAD_NO_EXTRACT TRUE) FetchContent_MakeAvailable(libmem-config) set(CMAKE_PREFIX_PATH "${libmem-config_SOURCE_DIR}" "${CMAKE_PREFIX_PATH}") set(LIBMEM_DOWNLOAD_VERSION "5.0.2") find_package(libmem CONFIG REQUIRED) ``` -------------------------------- ### Install Dependencies on Debian/Ubuntu Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Lists the essential packages required for building libmem on Debian/Ubuntu-based Linux distributions, including GCC, Git, CMake, Make, and Python. ```bash sudo apt install gcc g++ git cmake make python3 linux-headers ``` -------------------------------- ### CMake Integration for libmem Source: https://github.com/rdbo/libmem/blob/master/README.md Provides instructions on how to integrate libmem into a CMake project without requiring a separate installation. It involves using `FetchContent` to download the necessary configuration file and include libmem. ```cmake include(FetchContent) # Add the following commands to your CMakeLists.txt. # They will fetch libmem-config.cmake from the root of this repository, # which will download libmem binaries for your system and include libmem in your CMake project. ``` -------------------------------- ### CMake Setup for libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Configures libmem using CMake's FetchContent module. It declares the libmem-config.cmake file, makes it available, sets the CMAKE_PREFIX_PATH, and finds the libmem package. ```cmake FetchContent_Declare(libmem-config URL "https://raw.githubusercontent.com/rdbo/libmem/config-v1/libmem-config.cmake" DOWNLOAD_NO_EXTRACT TRUE) FetchContent_MakeAvailable(libmem-config) set(CMAKE_PREFIX_PATH "${libmem-config_SOURCE_DIR}" "${CMAKE_PREFIX_PATH}") set(LIBMEM_DOWNLOAD_VERSION "5.0.2") find_package(libmem CONFIG REQUIRED) ``` -------------------------------- ### CMake Integration for libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Provides instructions on how to integrate libmem into a CMake project without requiring a separate installation. It involves using `FetchContent` to download the necessary configuration file and include libmem. ```cmake include(FetchContent) # Add the following commands to your CMakeLists.txt. # They will fetch libmem-config.cmake from the root of this repository, # which will download libmem binaries for your system and include libmem in your CMake project. ``` -------------------------------- ### Install Dependencies on Debian/Ubuntu Source: https://github.com/rdbo/libmem/blob/master/README.md Lists the essential packages required for building libmem on Debian/Ubuntu-based Linux distributions, including GCC, Git, CMake, Make, and Python. ```bash sudo apt install gcc g++ git cmake make python3 linux-headers ``` -------------------------------- ### CMake Integration for libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Provides instructions on how to integrate libmem into a CMake project without requiring a separate installation. It involves using `FetchContent` to download the necessary configuration file and include libmem. ```cmake include(FetchContent) # Add the following commands to your CMakeLists.txt. # They will fetch libmem-config.cmake from the root of this repository, # which will download libmem binaries for your system and include libmem in your CMake project. ``` -------------------------------- ### CMake Integration for libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Provides instructions on how to integrate libmem into a CMake project without requiring a separate installation. It involves using `FetchContent` to download the necessary configuration file and include libmem. ```cmake include(FetchContent) # Add the following commands to your CMakeLists.txt. # They will fetch libmem-config.cmake from the root of this repository, # which will download libmem binaries for your system and include libmem in your CMake project. ``` -------------------------------- ### Install Dependencies on Debian/Ubuntu Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Lists the essential packages required for building libmem on Debian/Ubuntu-based Linux distributions, including GCC, Git, CMake, Make, and Python. ```bash sudo apt install gcc g++ git cmake make python3 linux-headers ``` -------------------------------- ### Hook Function in C/C++ using libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Provides an example of hooking a function in C/C++ using libmem. It demonstrates finding a module, locating a function's address by symbol name, and then applying a code hook to redirect execution to a custom handler function. ```c #include void hk_take_damage(int amount) { printf("hooked take_damage! no damage will be taken\n"); return; } int main() { lm_module_t game_mod; lm_address_t fn_take_damage; LM_FindModule("game.dll", &game_mod); printf("[*] Base address of 'game.dll': %p\n", game_mod.base); fn_take_damage = LM_FindSymbolAddress(&game_mod, "take_damage"); printf("[*] Found 'take_damage' function: %p\n", fn_take_damage); LM_HookCode(fn_take_damage, hk_take_damage, LM_NULLPTR); printf("[*] 'take_damage' hooked, player will no longer receive damage\n"); return 0; } ``` -------------------------------- ### Hook Function in C/C++ using libmem Source: https://github.com/rdbo/libmem/blob/master/README.md Provides an example of hooking a function in C/C++ using libmem. It demonstrates finding a module, locating a function's address by symbol name, and then applying a code hook to redirect execution to a custom handler function. ```c #include void hk_take_damage(int amount) { printf("hooked take_damage! no damage will be taken\n"); return; } int main() { lm_module_t game_mod; lm_address_t fn_take_damage; LM_FindModule("game.dll", &game_mod); printf("[*] Base address of 'game.dll': %p\n", game_mod.base); fn_take_damage = LM_FindSymbolAddress(&game_mod, "take_damage"); printf("[*] Found 'take_damage' function: %p\n", fn_take_damage); LM_HookCode(fn_take_damage, hk_take_damage, LM_NULLPTR); printf("[*] 'take_damage' hooked, player will no longer receive damage\n"); return 0; } ``` -------------------------------- ### Hook Function in C/C++ using libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Provides an example of hooking a function in C/C++ using libmem. It demonstrates finding a module, locating a function's address by symbol name, and then applying a code hook to redirect execution to a custom handler function. ```c #include void hk_take_damage(int amount) { printf("hooked take_damage! no damage will be taken\n"); return; } int main() { lm_module_t game_mod; lm_address_t fn_take_damage; LM_FindModule("game.dll", &game_mod); printf("[*] Base address of 'game.dll': %p\n", game_mod.base); fn_take_damage = LM_FindSymbolAddress(&game_mod, "take_damage"); printf("[*] Found 'take_damage' function: %p\n", fn_take_damage); LM_HookCode(fn_take_damage, hk_take_damage, LM_NULLPTR); printf("[*] 'take_damage' hooked, player will no longer receive damage\n"); return 0; } ``` -------------------------------- ### Build Unit Test Executable Source: https://github.com/rdbo/libmem/blob/master/tests/CMakeLists.txt Creates the 'unit' executable, which links against 'libmem'. It includes necessary header directories and defines specific compile-time variables like LIBTEST_PATH and TARGET_NAME. ```cmake file(GLOB_RECURSE UNIT_SRC "${TESTS_DIR}/unit/*.c") add_executable(unit ${UNIT_SRC}) target_include_directories(unit PUBLIC ${LIBMEM_INC} ) target_link_libraries(unit libmem) target_compile_definitions(unit PUBLIC LIBTEST_PATH="${LIBTEST_PATH}" TARGET_NAME="target${CMAKE_EXECUTABLE_SUFFIX}") ``` -------------------------------- ### Clone libmem Repository Source: https://github.com/rdbo/libmem/blob/master/CONTRIBUTING.md Clones the forked libmem GitHub repository to your local machine. This is the first step after forking the project. ```bash git clone https://github.com//libmem.git) ``` -------------------------------- ### Build C++ Test Executable Source: https://github.com/rdbo/libmem/blob/master/tests/CMakeLists.txt Sets up the 'cpptests' executable using C++ source files. It links against the 'libmem' library, enabling C++ tests for the project. ```cmake set(CPPTESTS_SRC "${TESTS_DIR}/cpptests.cpp") add_executable(cpptests ${CPPTESTS_SRC}) target_link_libraries(cpptests libmem) ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/rdbo/libmem/blob/master/CONTRIBUTING.md Changes the current directory to the cloned libmem project folder. This allows you to work within the project's files. ```bash cd libmem ``` -------------------------------- ### Static Library Bundling Source: https://github.com/rdbo/libmem/blob/master/CMakeLists.txt When building a static library, this section creates a bundled archive (`.a` or `.lib`) that includes all necessary dependencies. It uses `ar` for Unix-like systems and `lib.exe` for MSVC. ```cmake if(LIBMEM_BUILD_STATIC) set_target_properties(libmem PROPERTIES OUTPUT_NAME "libmem_partial") set(libmem_bundle_files "$") get_target_property(libmem_link_libraries libmem LINK_LIBRARIES) foreach(libmem_link_library IN LISTS libmem_link_libraries) if(TARGET "${libmem_link_library}") list(APPEND libmem_bundle_files "$") endif() endforeach() if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL Windows AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN) file(WRITE "${CMAKE_BINARY_DIR}/liblibmem.ar.in" "CREATE liblibmem.a\n" ) foreach(libmem_bundle_file IN LISTS libmem_bundle_files) file(APPEND "${CMAKE_BINARY_DIR}/liblibmem.ar.in" "ADDLIB ${libmem_bundle_file}\n") endforeach() file(APPEND "${CMAKE_BINARY_DIR}/liblibmem.ar.in" "SAVE\nEND\n") file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/liblibmem.ar" INPUT "${CMAKE_BINARY_DIR}/liblibmem.ar.in") add_custom_command( TARGET libmem POST_BUILD WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" COMMAND "${CMAKE_AR}" -M < "${CMAKE_BINARY_DIR}/liblibmem.ar" COMMENT "Bundling liblibmem.a" VERBATIM ) elseif(MSVC) find_program(LIB_EXECUTABLE lib) add_custom_command( TARGET libmem POST_BUILD WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" COMMAND "${LIB_EXECUTABLE}" /NOLOGO /OUT:libmem.lib ${libmem_bundle_files} COMMENT "Bundling libmem.lib" VERBATIM ) else() message(WARNING "Static library bundling not supported on this platform") endif() endif() ``` -------------------------------- ### Stage and Commit Changes Source: https://github.com/rdbo/libmem/blob/master/CONTRIBUTING.md Stages all modified files for commit and then creates a new commit with a descriptive message. This prepares your changes for pushing. ```bash git add . ``` ```bash git commit -m "" ``` -------------------------------- ### Configure Capstone Engine Source: https://github.com/rdbo/libmem/blob/master/external/CMakeLists.txt Sets CMake arguments for building the Capstone engine. This includes build type, compiler flags, runtime library settings, architecture support, and disabling tests/tools. It also includes specific logic for MSVC to manage static runtime builds and a hack to adjust the Capstone CMakeLists.txt for better compatibility with CMAKE_MSVC_RUNTIME_LIBRARY. ```cmake set(CAPSTONE_CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY} -DCAPSTONE_ARCHITECTURE_DEFAULT=ON -DCAPSTONE_BUILD_TESTS=OFF -DCAPSTONE_BUILD_CSTOOL=OFF -DCAPSTONE_INSTALL=OFF -DCAPSTONE_BUILD_SHARED=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCAPSTONE_ARCHITECTURE_DEFAULT=OFF ) if(MSVC) if(CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreaded" OR CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebug") set(CAPSTONE_CMAKE_ARGS ${CAPSTONE_CMAKE_ARGS} -DCAPSTONE_BUILD_STATIC_RUNTIME=ON) else() set(CAPSTONE_CMAKE_ARGS ${CAPSTONE_CMAKE_ARGS} -DCAPSTONE_BUILD_STATIC_RUNTIME=OFF) endif() # Hack: remove hardcoded /MT and /MTd flags from the Capstone v4 CMakeLists.txt # This way, it will respect CMAKE_MSVC_RUNTIME_LIBRARY and CAPSTONE_BUILD_STATIC_RUNTIME set(CAPSTONE_CMAKELISTS "${CAPSTONE_DIR}/CMakeLists.txt") file(LOCK "${CAPSTONE_CMAKELISTS}.lock" TIMEOUT 10) file(READ "${CAPSTONE_CMAKELISTS}" CAPSTONE_CMAKELISTS_CONTENTS) string(REPLACE "\"\${CMAKE_CXX_FLAGS_RELEASE} /MT\"" "\"\${CMAKE_CXX_FLAGS_RELEASE}\"" CAPSTONE_CMAKELISTS_CONTENTS "${CAPSTONE_CMAKELISTS_CONTENTS}") string(REPLACE "\"\${CMAKE_CXX_FLAGS_DEBUG} /MTd\"" "\"\${CMAKE_CXX_FLAGS_DEBUG}\"" CAPSTONE_CMAKELISTS_CONTENTS "${CAPSTONE_CMAKELISTS_CONTENTS}") file(WRITE "${CAPSTONE_CMAKELISTS}" "${CAPSTONE_CMAKELISTS_CONTENTS}") file(LOCK "${CAPSTONE_CMAKELISTS}.lock" RELEASE) else() set(CAPSTONE_CMAKE_ARGS ${CAPSTONE_CMAKE_ARGS} -DCAPSTONE_BUILD_STATIC_RUNTIME=OFF) endif() set(CAPSTONE_CMAKE_ARGS ${CAPSTONE_CMAKE_ARGS} -DCAPSTONE_ARM_SUPPORT=ON -DCAPSTONE_ARM64_SUPPORT=ON -DCAPSTONE_MIPS_SUPPORT=ON -DCAPSTONE_X86_SUPPORT=ON -DCAPSTONE_PPC_SUPPORT=ON -DCAPSTONE_SPARC_SUPPORT=ON -DCAPSTONE_SYSZ_SUPPORT=ON) ExternalProject_Add(capstone-engine SOURCE_DIR ${CAPSTONE_DIR} INSTALL_COMMAND "" CMAKE_ARGS ${CAPSTONE_CMAKE_ARGS}) ``` -------------------------------- ### Build Target Executable Source: https://github.com/rdbo/libmem/blob/master/tests/CMakeLists.txt Configures and builds the 'target' executable. This executable is linked against the 'libmem' library and includes the project's public header directories. ```cmake set(TARGET_SRC "${TESTS_DIR}/target.c") add_executable(target ${TARGET_SRC}) target_include_directories(target PUBLIC ${LIBMEM_INC} ) target_link_libraries(target libmem) ``` -------------------------------- ### Compile libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Commands to compile the libmem library on different operating systems. Uses 'nmake' on Windows and 'make -j' on Unix-like systems. ```bash # Windows: nmake # Unix-like: make -j 4 ``` -------------------------------- ### Configure Keystone Engine Source: https://github.com/rdbo/libmem/blob/master/external/CMakeLists.txt Sets CMake arguments for building the Keystone engine. This includes options for building libraries only, build type, compiler flags, MSVC runtime library settings, and position-independent code. It also configures LLVM targets to build and handles MSVC-specific runtime library configurations. ```cmake set(KEYSTONE_CMAKE_ARGS -DBUILD_LIBS_ONLY=1 -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY} -DCMAKE_POSITION_INDEPENDENT_CODE=ON ) if(MSVC) string(TOUPPER "LLVM_USE_CRT_${CMAKE_BUILD_TYPE}" LLVM_USE_CRT_VAR) if(CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreaded") set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -DKEYSTONE_BUILD_STATIC_RUNTIME=ON) set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -D${LLVM_USE_CRT_VAR}=MT) elseif(CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebug") set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -DKEYSTONE_BUILD_STATIC_RUNTIME=ON) set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -D${LLVM_USE_CRT_VAR}=MTd) elseif(CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDLL") set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -DKEYSTONE_BUILD_STATIC_RUNTIME=OFF) set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -D${LLVM_USE_CRT_VAR}=MD) elseif(CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebugDLL") set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -DKEYSTONE_BUILD_STATIC_RUNTIME=OFF) set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -D${LLVM_USE_CRT_VAR}=MDd) else() set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -DKEYSTONE_BUILD_STATIC_RUNTIME=OFF) endif() else () set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -DKEYSTONE_BUILD_STATIC_RUNTIME=OFF) endif() set(KEYSTONE_LLVM_TARGETS "AArch64 ARM Mips PowerPC Sparc SystemZ X86") set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -DLLVM_TARGETS_TO_BUILD=${KEYSTONE_LLVM_TARGETS}) ExternalProject_Add(keystone-engine SOURCE_DIR ${KEYSTONE_DIR} INSTALL_COMMAND "" CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS}) ``` -------------------------------- ### Hook Function in C/C++ using libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Provides an example of hooking a function in C/C++ using libmem. It demonstrates finding a module, locating a function's address by symbol name, and then applying a code hook to redirect execution to a custom handler function. ```c #include void hk_take_damage(int amount) { printf("hooked take_damage! no damage will be taken\n"); return; } int main() { lm_module_t game_mod; lm_address_t fn_take_damage; LM_FindModule("game.dll", &game_mod); printf("[*] Base address of 'game.dll': %p\n", game_mod.base); fn_take_damage = LM_FindSymbolAddress(&game_mod, "take_damage"); printf("[*] Found 'take_damage' function: %p\n", fn_take_damage); LM_HookCode(fn_take_damage, hk_take_damage, LM_NULLPTR); printf("[*] 'take_damage' hooked, player will no longer receive damage\n"); return 0; } ``` -------------------------------- ### Include libmem Header Files (C/C++) Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Demonstrates how to include the necessary libmem header files in C or C++ source code. ```c #include /* C/C++ */ ``` ```c++ #include /* Force C++ */ ``` -------------------------------- ### Compile libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Commands to compile the libmem library on different operating systems. Uses 'nmake' on Windows and 'make -j' on Unix-like systems. ```bash # Windows: nmake # Unix-like: make -j 4 ``` -------------------------------- ### Include libmem Header Files (C/C++) Source: https://github.com/rdbo/libmem/blob/master/README.md Demonstrates how to include the necessary libmem header files in C or C++ source code. ```c #include /* C/C++ */ ``` ```c++ #include /* Force C++ */ ``` -------------------------------- ### Include libmem Header Files (C/C++) Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Demonstrates how to include the necessary libmem header files in C or C++ source code. ```c #include /* C/C++ */ ``` ```c++ #include /* Force C++ */ ``` -------------------------------- ### Build libtest Shared Library Source: https://github.com/rdbo/libmem/blob/master/tests/CMakeLists.txt Configures and builds the 'libtest' shared library. It specifies the source file and sets public include directories. The prefix is also removed for cleaner naming. ```cmake set(LIBTEST_SRC "${TESTS_DIR}/libtest.c") set(LIBTEST_PATH "${PROJECT_BINARY_DIR}/tests/libtest${CMAKE_SHARED_LIBRARY_SUFFIX}") cmake_path(NATIVE_PATH LIBTEST_PATH LIBTEST_PATH) string(REPLACE \\ \\\\ LIBTEST_PATH "${LIBTEST_PATH}") add_library(libtest SHARED ${LIBTEST_SRC}) target_include_directories(libtest PUBLIC ${LIBMEM_INC} ) set_target_properties(libtest PROPERTIES PREFIX "") ``` -------------------------------- ### Add LLVM Demangle Component Library Source: https://github.com/rdbo/libmem/blob/master/external/llvm/lib/Demangle/CMakeLists.txt This CMake snippet demonstrates how to add the LLVM Demangle component library. It lists the necessary C++ source files and specifies the additional header directories required for the demangling functionality. ```cmake add_llvm_component_library(LLVMDemangle Demangle.cpp ItaniumDemangle.cpp MicrosoftDemangle.cpp MicrosoftDemangleNodes.cpp RustDemangle.cpp DLangDemangle.cpp ADDITIONAL_HEADER_DIRS "${LLVM_MAIN_INCLUDE_DIR}/llvm/Demangle" ) ``` -------------------------------- ### Rust Dependency for libmem Source: https://github.com/rdbo/libmem/blob/master/README.md Shows how to add libmem as a dependency in a Rust project's Cargo.toml file and import it into the source code. ```toml [dependencies] libmem = "5" ``` ```rust use libmem::*; ``` -------------------------------- ### Generate CMake Cache Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Steps to create a build directory, navigate into it, and generate the CMake cache for libmem with Release build type and compile commands export. ```bash mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ``` -------------------------------- ### Clone libmem Repository Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem-sys/README.md Command to clone the libmem source code repository using Git, including submodules, with a shallow clone for efficiency. ```bash git clone --recursive --depth 1 https://github.com/rdbo/libmem ``` -------------------------------- ### Generate CMake Cache Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Steps to create a build directory, navigate into it, and generate the CMake cache for libmem with Release build type and compile commands export. ```bash mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ``` -------------------------------- ### Compile libmem Source: https://github.com/rdbo/libmem/blob/master/README.md Commands to compile the libmem library on different operating systems. Uses 'nmake' on Windows and 'make -j' on Unix-like systems. ```bash # Windows: nmake # Unix-like: make -j 4 ``` -------------------------------- ### Create Branch and Push Changes Source: https://github.com/rdbo/libmem/blob/master/CONTRIBUTING.md Creates a new local branch for your changes and pushes it to the remote repository. This is essential for submitting a pull request. ```bash git checkout -b your-branch-name ``` ```bash git push origin your-branch-name ``` -------------------------------- ### Compile libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Commands to compile the libmem library on different operating systems. Uses 'nmake' on Windows and 'make -j' on Unix-like systems. ```bash # Windows: nmake # Unix-like: make -j 4 ``` -------------------------------- ### Generate CMake Cache Source: https://github.com/rdbo/libmem/blob/master/README.md Steps to create a build directory, navigate into it, and generate the CMake cache for libmem with Release build type and compile commands export. ```bash mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ``` -------------------------------- ### Clone libmem Repository Source: https://github.com/rdbo/libmem/blob/master/bindings/rust/libmem/README.md Command to clone the libmem source code repository using Git, including submodules, with a shallow clone for efficiency. ```bash git clone --recursive --depth 1 https://github.com/rdbo/libmem ``` -------------------------------- ### Importing External Static Libraries Source: https://github.com/rdbo/libmem/blob/master/CMakeLists.txt Imports external static libraries (capstone, keystone) into the build system. It uses `add_library(IMPORTED)` and `set_target_properties` to specify the location of the pre-built static libraries. ```CMake add_subdirectory("${EXTERNAL_DEPENDENCIES_DIR}") add_library(capstone STATIC IMPORTED) set_target_properties(capstone PROPERTIES IMPORTED_LOCATION ${CAPSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}capstone${CMAKE_STATIC_LIBRARY_SUFFIX}) add_library(keystone STATIC IMPORTED) set_target_properties(keystone PROPERTIES IMPORTED_LOCATION ${KEYSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}keystone${CMAKE_STATIC_LIBRARY_SUFFIX}) ``` -------------------------------- ### Clone libmem Repository Source: https://github.com/rdbo/libmem/blob/master/README.md Command to clone the libmem source code repository using Git, including submodules, with a shallow clone for efficiency. ```bash git clone --recursive --depth 1 https://github.com/rdbo/libmem ``` -------------------------------- ### Clone libmem Repository Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Command to clone the libmem source code repository using Git, including submodules, with a shallow clone for efficiency. ```bash git clone --recursive --depth 1 https://github.com/rdbo/libmem ``` -------------------------------- ### Rust Dependency for libmem Source: https://github.com/rdbo/libmem/blob/master/bindings/python/README.md Shows how to add libmem as a dependency in a Rust project's Cargo.toml file and import it into the source code. ```toml [dependencies] libmem = "5" ``` ```rust use libmem::*; ```