From 6789bf1bbf16c7cbcebe4e5e6b68b74aaf5b722f Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 14 Jan 2024 23:43:33 +0000 Subject: [PATCH 1/4] minhook: add minhook/cci.20240114 recipe --- recipes/minhook/all/conandata.yml | 9 ++ recipes/minhook/all/conanfile.py | 89 +++++++++++++++++++ ...cci.20240114-0001-increase-cmake-min.patch | 13 +++ .../minhook/all/test_package/CMakeLists.txt | 8 ++ recipes/minhook/all/test_package/conanfile.py | 27 ++++++ .../minhook/all/test_package/test_package.cpp | 75 ++++++++++++++++ recipes/minhook/config.yml | 3 + 7 files changed, 224 insertions(+) create mode 100644 recipes/minhook/all/conandata.yml create mode 100644 recipes/minhook/all/conanfile.py create mode 100644 recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch create mode 100644 recipes/minhook/all/test_package/CMakeLists.txt create mode 100644 recipes/minhook/all/test_package/conanfile.py create mode 100644 recipes/minhook/all/test_package/test_package.cpp create mode 100644 recipes/minhook/config.yml diff --git a/recipes/minhook/all/conandata.yml b/recipes/minhook/all/conandata.yml new file mode 100644 index 0000000000000..3199c290a83b3 --- /dev/null +++ b/recipes/minhook/all/conandata.yml @@ -0,0 +1,9 @@ +sources: + "cci.20240114": + url: "https://github.com/TsudaKageyu/minhook/archive/f5485b8454544c2f034c78f8f127c1d03dea3636.tar.gz" + sha256: "9a60e6615ddfe4ba0ef53f8589aa51acb539d617ce106ef72bfeed5a125f758b" +patches: + "cci.20240114": + - patch_file: "patches/cci.20240114-0001-increase-cmake-min.patch" + patch_description: "Increase cmake_minimum_required version to 3.5" + patch_type: "conan" diff --git a/recipes/minhook/all/conanfile.py b/recipes/minhook/all/conanfile.py new file mode 100644 index 0000000000000..28d79caddefc4 --- /dev/null +++ b/recipes/minhook/all/conanfile.py @@ -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" diff --git a/recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch b/recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch new file mode 100644 index 0000000000000..59eb03e63a555 --- /dev/null +++ b/recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch @@ -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) + diff --git a/recipes/minhook/all/test_package/CMakeLists.txt b/recipes/minhook/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..a090c65f0323b --- /dev/null +++ b/recipes/minhook/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/minhook/all/test_package/conanfile.py b/recipes/minhook/all/test_package/conanfile.py new file mode 100644 index 0000000000000..d7de1f914ce42 --- /dev/null +++ b/recipes/minhook/all/test_package/conanfile.py @@ -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") diff --git a/recipes/minhook/all/test_package/test_package.cpp b/recipes/minhook/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..95ccf7f207da6 --- /dev/null +++ b/recipes/minhook/all/test_package/test_package.cpp @@ -0,0 +1,75 @@ +#include + +#include + +#include "MinHook.h" + +typedef int(WINAPI *MESSAGEBOXW)(HWND, LPCWSTR, LPCWSTR, UINT); + +// Pointer for calling original MessageBoxW. +MESSAGEBOXW fpMessageBoxW = NULL; + +// Dummy MessageBox function for testing. +int WINAPI DummyMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType) +{ + const int box_width = 40; + std::wstring text(lpText); + std::wstring caption(lpCaption); + + // Top border + std::wcout << "+" << std::wstring(box_width - 2, '-') << "+\n"; + + // Caption + std::wcout << "| " << caption << std::wstring(box_width - 3 - caption.size(), ' ') << "|\n"; + std::wcout << "| " << std::wstring(box_width - 4, '=') << " |\n"; + + // Text + std::wcout << "| " << text << std::wstring(box_width - 3 - text.size(), ' ') << "|\n"; + + // Bottom border + std::wcout << "+" << std::wstring(box_width - 2, '-') << "+\n"; + + return IDOK; // The OK button was selected. +} + +// Detour function which overrides MessageBoxW. +int WINAPI DetourMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType) +{ + return fpMessageBoxW(hWnd, L"Hooked!", lpCaption, uType); +} + +int main() +{ + // Initialize MinHook. + if (MH_Initialize() != MH_OK) { + return 1; + } + + // Create a hook for MessageBoxW, in disabled state. + if (MH_CreateHook(&DummyMessageBoxW, &DetourMessageBoxW, reinterpret_cast(&fpMessageBoxW)) != MH_OK) { + return 1; + } + + // Enable the hook for MessageBoxW. + if (MH_EnableHook(&DummyMessageBoxW) != MH_OK) { + return 1; + } + + // Expected to tell "Hooked!". + DummyMessageBoxW(NULL, L"Not hooked...", L"MinHook Sample", MB_OK); + + // Disable the hook for MessageBoxW. + if (MH_DisableHook(&DummyMessageBoxW) != MH_OK) { + return 1; + } + + // Expected to tell "Not hooked...". + DummyMessageBoxW(NULL, L"Not hooked...", L"MinHook Sample", MB_OK); + + // Uninitialize MinHook. + if (MH_Uninitialize() != MH_OK) { + return 1; + } + + return 0; +} diff --git a/recipes/minhook/config.yml b/recipes/minhook/config.yml new file mode 100644 index 0000000000000..a5bd7eb6e490e --- /dev/null +++ b/recipes/minhook/config.yml @@ -0,0 +1,3 @@ +versions: + "cci.20240114": + folder: all From f0809765f8ac113c0aa43106b4daa2051af9942c Mon Sep 17 00:00:00 2001 From: "Vincent (Zhengyu) Wu" Date: Sun, 24 Mar 2024 21:38:11 +0000 Subject: [PATCH 2/4] Update recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch Co-authored-by: Martin Valgur --- .../all/patches/cci.20240114-0001-increase-cmake-min.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch b/recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch index 59eb03e63a555..115b9b30e358f 100644 --- a/recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch +++ b/recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch @@ -7,7 +7,7 @@ index d45414e..533dac6 100644 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -cmake_minimum_required(VERSION 3.0) -+cmake_minimum_required(VERSION 3.5) ++cmake_minimum_required(VERSION 3.15) project(minhook LANGUAGES C) From 29ecb65a9e732b7e9803286c5fe6359b75284afe Mon Sep 17 00:00:00 2001 From: memsharded Date: Mon, 29 Jul 2024 18:28:42 +0200 Subject: [PATCH 3/4] review and update to latest commit --- recipes/minhook/all/conandata.yml | 11 +++------- recipes/minhook/all/conanfile.py | 22 +------------------ ...cci.20240114-0001-increase-cmake-min.patch | 13 ----------- 3 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch diff --git a/recipes/minhook/all/conandata.yml b/recipes/minhook/all/conandata.yml index 3199c290a83b3..9fbac6aa78698 100644 --- a/recipes/minhook/all/conandata.yml +++ b/recipes/minhook/all/conandata.yml @@ -1,9 +1,4 @@ sources: - "cci.20240114": - url: "https://github.com/TsudaKageyu/minhook/archive/f5485b8454544c2f034c78f8f127c1d03dea3636.tar.gz" - sha256: "9a60e6615ddfe4ba0ef53f8589aa51acb539d617ce106ef72bfeed5a125f758b" -patches: - "cci.20240114": - - patch_file: "patches/cci.20240114-0001-increase-cmake-min.patch" - patch_description: "Increase cmake_minimum_required version to 3.5" - patch_type: "conan" + "1.3.3.cci.20240629": + url: "https://github.com/TsudaKageyu/minhook/archive/91cc9466e383d13a43d7cf33c7c8fdccb27095d3.tar.gz" + sha256: "b84b2ff19afe5fb9430948680146bee2e198392ee6333a71f81e339c36a819f1" diff --git a/recipes/minhook/all/conanfile.py b/recipes/minhook/all/conanfile.py index 28d79caddefc4..73c08a93a80d6 100644 --- a/recipes/minhook/all/conanfile.py +++ b/recipes/minhook/all/conanfile.py @@ -3,7 +3,7 @@ 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 +from conan.tools.files import copy, get, rmdir required_conan_version = ">=1.53.0" @@ -19,23 +19,12 @@ class PackageConan(ConanFile): 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") @@ -60,7 +49,6 @@ def generate(self): tc.generate() def build(self): - apply_conandata_patches(self) cmake = CMake(self) cmake.configure() cmake.build() @@ -79,11 +67,3 @@ def package_info(self): 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" diff --git a/recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch b/recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch deleted file mode 100644 index 115b9b30e358f..0000000000000 --- a/recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch +++ /dev/null @@ -1,13 +0,0 @@ -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.15) - - project(minhook LANGUAGES C) - From d40b30ea894b911c5b0151dd52be2d47185ef029 Mon Sep 17 00:00:00 2001 From: memsharded Date: Mon, 29 Jul 2024 18:29:06 +0200 Subject: [PATCH 4/4] add config.yml changes --- recipes/minhook/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/minhook/config.yml b/recipes/minhook/config.yml index a5bd7eb6e490e..36b74a86356a1 100644 --- a/recipes/minhook/config.yml +++ b/recipes/minhook/config.yml @@ -1,3 +1,3 @@ versions: - "cci.20240114": + "1.3.3.cci.20240629": folder: all