From e7041e1ef6f61ef01cee0eed90308930258ba457 Mon Sep 17 00:00:00 2001 From: "Matthias C. M. Troffaes" Date: Tue, 2 Jun 2020 02:57:11 +0100 Subject: [polyhook2] Update to 2020-05-25 (#11561) * [polyhook2] Update to 2020-05-25 - Update to latest PolyHook_2 revision. - Add support for zydis and inlinentd as features (enabled by default, as per upstream default). - Support for capstone, exception, detours, and pe is now configurable via features (all enabled by default, as per upstream default). - Remove cmake build patch. Relevant parts have been upstreamed. - For now, remove tool feature for building tests, as upstream does not support building tests along with building the library. - Add support for cmake config so library can be used simply with "find_package(PolyHook_2 CONFIG REQUIRE)". * [polyhook2] package does not support arm, uwp, linux, and osx Co-authored-by: NancyLi1013 <46708020+NancyLi1013@users.noreply.github.com> Co-authored-by: NancyLi1013 <46708020+NancyLi1013@users.noreply.github.com> --- ports/polyhook2/CONTROL | 28 ++++++- ports/polyhook2/fix-build-error.patch | 135 ---------------------------------- ports/polyhook2/portfile.cmake | 39 ++++++---- 3 files changed, 49 insertions(+), 153 deletions(-) delete mode 100644 ports/polyhook2/fix-build-error.patch diff --git a/ports/polyhook2/CONTROL b/ports/polyhook2/CONTROL index e238aa954..6253a362b 100644 --- a/ports/polyhook2/CONTROL +++ b/ports/polyhook2/CONTROL @@ -1,8 +1,30 @@ Source: polyhook2 -Version: 2020-02-17 +Version: 2020-05-25 Homepage: https://github.com/stevemk14ebr/PolyHook_2_0 Description: C++17, x86/x64 Hooking Libary v2.0 +Supports: !(arm|uwp|linux|osx) +Default-Features: capstone,zydis,exception,detours,inlinentd,pe,virtuals + +Feature: capstone Build-Depends: capstone[x86] +Description: Capstone disassembler integration. + +Feature: zydis +Build-Depends: zydis +Description: Zydis disassembler integration. + +Feature: exception +Description: Implement all exception hooking functionality + +Feature: detours +Description: Implement detour functionality + +Feature: inlinentd +Build-Depends: asmjit +Description: Support inline hooks without specifying typedefs by generating callback stubs at runtime with AsmJit + +Feature: pe +Description: Implement all win pe hooking functionality -Feature: tool -Description: Build tests \ No newline at end of file +Feature: virtuals +Description: Implement all virtual table hooking functionality diff --git a/ports/polyhook2/fix-build-error.patch b/ports/polyhook2/fix-build-error.patch deleted file mode 100644 index 1366d6816..000000000 --- a/ports/polyhook2/fix-build-error.patch +++ /dev/null @@ -1,135 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 2577bb2..e88761c 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -12,18 +12,19 @@ option(FEATURE_PE "Implement all win pe hooking functionality" ON) - option(BUILD_DLL "Build dll & lib instead of tests" OFF) - option(BUILD_STATIC "If BUILD_DLL is set, create the type that can be statically linked" ON) - option(CAPSTONE_FULL "Build all features of capstone." OFF) -+option(BUILD_TOOLS "Build tests" OFF) - - # Calculate inclusion of necessary dependencies based on features - - # for now only inlinentd uses asmjit - set(DEP_ASMJIT_NEED ${FEATURE_INLINENTD}) --set(DEP_ZYDIS_NEED ON) -+set(DEP_ZYDIS_NEED OFF) - # todo: make inclusion of capstone stuff depend on feature flags - - #IDE's like it when header file are included as source files - set(HEADER_FILES ${PROJECT_SOURCE_DIR}/polyhook2/ADisassembler.hpp - ${PROJECT_SOURCE_DIR}/polyhook2/CapstoneDisassembler.hpp -- ${PROJECT_SOURCE_DIR}/polyhook2/ZydisDisassembler.hpp -+# ${PROJECT_SOURCE_DIR}/polyhook2/ZydisDisassembler.hpp - ${PROJECT_SOURCE_DIR}/polyhook2/Enums.hpp - ${PROJECT_SOURCE_DIR}/polyhook2/IHook.hpp - ${PROJECT_SOURCE_DIR}/polyhook2/Instruction.hpp -@@ -35,13 +36,13 @@ set(HEADER_FILES ${PROJECT_SOURCE_DIR}/polyhook2/ADisassembler.hpp - - set(HEADER_IMP_SOURCES - ${PROJECT_SOURCE_DIR}/sources/CapstoneDisassembler.cpp -- ${PROJECT_SOURCE_DIR}/sources/ZydisDisassembler.cpp -+# ${PROJECT_SOURCE_DIR}/sources/ZydisDisassembler.cpp - ${PROJECT_SOURCE_DIR}/sources/MemProtector.cpp - ${PROJECT_SOURCE_DIR}/sources/TestEffectTracker.cpp - ${PROJECT_SOURCE_DIR}/sources/PageAllocator.cpp) - - # only build tests if making exe --if(BUILD_DLL MATCHES OFF) -+if(BUILD_TOOLS) - set(UNIT_TEST_SOURCES - ${PROJECT_SOURCE_DIR}/MainTests.cpp - ${PROJECT_SOURCE_DIR}/UnitTests/TestDisassembler.cpp -@@ -65,7 +66,7 @@ if(FEATURE_DETOURS MATCHES ON) - set(HEADER_IMP_SOURCES ${HEADER_IMP_SOURCES} ${DETOUR_IMP_SOURCES}) - - # only build tests if making exe -- if(BUILD_DLL MATCHES OFF) -+ if(BUILD_TOOLS) - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - # 64 bits - set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} -@@ -93,7 +94,7 @@ if(FEATURE_EXCEPTION MATCHES ON) - set(HEADER_IMP_SOURCES ${HEADER_IMP_SOURCES} ${EXCEPTION_IMP_SOURCES}) - - # only build tests if making exe -- if(BUILD_DLL MATCHES OFF) -+ if(BUILD_TOOLS) - set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} - ${PROJECT_SOURCE_DIR}/UnitTests/TestBreakpointHook.cpp - ${PROJECT_SOURCE_DIR}/UnitTests/TestHWBreakpointHook.cpp) -@@ -113,7 +114,7 @@ if(FEATURE_VIRTUALS MATCHES ON) - set(HEADER_IMP_SOURCES ${HEADER_IMP_SOURCES} ${VIRTUAL_IMP_SOURCES}) - - # only build tests if making exe -- if(BUILD_DLL MATCHES OFF) -+ if(BUILD_TOOLS) - set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} - ${PROJECT_SOURCE_DIR}/UnitTests/TestVTableSwapHook.cpp - ${PROJECT_SOURCE_DIR}/UnitTests/TestVFuncSwapHook.cpp) -@@ -134,7 +135,7 @@ if(FEATURE_PE MATCHES ON) - set(HEADER_IMP_SOURCES ${HEADER_IMP_SOURCES} ${PE_IMP_SOURCES}) - - # only build tests if making exe -- if(BUILD_DLL MATCHES OFF) -+ if(BUILD_TOOLS) - set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} - ${PROJECT_SOURCE_DIR}/UnitTests/TestEatHook.cpp - ${PROJECT_SOURCE_DIR}/UnitTests/TestIatHook.cpp) -@@ -152,7 +153,7 @@ if(FEATURE_INLINENTD MATCHES ON) - set(HEADER_IMP_SOURCES ${HEADER_IMP_SOURCES} ${NTD_SOURCES}) - - # only build tests if making exe -- if(BUILD_DLL MATCHES OFF) -+ if(BUILD_TOOLS) - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - # 64 bits - set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} -@@ -175,8 +176,10 @@ if(BUILD_DLL MATCHES ON) - else() - add_library(PolyHook_2 SHARED ${SOURCE_FILES_PLH}) - endif() --else() -- add_executable(PolyHook_2 ${SOURCE_FILES_PLH}) -+endif() -+ -+if(BUILD_TOOLS) -+ add_executable(PolyHook2_tool ${SOURCE_FILES_PLH}) - endif() - - # add WALL + PDB flags -@@ -220,8 +223,16 @@ if(NOT ${CAPSTONE_FULL}) - set(CAPSTONE_EVM_SUPPORT OFF CACHE BOOL "EVM support") - endif() - --add_subdirectory(capstone) --target_link_libraries(${PROJECT_NAME} capstone-static) -+find_library(CAPSTONE_LIBRARY NAMES capstone_dll capstone) -+find_path(CAPSTONE_INCLUDE_DIR NAMES capstone/capstone.h) -+target_link_libraries(${PROJECT_NAME} ${CAPSTONE_LIBRARY}) -+target_include_directories(${PROJECT_NAME} PRIVATE ${CAPSTONE_INCLUDE_DIR}) -+ -+if(BUILD_TOOLS) -+ target_link_libraries(PolyHook2_tool ${CAPSTONE_LIBRARY}) -+ target_include_directories(PolyHook2_tool PRIVATE ${CAPSTONE_INCLUDE_DIR}) -+ install(TARGETS PolyHook2_tool DESTINATION tool) -+endif() - - # ASMJIT - if(DEP_ASMJIT_NEED MATCHES ON) -diff --git a/polyhook2/CapstoneDisassembler.hpp b/polyhook2/CapstoneDisassembler.hpp -index d227b30..bb5d222 100644 ---- a/polyhook2/CapstoneDisassembler.hpp -+++ b/polyhook2/CapstoneDisassembler.hpp -@@ -7,7 +7,7 @@ - - #include "polyhook2/ADisassembler.hpp" - --#include -+#include - - #include - #include //for debug printing --- -2.25.0.windows.1 - diff --git a/ports/polyhook2/portfile.cmake b/ports/polyhook2/portfile.cmake index b001d26dd..d10129e31 100644 --- a/ports/polyhook2/portfile.cmake +++ b/ports/polyhook2/portfile.cmake @@ -3,30 +3,42 @@ vcpkg_fail_port_install(ON_ARCH "arm" "arm64" ON_TARGET "Linux" "OSX" "UWP") vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO stevemk14ebr/PolyHook_2_0 - REF 157112f7991768eef51f262486d59c02f18413dc - SHA512 3e8919e5a5a66db29848737b2b90bef57e97b55f516b78518abeb004fbdd2c7a3c99c26753024a8f0be5accc830ded8065f473f1d67f7e033ee419626f4212fe + REF 0f47489c8c27d5be67aa608cfd7304c674ac4ef1 + SHA512 9e1945638479e942dba3d524b64a3ad7d8bff156d2be1fa55a1715f962da54d46995876b1c60c189918c232d70a031d382b3d8cda36e5f9c7951f31bcdc9cd19 HEAD_REF master - PATCHES - fix-build-error.patch ) vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS - tool BUILD_TOOLS + capstone POLYHOOK_DISASM_CAPSTONE + zydis POLYHOOK_DISASM_ZYDIS + exception POLYHOOK_FEATURE_EXCEPTION + detours POLYHOOK_FEATURE_DETOURS + inlinentd POLYHOOK_FEATURE_INLINENTD + pe POLYHOOK_FEATURE_PE + virtuals POLYHOOK_FEATURE_VIRTUALS ) if (VCPKG_LIBRARY_LINKAGE STREQUAL "static") - set(BUILD_STATIC ON) + set(BUILD_SHARED_LIB OFF) else() - set(BUILD_STATIC OFF) + set(BUILD_SHARED_LIB ON) +endif() + +if (VCPKG_CRT_LINKAGE STREQUAL "static") + set(BUILD_STATIC_RUNTIME ON) +else() + set(BUILD_STATIC_RUNTIME OFF) endif() vcpkg_configure_cmake( SOURCE_PATH ${SOURCE_PATH} PREFER_NINJA OPTIONS ${FEATURE_OPTIONS} - -DFEATURE_INLINENTD=OFF - -DBUILD_DLL=ON - -DBUILD_STATIC=${BUILD_STATIC} + -DPOLYHOOK_BUILD_SHARED_LIB=${BUILD_SHARED_LIB} + -DPOLYHOOK_BUILD_STATIC_RUNTIME=${BUILD_STATIC_RUNTIME} + -DPOLYHOOK_USE_EXTERNAL_ASMJIT=ON + -DPOLYHOOK_USE_EXTERNAL_CAPSTONE=ON + -DPOLYHOOK_USE_EXTERNAL_ZYDIS=ON ) vcpkg_install_cmake() @@ -34,10 +46,7 @@ vcpkg_install_cmake() file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) vcpkg_copy_pdbs() - -if(VCPKG_LIBRARY_LINKAGE STREQUAL static) - file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin) -endif() +vcpkg_fixup_cmake_targets(CONFIG_PATH lib/PolyHook_2 TARGET_PATH share/PolyHook_2) # Handle copyright -file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) \ No newline at end of file +file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) -- cgit v1.2.3