Skip to content

Commit

Permalink
minhook: add minhook/1.3.3 recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jan 9, 2024
1 parent edf1c5a commit f7f178b
Show file tree
Hide file tree
Showing 8 changed files with 432 additions and 0 deletions.
13 changes: 13 additions & 0 deletions recipes/minhook/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sources:
"1.3.3":
url: "https://github.com/TsudaKageyu/minhook/archive/refs/tags/v1.3.3.tar.gz"
sha256: "5bec16358ec9086d4593124bf558635e89135abea2c76e5761ecaf09f4546b19"
patches:
"1.3.3":
- patch_file: "patches/0001-add-cmake-support-1.3.3.patch"
patch_description: "Add CMake support"
patch_type: "official"
patch_source: "https://github.com/TsudaKageyu/minhook/commit/3f2e34976c1685ee372a09f54c0c8c8f4240ef90"
- patch_file: "patches/0002-increase-cmake-min-1.3.3.patch"
patch_description: "Increase cmake_minimum_required version to 3.5"
patch_type: "conan"
89 changes: 89 additions & 0 deletions recipes/minhook/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir

required_conan_version = ">=1.53.0"


class PackageConan(ConanFile):
name = "minhook"
description = "The Minimalistic x86/x64 API Hooking Library for Windows"
license = "BSD-2-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/TsudaKageyu/minhook"
topics = ("hook", "windows")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
# minhook is a plain C projects
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def layout(self):
cmake_layout(self, src_folder="src")

def validate(self):
if self.settings.os != "Windows":
raise ConanInvalidConfiguration(f"{self.ref} can only be built on Windows.")

if self.settings.arch not in ["x86", "x86_64"]:
raise ConanInvalidConfiguration(f"{self.ref} can only be built on x86 or x86_64 architectures.")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()

def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "LICENSE.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

rmdir(self, os.path.join(self.package_folder, "lib", "minhook"))

def package_info(self):
if self.settings.arch == "x86_64":
postfix = ".x64d" if self.settings.build_type == "Debug" else ".x64"
else:
postfix = ".x32d" if self.settings.build_type == "Debug" else ".x32"

self.cpp_info.libs = [f"minhook{postfix}"]
self.cpp_info.set_property("cmake_file_name", "minhook")
self.cpp_info.set_property("cmake_target_name", "minhook::minhook")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "minhook"
self.cpp_info.filenames["cmake_find_package_multi"] = "minhook"
self.cpp_info.names["cmake_find_package"] = "minhook"
self.cpp_info.names["cmake_find_package_multi"] = "minhook"
204 changes: 204 additions & 0 deletions recipes/minhook/all/patches/0001-add-cmake-support-1.3.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
From 3f2e34976c1685ee372a09f54c0c8c8f4240ef90 Mon Sep 17 00:00:00 2001
From: Mikhail Paulyshka <me@mixaill.tk>
Date: Sun, 5 Nov 2017 16:50:31 +0300
Subject: [PATCH] Add CMake support

