-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minhook: add minhook/cci.20240114 recipe
- Loading branch information
1 parent
43f8bb1
commit 6789bf1
Showing
7 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
13 changes: 13 additions & 0 deletions
13
recipes/minhook/all/patches/cci.20240114-0001-increase-cmake-min.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <Windows.h> | ||
|
||
#include <iostream> | ||
|
||
#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<LPVOID *>(&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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"cci.20240114": | ||
folder: all |