From 17702356489256887a2082d93a7865eab12d2df8 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 15 Dec 2021 23:28:47 +0100 Subject: [PATCH] build: Build and statically link capstone to work around Ubuntu issues Sigh... --- .gitmodules | 3 +++ external/capstone | 1 + plugins/builtin/CMakeLists.txt | 3 --- .../content/views/view_disassembler.hpp | 7 ++++++- plugins/libimhex/CMakeLists.txt | 19 ++++++++++++++++--- .../include/hex/helpers/disassembler.hpp | 6 +++++- 6 files changed, 31 insertions(+), 8 deletions(-) create mode 160000 external/capstone diff --git a/.gitmodules b/.gitmodules index 3568d9516..519530f1f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -18,3 +18,6 @@ path = external/curl url = https://github.com/curl/curl ignore = dirty +[submodule "external/capstone"] + path = external/capstone + url = https://github.com/capstone-engine/capstone diff --git a/external/capstone b/external/capstone new file mode 160000 index 000000000..68102c05f --- /dev/null +++ b/external/capstone @@ -0,0 +1 @@ +Subproject commit 68102c05f1c55eeed1035e7ab2638181e872c162 diff --git a/plugins/builtin/CMakeLists.txt b/plugins/builtin/CMakeLists.txt index 7a3715a99..65a9264bf 100644 --- a/plugins/builtin/CMakeLists.txt +++ b/plugins/builtin/CMakeLists.txt @@ -54,9 +54,6 @@ add_library(${PROJECT_NAME} SHARED target_include_directories(${PROJECT_NAME} PRIVATE include) # Add additional libraries here # -find_package(PkgConfig REQUIRED) -pkg_search_module(CAPSTONE 4.0.2 REQUIRED capstone) - target_link_libraries(${PROJECT_NAME} PRIVATE libimhex LLVMDemangle capstone) # ---- No need to change anything from here downwards unless you know what you're doing ---- # diff --git a/plugins/builtin/include/content/views/view_disassembler.hpp b/plugins/builtin/include/content/views/view_disassembler.hpp index f9ec0063f..8641d8528 100644 --- a/plugins/builtin/include/content/views/view_disassembler.hpp +++ b/plugins/builtin/include/content/views/view_disassembler.hpp @@ -37,7 +37,12 @@ namespace hex::plugin::builtin { bool m_shouldMatchSelection = false; Architecture m_architecture = Architecture::ARM; - cs_mode m_modeBasicARM = cs_mode(0), m_modeExtraARM = cs_mode(0), m_modeBasicMIPS = cs_mode(0), m_modeBasicPPC = cs_mode(0), m_modeBasicX86 = cs_mode(0); + cs_mode m_modeBasicARM = cs_mode(0); + cs_mode m_modeExtraARM = cs_mode(0); + cs_mode m_modeBasicMIPS = cs_mode(0); + cs_mode m_modeBasicPPC = cs_mode(0); + cs_mode m_modeBasicX86 = cs_mode(0); + bool m_littleEndianMode = true, m_micoMode = false, m_sparcV9Mode = false; std::vector m_disassembly; diff --git a/plugins/libimhex/CMakeLists.txt b/plugins/libimhex/CMakeLists.txt index dfd91d608..64a5f72ce 100644 --- a/plugins/libimhex/CMakeLists.txt +++ b/plugins/libimhex/CMakeLists.txt @@ -17,7 +17,7 @@ set(FPHSA_NAME_MISMATCHED ON CACHE BOOL "") find_package(PkgConfig REQUIRED) if(NOT USE_SYSTEM_NLOHMANN_JSON) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/nlohmann_json ${CMAKE_CURRENT_BINARY_DIR}/external/nlohmann_json) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/nlohmann_json ${CMAKE_CURRENT_BINARY_DIR}/external/nlohmann_json EXCLUDE_FROM_ALL) set(NLOHMANN_JSON_LIBRARIES nlohmann_json) else() find_package(nlohmann_json 3.10.2 REQUIRED) @@ -25,7 +25,7 @@ else() endif() if(NOT USE_SYSTEM_FMT) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/fmt ${CMAKE_CURRENT_BINARY_DIR}/external/fmt) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/fmt ${CMAKE_CURRENT_BINARY_DIR}/external/fmt EXCLUDE_FROM_ALL) set(FMT_LIBRARIES fmt-header-only) else() find_package(fmt 8.0.0 REQUIRED) @@ -55,6 +55,19 @@ else() pkg_check_modules(YARA REQUIRED IMPORTED_TARGET yara) endif() +if (NOT USE_SYSTEM_CAPSTONE) + set(CAPSTONE_BUILD_STATIC_RUNTIME OFF) + set(CAPSTONE_BUILD_SHARED OFF) + set(CAPSTONE_BUILD_TESTS OFF) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/capstone ${CMAKE_CURRENT_BINARY_DIR}/external/capstone EXCLUDE_FROM_ALL) + set(CAPSTONE_LIBRARIES capstone-static) +else() + find_package(PkgConfig REQUIRED) + pkg_search_module(CAPSTONE 4.0.2 REQUIRED capstone) +endif() + + + find_package(mbedTLS 2.26.0 REQUIRED) configurePython() @@ -134,4 +147,4 @@ if (APPLE) target_link_libraries(libimhex PUBLIC ${FOUNDATION}) endif () -target_link_libraries(libimhex PUBLIC imgui nfd magic capstone LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${FMT_LIBRARIES} ${Python_LIBRARIES}) +target_link_libraries(libimhex PUBLIC imgui nfd magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${FMT_LIBRARIES} ${Python_LIBRARIES}) diff --git a/plugins/libimhex/include/hex/helpers/disassembler.hpp b/plugins/libimhex/include/hex/helpers/disassembler.hpp index 03f6a8bcd..d6465ce7f 100644 --- a/plugins/libimhex/include/hex/helpers/disassembler.hpp +++ b/plugins/libimhex/include/hex/helpers/disassembler.hpp @@ -22,6 +22,10 @@ namespace hex { TMS320C64X, M680X, EVM, + MOS65XX, + WASM, + BPF, + RISCV, MAX, MIN = ARM @@ -37,7 +41,7 @@ namespace hex { return cs_support(toCapstoneArchictecture(architecture)); } - constexpr static const char * const ArchitectureNames[] = { "ARM32", "ARM64", "MIPS", "x86", "PowerPC", "Sparc", "SystemZ", "XCore", "68K", "TMS320C64x", "680X", "Ethereum" }; + constexpr static const char * const ArchitectureNames[] = { "ARM32", "ARM64", "MIPS", "x86", "PowerPC", "Sparc", "SystemZ", "XCore", "68K", "TMS320C64x", "680X", "Ethereum", "MOS65XX", "WebAssembly", "Berkeley Packet Filter", "RISC-V" }; static inline s32 getArchitectureSupportedCount() { static s32 supportedCount = -1;