---
CMakeLists.txt | 141 ++++++++++++++++++++++++++++++++++
cmake/minhook-config.cmake.in | 39 ++++++++++
2 files changed, 180 insertions(+)
create mode 100644 CMakeLists.txt
create mode 100644 cmake/minhook-config.cmake.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..df947af
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,141 @@
+# MinHook - The Minimalistic API Hooking Library for x64/x86
+# Copyright (C) 2009-2017 Tsuda Kageyu.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
+# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+cmake_minimum_required(VERSION 3.0)
+
+project(minhook LANGUAGES C)
+
+include(CMakePackageConfigHelpers)
+
+set(MINHOOK_MAJOR_VERSION 1)
+set(MINHOOK_MINOR_VERSION 3)
+set(MINHOOK_PATCH_VERSION 3)
+set(MINHOOK_VERSION ${MINHOOK_MAJOR_VERSION}.${MINHOOK_MINOR_VERSION}.${MINHOOK_PATCH_VERSION})
+
+################
+# BUILD #
+################
+
+option(BUILD_SHARED_LIBS "build shared version" OFF)
+
+set(SOURCES_MINHOOK
+ "src/buffer.c"
+ "src/hook.c"
+ "src/trampoline.c"
+)
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(SOURCES_HDE "src/hde/hde64.c")
+else()
+ set(SOURCES_HDE "src/hde/hde32.c")
+endif()
+
+if(BUILD_SHARED_LIBS)
+ set(RESOURCES
+ "dll_resources/minhook.rc"
+ "dll_resources/minhook.def"
+ )
+endif()
+
+add_library(minhook ${SOURCES_MINHOOK} ${SOURCES_HDE} ${RESOURCES})
+
+target_include_directories(minhook PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
+ $<INSTALL_INTERFACE:include>
+)
+
+target_include_directories(minhook PRIVATE "src/")
+target_include_directories(minhook PRIVATE "src/hde/")
+
+if(WIN32)
+ set_target_properties(minhook PROPERTIES PREFIX "")
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set_target_properties(minhook PROPERTIES DEBUG_POSTFIX ".x64d")
+ set_target_properties(minhook PROPERTIES RELEASE_POSTFIX ".x64")
+ set_target_properties(minhook PROPERTIES RELWITHDEBINFO_POSTFIX ".x64")
+ set_target_properties(minhook PROPERTIES MINSIZEREL_POSTFIX ".x64")
+ else()
+ set_target_properties(minhook PROPERTIES DEBUG_POSTFIX ".x32d")
+ set_target_properties(minhook PROPERTIES RELEASE_POSTFIX ".x32")
+ set_target_properties(minhook PROPERTIES RELWITHDEBINFO_POSTFIX ".x32")
+ set_target_properties(minhook PROPERTIES MINSIZEREL_POSTFIX ".x64")
+ endif()
+else()
+ set_target_properties(minhook PROPERTIES PREFIX "lib")
+ set_target_properties(minhook PROPERTIES POSTFIX "")
+ set_target_properties(minhook PROPERTIES DEBUG_POSTFIX "d")
+endif()
+
+################
+# CMAKE CONFIG #
+################
+
+configure_package_config_file(
+ "cmake/minhook-config.cmake.in"
+ "minhook-config.cmake"
+ INSTALL_DESTINATION
+ "lib/minhook"
+)
+
+write_basic_package_version_file(
+ "minhook-config-version.cmake"
+VERSION
+ ${MINHOOK_VERSION}
+COMPATIBILITY
+ AnyNewerVersion
+)
+
+install(
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/minhook-config.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/minhook-config-version.cmake"
+ DESTINATION
+ "lib/minhook"
+)
+
+###################
+# INSTALL #
+###################
+
+install(TARGETS minhook
+ EXPORT minhook-targets
+ RUNTIME DESTINATION "bin"
+ ARCHIVE DESTINATION "lib"
+ LIBRARY DESTINATION "lib"
+)
+
+install(
+ EXPORT
+ minhook-targets
+ NAMESPACE
+ minhook::
+ DESTINATION
+ "lib/minhook"
+)
+
+install(
+ DIRECTORY include DESTINATION .
+)
diff --git a/cmake/minhook-config.cmake.in b/cmake/minhook-config.cmake.in
new file mode 100644
index 0000000..14e6463
--- /dev/null
+++ b/cmake/minhook-config.cmake.in
@@ -0,0 +1,39 @@
+# MinHook - The Minimalistic API Hooking Library for x64/x86
+# Copyright (C) 2009-2017 Tsuda Kageyu.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
+# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+set(MINHOOK_MAJOR_VERSION "@MINHOOK_MAJOR_VERSION@")
+set(MINHOOK_MINOR_VERSION "@MINHOOK_MINOR_VERSION@")
+set(MINHOOK_PATCH_VERSION "@MINHOOK_PATCH_VERSION@")
+set(MINHOOK_VERSION "@MINHOOK_VERSION@")
+
+@PACKAGE_INIT@
+
+set(MINHOOK_FOUND ON)
+
+set_and_check(MINHOOK_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/")
+set_and_check(MINHOOK_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/lib")
+
+include("${PACKAGE_PREFIX_DIR}/lib/minhook/minhook-targets.cmake")
13 changes: 13 additions & 0 deletions recipes/minhook/all/patches/0002-increase-cmake-min-1.3.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d45414e..533dac6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,7 +24,7 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-cmake_minimum_required(VERSION 3.0)
+cmake_minimum_required(VERSION 3.5)

project(minhook LANGUAGES C)

8 changes: 8 additions & 0 deletions recipes/minhook/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)

project(test_package LANGUAGES CXX)

find_package(minhook REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE minhook::minhook)
27 changes: 27 additions & 0 deletions recipes/minhook/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
Loading

0 comments on commit f7f178b

Please sign in to comment.