include/DetourModKit/hook_manager.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef DETOURMODKIT_HOOK_MANAGER_HPP | ||
| 2 | #define DETOURMODKIT_HOOK_MANAGER_HPP | ||
| 3 | |||
| 4 | #include <string> | ||
| 5 | #include <unordered_map> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <functional> | ||
| 8 | #include <memory> | ||
| 9 | #include <shared_mutex> | ||
| 10 | #include <optional> | ||
| 11 | #include <expected> | ||
| 12 | #include <string_view> | ||
| 13 | #include <type_traits> | ||
| 14 | #include <concepts> | ||
| 15 | #include <atomic> | ||
| 16 | #include <cassert> | ||
| 17 | #include <utility> | ||
| 18 | |||
| 19 | #include "safetyhook.hpp" | ||
| 20 | #include "DetourModKit/logger.hpp" | ||
| 21 | #include "DetourModKit/scanner.hpp" | ||
| 22 | #include "DetourModKit/format.hpp" | ||
| 23 | |||
| 24 | namespace DetourModKit | ||
| 25 | { | ||
| 26 | /** | ||
| 27 | * @enum HookType | ||
| 28 | * @brief Enumeration of supported hook types, corresponding to SafetyHook capabilities. | ||
| 29 | */ | ||
| 30 | enum class HookType | ||
| 31 | { | ||
| 32 | Inline, | ||
| 33 | Mid | ||
| 34 | }; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * @enum HookStatus | ||
| 38 | * @brief Represents the current operational status of a managed hook. | ||
| 39 | */ | ||
| 40 | enum class HookStatus | ||
| 41 | { | ||
| 42 | Active, | ||
| 43 | Disabled, | ||
| 44 | Enabling, | ||
| 45 | Disabling, | ||
| 46 | Failed, | ||
| 47 | Removed | ||
| 48 | }; | ||
| 49 | |||
| 50 | /** | ||
| 51 | * @enum HookError | ||
| 52 | * @brief Error codes for hook creation/operation failures. | ||
| 53 | */ | ||
| 54 | enum class HookError | ||
| 55 | { | ||
| 56 | AllocatorNotAvailable, | ||
| 57 | InvalidTargetAddress, | ||
| 58 | InvalidDetourFunction, | ||
| 59 | InvalidTrampolinePointer, | ||
| 60 | HookAlreadyExists, | ||
| 61 | ShutdownInProgress, | ||
| 62 | SafetyHookError, | ||
| 63 | UnknownError | ||
| 64 | }; | ||
| 65 | |||
| 66 | /** | ||
| 67 | * @struct HookConfig | ||
| 68 | * @brief Configuration options used during the creation of a new hook. | ||
| 69 | */ | ||
| 70 | struct HookConfig | ||
| 71 | { | ||
| 72 | bool auto_enable = true; | ||
| 73 | safetyhook::InlineHook::Flags inline_flags = static_cast<safetyhook::InlineHook::Flags>(0); | ||
| 74 | safetyhook::MidHook::Flags mid_flags = static_cast<safetyhook::MidHook::Flags>(0); | ||
| 75 | }; | ||
| 76 | |||
| 77 | /** | ||
| 78 | * @class Hook | ||
| 79 | * @brief Abstract base class for managed hooks. | ||
| 80 | * @details Defines a common interface for interacting with different types of hooks | ||
| 81 | * managed by the HookManager. Implements the Template Method pattern for | ||
| 82 | * enable/disable state management. | ||
| 83 | */ | ||
| 84 | class Hook | ||
| 85 | { | ||
| 86 | public: | ||
| 87 | 52 | virtual ~Hook() = default; | |
| 88 | |||
| 89 | 20 | const std::string &get_name() const noexcept { return m_name; } | |
| 90 | 32 | HookType get_type() const noexcept { return m_type; } | |
| 91 | 1 | uintptr_t get_target_address() const noexcept { return m_target_address; } | |
| 92 | 410 | HookStatus get_status() const noexcept { return m_status.load(std::memory_order_acquire); } | |
| 93 | |||
| 94 | /** | ||
| 95 | * @brief Enables the hook. | ||
| 96 | * @return true if the hook was successfully enabled or already active, false otherwise. | ||
| 97 | * @note Uses atomic CAS for lock-free status transitions. Thread-safe without | ||
| 98 | * requiring external synchronization. Uses an intermediate Enabling state | ||
| 99 | * to prevent other threads from observing a speculative terminal state | ||
| 100 | * while the SafetyHook enable call is in progress. | ||
| 101 | */ | ||
| 102 | 106 | bool enable() | |
| 103 | { | ||
| 104 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 108 times.
|
106 | if (!is_impl_valid()) |
| 105 | ✗ | return false; | |
| 106 | |||
| 107 | 108 | HookStatus expected = HookStatus::Disabled; | |
| 108 |
2/2✓ Branch 6 → 7 taken 97 times.
✓ Branch 6 → 8 taken 11 times.
|
108 | if (!m_status.compare_exchange_strong(expected, HookStatus::Enabling, std::memory_order_acq_rel)) |
| 109 | 97 | return expected == HookStatus::Active; | |
| 110 | |||
| 111 |
2/4✓ Branch 8 → 9 taken 11 times.
✗ Branch 8 → 16 not taken.
✓ Branch 9 → 10 taken 11 times.
✗ Branch 9 → 12 not taken.
|
11 | if (do_enable()) |
| 112 | { | ||
| 113 | 11 | m_status.store(HookStatus::Active, std::memory_order_release); | |
| 114 | 11 | return true; | |
| 115 | } | ||
| 116 | |||
| 117 | ✗ | m_status.store(HookStatus::Disabled, std::memory_order_release); | |
| 118 | ✗ | return false; | |
| 119 | } | ||
| 120 | |||
| 121 | /** | ||
| 122 | * @brief Disables the hook. | ||
| 123 | * @return true if the hook was successfully disabled or already disabled, false otherwise. | ||
| 124 | * @note Uses atomic CAS for lock-free status transitions. Thread-safe without | ||
| 125 | * requiring external synchronization. Uses an intermediate Disabling state | ||
| 126 | * to prevent other threads from observing a speculative terminal state | ||
| 127 | * while the SafetyHook disable call is in progress. | ||
| 128 | */ | ||
| 129 | 112 | bool disable() | |
| 130 | { | ||
| 131 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 112 times.
|
112 | if (!is_impl_valid()) |
| 132 | ✗ | return false; | |
| 133 | |||
| 134 | 112 | HookStatus expected = HookStatus::Active; | |
| 135 |
2/2✓ Branch 6 → 7 taken 95 times.
✓ Branch 6 → 8 taken 15 times.
|
112 | if (!m_status.compare_exchange_strong(expected, HookStatus::Disabling, std::memory_order_acq_rel)) |
| 136 | 95 | return expected == HookStatus::Disabled; | |
| 137 | |||
| 138 |
2/4✓ Branch 8 → 9 taken 16 times.
✗ Branch 8 → 16 not taken.
✓ Branch 9 → 10 taken 16 times.
✗ Branch 9 → 12 not taken.
|
15 | if (do_disable()) |
| 139 | { | ||
| 140 | 16 | m_status.store(HookStatus::Disabled, std::memory_order_release); | |
| 141 | 16 | return true; | |
| 142 | } | ||
| 143 | |||
| 144 | ✗ | m_status.store(HookStatus::Active, std::memory_order_release); | |
| 145 | ✗ | return false; | |
| 146 | } | ||
| 147 | |||
| 148 | bool is_enabled() const noexcept { return m_status.load(std::memory_order_acquire) == HookStatus::Active; } | ||
| 149 | |||
| 150 | 192 | static std::string_view status_to_string(HookStatus status) | |
| 151 | { | ||
| 152 |
6/7✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 1 time.
✓ Branch 2 → 5 taken 79 times.
✓ Branch 2 → 6 taken 110 times.
✓ Branch 2 → 7 taken 1 time.
✓ Branch 2 → 8 taken 1 time.
✗ Branch 2 → 9 not taken.
|
192 | switch (status) |
| 153 | { | ||
| 154 | 1 | case HookStatus::Active: | |
| 155 | 1 | return "Active"; | |
| 156 | 1 | case HookStatus::Disabled: | |
| 157 | 1 | return "Disabled"; | |
| 158 | 79 | case HookStatus::Enabling: | |
| 159 | 79 | return "Enabling"; | |
| 160 | 110 | case HookStatus::Disabling: | |
| 161 | 110 | return "Disabling"; | |
| 162 | 1 | case HookStatus::Failed: | |
| 163 | 1 | return "Failed"; | |
| 164 | 1 | case HookStatus::Removed: | |
| 165 | 1 | return "Removed"; | |
| 166 | ✗ | default: | |
| 167 | ✗ | return "Unknown"; | |
| 168 | } | ||
| 169 | } | ||
| 170 | |||
| 171 | 7 | static std::string_view error_to_string(HookError error) | |
| 172 | { | ||
| 173 |
7/8✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 1 time.
✓ Branch 2 → 5 taken 1 time.
✓ Branch 2 → 6 taken 1 time.
✓ Branch 2 → 7 taken 1 time.
✓ Branch 2 → 8 taken 1 time.
✓ Branch 2 → 9 taken 1 time.
✗ Branch 2 → 10 not taken.
|
7 | switch (error) |
| 174 | { | ||
| 175 | 1 | case HookError::AllocatorNotAvailable: | |
| 176 | 1 | return "Allocator not available"; | |
| 177 | 1 | case HookError::InvalidTargetAddress: | |
| 178 | 1 | return "Invalid target address"; | |
| 179 | 1 | case HookError::InvalidDetourFunction: | |
| 180 | 1 | return "Invalid detour function"; | |
| 181 | 1 | case HookError::InvalidTrampolinePointer: | |
| 182 | 1 | return "Invalid trampoline pointer"; | |
| 183 | 1 | case HookError::HookAlreadyExists: | |
| 184 | 1 | return "Hook already exists"; | |
| 185 | 1 | case HookError::SafetyHookError: | |
| 186 | 1 | return "SafetyHook error"; | |
| 187 | 1 | case HookError::UnknownError: | |
| 188 | 1 | return "Unknown error"; | |
| 189 | ✗ | default: | |
| 190 | ✗ | return "Invalid error code"; | |
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | protected: | ||
| 195 | std::string m_name; | ||
| 196 | HookType m_type; | ||
| 197 | uintptr_t m_target_address; | ||
| 198 | std::atomic<HookStatus> m_status; | ||
| 199 | |||
| 200 | 52 | Hook(std::string name, HookType type, uintptr_t target_address, HookStatus initial_status) | |
| 201 | 104 | : m_name(std::move(name)), m_type(type), m_target_address(target_address), m_status(initial_status) {} | |
| 202 | |||
| 203 | virtual bool is_impl_valid() const noexcept = 0; | ||
| 204 | virtual bool do_enable() = 0; | ||
| 205 | virtual bool do_disable() = 0; | ||
| 206 | |||
| 207 | Hook(const Hook &) = delete; | ||
| 208 | Hook &operator=(const Hook &) = delete; | ||
| 209 | Hook(Hook &&) = delete; | ||
| 210 | Hook &operator=(Hook &&) = delete; | ||
| 211 | }; | ||
| 212 | |||
| 213 | /** | ||
| 214 | * @class InlineHook | ||
| 215 | * @brief Represents a managed inline hook, wrapping a SafetyHook::InlineHook object. | ||
| 216 | */ | ||
| 217 | class InlineHook : public Hook | ||
| 218 | { | ||
| 219 | public: | ||
| 220 | 33 | InlineHook(std::string name, uintptr_t target_address, | |
| 221 | std::unique_ptr<safetyhook::InlineHook> hook_obj, | ||
| 222 | HookStatus initial_status) | ||
| 223 | 66 | : Hook(std::move(name), HookType::Inline, target_address, initial_status), | |
| 224 | 99 | m_safetyhook_impl(std::move(hook_obj)) {} | |
| 225 | |||
| 226 | /** | ||
| 227 | * @brief Retrieves the trampoline to call the original function. | ||
| 228 | * @tparam T The function pointer type of the original function. | ||
| 229 | * @return A function pointer of type T to the original function's trampoline. | ||
| 230 | */ | ||
| 231 | template <typename T> | ||
| 232 | 2 | T get_original() const noexcept | |
| 233 | { | ||
| 234 |
1/2✓ Branch 3 → 4 taken 2 times.
✗ Branch 3 → 6 not taken.
|
2 | return m_safetyhook_impl ? m_safetyhook_impl->original<T>() : nullptr; |
| 235 | } | ||
| 236 | |||
| 237 | protected: | ||
| 238 | 209 | bool is_impl_valid() const noexcept override { return m_safetyhook_impl != nullptr; } | |
| 239 | 8 | bool do_enable() override | |
| 240 | { | ||
| 241 |
1/2✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 7 not taken.
|
8 | auto result = m_safetyhook_impl->enable(); |
| 242 | 16 | return result.has_value(); | |
| 243 | } | ||
| 244 | 11 | bool do_disable() override | |
| 245 | { | ||
| 246 |
1/2✓ Branch 3 → 4 taken 11 times.
✗ Branch 3 → 7 not taken.
|
11 | auto result = m_safetyhook_impl->disable(); |
| 247 | 22 | return result.has_value(); | |
| 248 | } | ||
| 249 | |||
| 250 | private: | ||
| 251 | std::unique_ptr<safetyhook::InlineHook> m_safetyhook_impl; | ||
| 252 | }; | ||
| 253 | |||
| 254 | /** | ||
| 255 | * @class MidHook | ||
| 256 | * @brief Represents a managed mid-function hook, wrapping a SafetyHook::MidHook object. | ||
| 257 | */ | ||
| 258 | class MidHook : public Hook | ||
| 259 | { | ||
| 260 | public: | ||
| 261 | 19 | MidHook(std::string name, uintptr_t target_address, | |
| 262 | std::unique_ptr<safetyhook::MidHook> hook_obj, | ||
| 263 | HookStatus initial_status) | ||
| 264 | 38 | : Hook(std::move(name), HookType::Mid, target_address, initial_status), | |
| 265 | 57 | m_safetyhook_impl(std::move(hook_obj)) {} | |
| 266 | |||
| 267 | /** | ||
| 268 | * @brief Gets the destination function of this mid-hook. | ||
| 269 | * @return safetyhook::MidHookFn The function pointer to the detour. | ||
| 270 | */ | ||
| 271 | 1 | safetyhook::MidHookFn get_destination() const noexcept | |
| 272 | { | ||
| 273 |
1/2✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 6 not taken.
|
1 | return m_safetyhook_impl ? m_safetyhook_impl->destination() : nullptr; |
| 274 | } | ||
| 275 | |||
| 276 | protected: | ||
| 277 | 8 | bool is_impl_valid() const noexcept override { return m_safetyhook_impl != nullptr; } | |
| 278 | 3 | bool do_enable() override | |
| 279 | { | ||
| 280 |
1/2✓ Branch 3 → 4 taken 3 times.
✗ Branch 3 → 7 not taken.
|
3 | auto result = m_safetyhook_impl->enable(); |
| 281 | 6 | return result.has_value(); | |
| 282 | } | ||
| 283 | 5 | bool do_disable() override | |
| 284 | { | ||
| 285 |
1/2✓ Branch 3 → 4 taken 5 times.
✗ Branch 3 → 7 not taken.
|
5 | auto result = m_safetyhook_impl->disable(); |
| 286 | 10 | return result.has_value(); | |
| 287 | } | ||
| 288 | |||
| 289 | private: | ||
| 290 | std::unique_ptr<safetyhook::MidHook> m_safetyhook_impl; | ||
| 291 | }; | ||
| 292 | |||
| 293 | /** | ||
| 294 | * @class HookManager | ||
| 295 | * @brief Manages the lifecycle of all hooks (Inline and Mid) using SafetyHook. | ||
| 296 | * @details Provides a centralized API for creating, removing, enabling, and disabling hooks. | ||
| 297 | * Thread-safe for all public methods. Uses std::expected for explicit error handling. | ||
| 298 | */ | ||
| 299 | class HookManager | ||
| 300 | { | ||
| 301 | public: | ||
| 302 | /** | ||
| 303 | * @brief Provides access to the singleton instance of the HookManager. | ||
| 304 | * @return HookManager& Reference to the global HookManager instance. | ||
| 305 | */ | ||
| 306 | static HookManager &get_instance(); | ||
| 307 | |||
| 308 | ~HookManager() noexcept; | ||
| 309 | |||
| 310 | /** | ||
| 311 | * @brief Explicitly shuts down the HookManager, removing all hooks without logging. | ||
| 312 | * @details This method is safe to call during shutdown when Logger may be destroyed. | ||
| 313 | * It removes all hooks without attempting to log, preventing use-after-free. | ||
| 314 | * The shutdown flag is reset after hooks are cleared, allowing subsequent | ||
| 315 | * hook creation for hot-reload scenarios. The destructor becomes a no-op | ||
| 316 | * only while the flag is set during the shutdown operation itself. | ||
| 317 | */ | ||
| 318 | void shutdown(); | ||
| 319 | |||
| 320 | // Non-copyable, non-movable (mutex member) | ||
| 321 | HookManager(const HookManager &) = delete; | ||
| 322 | HookManager &operator=(const HookManager &) = delete; | ||
| 323 | HookManager(HookManager &&) = delete; | ||
| 324 | HookManager &operator=(HookManager &&) = delete; | ||
| 325 | |||
| 326 | /** | ||
| 327 | * @brief Creates an inline hook at a specific target memory address. | ||
| 328 | * @param name A unique, descriptive name for the hook. | ||
| 329 | * @param target_address The memory address of the function to hook. | ||
| 330 | * @param detour_function Pointer to the detour function. | ||
| 331 | * @param original_trampoline Output pointer to receive trampoline address. | ||
| 332 | * @param config Optional configuration settings for the hook. | ||
| 333 | * @return std::expected<std::string, HookError> The hook name if successful, error code otherwise. | ||
| 334 | */ | ||
| 335 | [[nodiscard]] std::expected<std::string, HookError> create_inline_hook( | ||
| 336 | std::string_view name, | ||
| 337 | uintptr_t target_address, | ||
| 338 | void *detour_function, | ||
| 339 | void **original_trampoline, | ||
| 340 | const HookConfig &config = HookConfig()); | ||
| 341 | |||
| 342 | /** | ||
| 343 | * @brief Creates an inline hook by finding target address via AOB scan. | ||
| 344 | * @param name A unique, descriptive name for the hook. | ||
| 345 | * @param module_base Base address of the memory module to scan. | ||
| 346 | * @param module_size Size of the memory module to scan. | ||
| 347 | * @param aob_pattern_str The AOB pattern string. | ||
| 348 | * @param aob_offset Offset to add to the found pattern's address. | ||
| 349 | * @param detour_function Pointer to the detour function. | ||
| 350 | * @param original_trampoline Output pointer to store trampoline address. | ||
| 351 | * @param config Optional configuration settings for the hook. | ||
| 352 | * @return std::expected<std::string, HookError> The hook name if successful, error code otherwise. | ||
| 353 | */ | ||
| 354 | [[nodiscard]] std::expected<std::string, HookError> create_inline_hook_aob( | ||
| 355 | std::string_view name, | ||
| 356 | uintptr_t module_base, | ||
| 357 | size_t module_size, | ||
| 358 | std::string_view aob_pattern_str, | ||
| 359 | ptrdiff_t aob_offset, | ||
| 360 | void *detour_function, | ||
| 361 | void **original_trampoline, | ||
| 362 | const HookConfig &config = HookConfig()); | ||
| 363 | |||
| 364 | /** | ||
| 365 | * @brief Creates a mid-function hook at a specific target memory address. | ||
| 366 | * @param name A unique, descriptive name for the hook. | ||
| 367 | * @param target_address The memory address within a function to hook. | ||
| 368 | * @param detour_function The function to be called when the mid-hook is executed. | ||
| 369 | * @param config Optional configuration settings for the hook. | ||
| 370 | * @return std::expected<std::string, HookError> The hook name if successful, error code otherwise. | ||
| 371 | */ | ||
| 372 | [[nodiscard]] std::expected<std::string, HookError> create_mid_hook( | ||
| 373 | std::string_view name, | ||
| 374 | uintptr_t target_address, | ||
| 375 | safetyhook::MidHookFn detour_function, | ||
| 376 | const HookConfig &config = HookConfig()); | ||
| 377 | |||
| 378 | /** | ||
| 379 | * @brief Creates a mid-function hook by finding target address via AOB scan. | ||
| 380 | * @param name A unique, descriptive name for the hook. | ||
| 381 | * @param module_base Base address of the memory module to scan. | ||
| 382 | * @param module_size Size of the memory module to scan. | ||
| 383 | * @param aob_pattern_str The AOB pattern string. | ||
| 384 | * @param aob_offset Offset to add to the found pattern's address. | ||
| 385 | * @param detour_function The mid-hook detour function. | ||
| 386 | * @param config Optional configuration settings for the hook. | ||
| 387 | * @return std::expected<std::string, HookError> The hook name if successful, error code otherwise. | ||
| 388 | */ | ||
| 389 | [[nodiscard]] std::expected<std::string, HookError> create_mid_hook_aob( | ||
| 390 | std::string_view name, | ||
| 391 | uintptr_t module_base, | ||
| 392 | size_t module_size, | ||
| 393 | std::string_view aob_pattern_str, | ||
| 394 | ptrdiff_t aob_offset, | ||
| 395 | safetyhook::MidHookFn detour_function, | ||
| 396 | const HookConfig &config = HookConfig()); | ||
| 397 | |||
| 398 | /** | ||
| 399 | * @brief Removes a hook identified by its name. | ||
| 400 | * @param hook_id The name of the hook to remove. | ||
| 401 | * @return true if the hook was found and successfully removed, false otherwise. | ||
| 402 | */ | ||
| 403 | [[nodiscard]] bool remove_hook(std::string_view hook_id); | ||
| 404 | |||
| 405 | /** | ||
| 406 | * @brief Removes all hooks currently managed by this HookManager instance. | ||
| 407 | */ | ||
| 408 | void remove_all_hooks(); | ||
| 409 | |||
| 410 | /** | ||
| 411 | * @brief Enables a previously disabled hook. | ||
| 412 | * @param hook_id The name of the hook to enable. | ||
| 413 | * @return true if the hook was found and successfully enabled, false otherwise. | ||
| 414 | */ | ||
| 415 | [[nodiscard]] bool enable_hook(std::string_view hook_id); | ||
| 416 | |||
| 417 | /** | ||
| 418 | * @brief Disables an active hook temporarily without removing it. | ||
| 419 | * @param hook_id The name of the hook to disable. | ||
| 420 | * @return true if the hook was found and successfully disabled, false otherwise. | ||
| 421 | */ | ||
| 422 | [[nodiscard]] bool disable_hook(std::string_view hook_id); | ||
| 423 | |||
| 424 | /** | ||
| 425 | * @brief Retrieves the current status of a hook. | ||
| 426 | * @param hook_id The name of the hook. | ||
| 427 | * @return std::optional<HookStatus> The current status, or std::nullopt if not found. | ||
| 428 | */ | ||
| 429 | [[nodiscard]] std::optional<HookStatus> get_hook_status(std::string_view hook_id) const; | ||
| 430 | |||
| 431 | /** | ||
| 432 | * @brief Gets a summary of hook counts categorized by their status. | ||
| 433 | * @return std::unordered_map<HookStatus, size_t> Map of statuses to counts. | ||
| 434 | */ | ||
| 435 | std::unordered_map<HookStatus, size_t> get_hook_counts() const; | ||
| 436 | |||
| 437 | /** | ||
| 438 | * @brief Retrieves a list of hook names. | ||
| 439 | * @param status_filter Optional status filter for returned hooks. | ||
| 440 | * @return std::vector<std::string> Vector containing the names of the hooks. | ||
| 441 | */ | ||
| 442 | 48 | std::vector<std::string> get_hook_ids(std::optional<HookStatus> status_filter = std::nullopt) const; | |
| 443 | |||
| 444 | /** | ||
| 445 | * @brief Safely accesses an InlineHook by its ID while holding the internal lock. | ||
| 446 | * @details The callback is invoked with a reference to the InlineHook while the | ||
| 447 | * shared_mutex is held as a reader, preventing concurrent removal. | ||
| 448 | * @warning DANGER: Any callback holding m_hooks_mutex must NOT call methods that | ||
| 449 | * acquire a unique_lock (remove_hook, enable_hook, disable_hook, create_*_hook) | ||
| 450 | * because those calls will deadlock. Perform such mutations outside the callback | ||
| 451 | * or use an asynchronous/posted operation that does not hold m_hooks_mutex. | ||
| 452 | * @tparam F Callable type accepting (InlineHook&) and returning a value. | ||
| 453 | * @param hook_id The name of the inline hook. | ||
| 454 | * @param fn The callback to invoke with the hook reference. | ||
| 455 | * @return std::optional<R> The callback's return value, or std::nullopt if hook not found. | ||
| 456 | */ | ||
| 457 | template <typename F> | ||
| 458 | requires std::invocable<F, InlineHook &> && | ||
| 459 | (!std::is_void_v<std::invoke_result_t<F, InlineHook &>>) && | ||
| 460 | (!std::is_reference_v<std::invoke_result_t<F, InlineHook &>>) | ||
| 461 | 8 | [[nodiscard]] auto with_inline_hook(std::string_view hook_id, F &&fn) | |
| 462 | -> std::optional<std::invoke_result_t<F, InlineHook &>> | ||
| 463 | { | ||
| 464 |
8/16std::optional<std::invoke_result<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
|
8 | if (get_reentrancy_guard() > 0) |
| 465 | { | ||
| 466 | ✗ | m_logger.error("HookManager: Reentrant callback detected in with_inline_hook('{}')! Callback holding m_hooks_mutex must not call HookManager methods that acquire a unique_lock (remove_hook, enable_hook, disable_hook, create_*_hook). Perform mutations outside the callback or use an asynchronous operation.", hook_id); | |
| 467 | ✗ | return std::nullopt; | |
| 468 | } | ||
| 469 |
8/16std::optional<std::invoke_result<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
std::optional<std::invoke_result<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 49 not taken.
std::optional<std::invoke_result<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
|
8 | std::shared_lock<std::shared_mutex> lock(m_hooks_mutex); |
| 470 | 8 | ReentrancyGuard guard(get_reentrancy_guard()); | |
| 471 |
8/16std::optional<std::invoke_result<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 39 not taken.
std::optional<std::invoke_result<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
|
8 | const std::string key{hook_id}; |
| 472 |
8/16std::optional<std::invoke_result<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
|
8 | auto it = m_hooks.find(key); |
| 473 |
22/48std::optional<std::invoke_result<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 24 taken 1 time.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 34 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 24 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 1 time.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 34 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 24 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 24 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 34 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 22 not taken.
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 22 not taken.
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 32 not taken.
std::optional<std::invoke_result<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 24 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 24 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 34 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 24 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 24 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 34 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 24 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 24 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 34 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 24 taken 1 time.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 34 taken 1 time.
|
8 | if (it != m_hooks.end() && it->second->get_type() == HookType::Inline) |
| 474 | { | ||
| 475 |
5/16std::optional<std::invoke_result<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_WrongType_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealInlineHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 28 → 29 taken 1 time.
✗ Branch 28 → 42 not taken.
std::optional<std::invoke_result<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_InlineHook_GetOriginal_Noexcept_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::with_inline_hook<HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithInlineHook_ReturnsNulloptForNonExistentHook_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 46 not taken.
|
10 | return std::invoke(std::forward<F>(fn), static_cast<InlineHook &>(*it->second)); |
| 476 | } | ||
| 477 | 3 | return std::nullopt; | |
| 478 | 8 | } | |
| 479 | |||
| 480 | /** | ||
| 481 | * @brief Try-safe access to an InlineHook by its ID using a non-blocking lock. | ||
| 482 | * @details Provides a non-blocking alternative to with_inline_hook(). The callback | ||
| 483 | * is invoked only if the lock is immediately acquired via std::try_to_lock. | ||
| 484 | * Note: try_to_lock only avoids blocking on initial acquisition - it does NOT | ||
| 485 | * make callbacks safe to re-enter HookManager methods that also acquire the | ||
| 486 | * same non-recursive mutex (e.g., enable_hook, disable_hook). If a callback | ||
| 487 | * needs to call those methods, it must release the lock first or perform those | ||
| 488 | * calls asynchronously to avoid deadlock. See with_inline_hook for the blocking | ||
| 489 | * analogue. | ||
| 490 | * @param hook_id The name of the inline hook. | ||
| 491 | * @param fn The callback to invoke with the hook reference. | ||
| 492 | * @return std::optional<R> The callback's return value. Returns std::nullopt if either | ||
| 493 | * the lock could not be acquired or the hook was not found. | ||
| 494 | */ | ||
| 495 | template <typename F> | ||
| 496 | requires std::invocable<F, InlineHook &> && | ||
| 497 | (!std::is_void_v<std::invoke_result_t<F, InlineHook &>>) && | ||
| 498 | (!std::is_reference_v<std::invoke_result_t<F, InlineHook &>>) | ||
| 499 | 3 | [[nodiscard]] auto try_with_inline_hook(std::string_view hook_id, F &&fn) | |
| 500 | -> std::optional<std::invoke_result_t<F, InlineHook &>> | ||
| 501 | { | ||
| 502 |
3/6std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
|
3 | if (get_reentrancy_guard() > 0) |
| 503 | { | ||
| 504 | ✗ | m_logger.error("HookManager: Reentrant callback detected in try_with_inline_hook('{}')! Callback holding m_hooks_mutex must not call HookManager methods that acquire a unique_lock (remove_hook, enable_hook, disable_hook, create_*_hook). Perform mutations outside the callback or use an asynchronous operation.", hook_id); | |
| 505 | ✗ | return std::nullopt; | |
| 506 | } | ||
| 507 |
3/6std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 52 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 59 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 59 not taken.
|
3 | std::shared_lock<std::shared_mutex> lock(m_hooks_mutex, std::try_to_lock); |
| 508 |
3/6std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 14 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 14 taken 1 time.
|
3 | if (!lock.owns_lock()) |
| 509 | { | ||
| 510 | ✗ | return std::nullopt; | |
| 511 | } | ||
| 512 | 3 | ReentrancyGuard guard(get_reentrancy_guard()); | |
| 513 |
3/6std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 42 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 48 not taken.
|
3 | const std::string key{hook_id}; |
| 514 |
3/6std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 53 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 53 not taken.
|
3 | auto it = m_hooks.find(key); |
| 515 |
8/18std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 25 not taken.
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 25 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 35 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 29 taken 1 time.
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 29 not taken.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 39 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 29 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 29 not taken.
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 39 not taken.
|
3 | if (it != m_hooks.end() && it->second->get_type() == HookType::Inline) |
| 516 | { | ||
| 517 |
2/6std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_Success_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 45 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_NotFound_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 51 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}, DetourModKit::InlineHook&>::type> DetourModKit::HookManager::try_with_inline_hook<HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithInlineHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::InlineHook&)#1}&&):
✓ Branch 35 → 36 taken 1 time.
✗ Branch 35 → 51 not taken.
|
4 | return std::invoke(std::forward<F>(fn), static_cast<InlineHook &>(*it->second)); |
| 518 | } | ||
| 519 | 1 | return std::nullopt; | |
| 520 | 3 | } | |
| 521 | |||
| 522 | /** | ||
| 523 | * @brief Safely accesses a MidHook by its ID while holding the internal lock. | ||
| 524 | * @details The callback is invoked with a reference to the MidHook while the | ||
| 525 | * shared_mutex is held as a reader, preventing concurrent removal. | ||
| 526 | * @warning DANGER: Any callback holding m_hooks_mutex must NOT call methods that | ||
| 527 | * acquire a unique_lock (remove_hook, enable_hook, disable_hook, create_*_hook) | ||
| 528 | * because those calls will deadlock. Perform such mutations outside the callback | ||
| 529 | * or use an asynchronous/posted operation that does not hold m_hooks_mutex. | ||
| 530 | * @tparam F Callable type accepting (MidHook&) and returning a value. | ||
| 531 | * @param hook_id The name of the mid hook. | ||
| 532 | * @param fn The callback to invoke with the hook reference. | ||
| 533 | * @return std::optional<R> The callback's return value, or std::nullopt if hook not found. | ||
| 534 | */ | ||
| 535 | template <typename F> | ||
| 536 | requires std::invocable<F, MidHook &> && | ||
| 537 | (!std::is_void_v<std::invoke_result_t<F, MidHook &>>) && | ||
| 538 | (!std::is_reference_v<std::invoke_result_t<F, MidHook &>>) | ||
| 539 | 7 | [[nodiscard]] auto with_mid_hook(std::string_view hook_id, F &&fn) | |
| 540 | -> std::optional<std::invoke_result_t<F, MidHook &>> | ||
| 541 | { | ||
| 542 |
7/14std::optional<std::invoke_result<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
|
7 | if (get_reentrancy_guard() > 0) |
| 543 | { | ||
| 544 | ✗ | m_logger.error("HookManager: Reentrant callback detected in with_mid_hook('{}')! Callback holding m_hooks_mutex must not call HookManager methods that acquire a unique_lock (remove_hook, enable_hook, disable_hook, create_*_hook). Perform mutations outside the callback or use an asynchronous operation.", hook_id); | |
| 545 | ✗ | return std::nullopt; | |
| 546 | } | ||
| 547 |
7/14std::optional<std::invoke_result<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
std::optional<std::invoke_result<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 49 not taken.
std::optional<std::invoke_result<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
|
7 | std::shared_lock<std::shared_mutex> lock(m_hooks_mutex); |
| 548 | 7 | ReentrancyGuard guard(get_reentrancy_guard()); | |
| 549 |
7/14std::optional<std::invoke_result<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 39 not taken.
std::optional<std::invoke_result<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
|
7 | const std::string key{hook_id}; |
| 550 |
7/14std::optional<std::invoke_result<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 43 not taken.
std::optional<std::invoke_result<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 48 not taken.
|
7 | auto it = m_hooks.find(key); |
| 551 |
20/42std::optional<std::invoke_result<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 24 taken 1 time.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 34 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 24 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 1 time.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 34 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 24 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 24 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 34 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 22 not taken.
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 22 not taken.
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 32 not taken.
std::optional<std::invoke_result<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 24 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 24 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 34 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 24 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 24 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 34 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 24 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 24 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 34 not taken.
|
7 | if (it != m_hooks.end() && it->second->get_type() == HookType::Mid) |
| 552 | { | ||
| 553 |
5/14std::optional<std::invoke_result<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_WrongType_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_RealMidHook_WithCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_SuccessCallback_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 28 → 29 taken 1 time.
✗ Branch 28 → 42 not taken.
std::optional<std::invoke_result<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_MidHook_GetDestination_Noexcept_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_DirectEnableDisable_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::with_mid_hook<HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_WithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 46 not taken.
|
10 | return std::invoke(std::forward<F>(fn), static_cast<MidHook &>(*it->second)); |
| 554 | } | ||
| 555 | 2 | return std::nullopt; | |
| 556 | 7 | } | |
| 557 | |||
| 558 | /** | ||
| 559 | * @brief Try-safe access to a MidHook by its ID using a non-blocking lock. | ||
| 560 | * @details Provides a non-blocking alternative to with_mid_hook(). The callback | ||
| 561 | * is invoked only if the lock is immediately acquired via std::try_to_lock. | ||
| 562 | * Note: try_to_lock only avoids blocking on initial acquisition - it does NOT | ||
| 563 | * make callbacks safe to re-enter HookManager methods that also acquire the | ||
| 564 | * same non-recursive mutex (e.g., enable_hook, disable_hook). If a callback | ||
| 565 | * needs to call those methods, it must release the lock first or perform those | ||
| 566 | * calls asynchronously to avoid deadlock. See with_mid_hook for the blocking | ||
| 567 | * analogue. | ||
| 568 | * @param hook_id The name of the mid hook. | ||
| 569 | * @param fn The callback to invoke with the hook reference. | ||
| 570 | * @return std::optional<R> The callback's return value. Returns std::nullopt if either | ||
| 571 | * the lock could not be acquired or the hook was not found. | ||
| 572 | */ | ||
| 573 | template <typename F> | ||
| 574 | requires std::invocable<F, MidHook &> && | ||
| 575 | (!std::is_void_v<std::invoke_result_t<F, MidHook &>>) && | ||
| 576 | (!std::is_reference_v<std::invoke_result_t<F, MidHook &>>) | ||
| 577 | 3 | [[nodiscard]] auto try_with_mid_hook(std::string_view hook_id, F &&fn) | |
| 578 | -> std::optional<std::invoke_result_t<F, MidHook &>> | ||
| 579 | { | ||
| 580 |
3/6std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 1 time.
|
3 | if (get_reentrancy_guard() > 0) |
| 581 | { | ||
| 582 | ✗ | m_logger.error("HookManager: Reentrant callback detected in try_with_mid_hook('{}')! Callback holding m_hooks_mutex must not call HookManager methods that acquire a unique_lock (remove_hook, enable_hook, disable_hook, create_*_hook). Perform mutations outside the callback or use an asynchronous operation.", hook_id); | |
| 583 | ✗ | return std::nullopt; | |
| 584 | } | ||
| 585 |
3/6std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 52 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 59 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 59 not taken.
|
3 | std::shared_lock<std::shared_mutex> lock(m_hooks_mutex, std::try_to_lock); |
| 586 |
3/6std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 14 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 14 taken 1 time.
|
3 | if (!lock.owns_lock()) |
| 587 | { | ||
| 588 | ✗ | return std::nullopt; | |
| 589 | } | ||
| 590 | 3 | ReentrancyGuard guard(get_reentrancy_guard()); | |
| 591 |
3/6std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 42 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 48 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 48 not taken.
|
3 | const std::string key{hook_id}; |
| 592 |
3/6std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 46 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 53 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 53 not taken.
|
3 | auto it = m_hooks.find(key); |
| 593 |
8/18std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 25 not taken.
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 25 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 35 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 29 taken 1 time.
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 29 not taken.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 39 taken 1 time.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 29 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 29 not taken.
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 39 not taken.
|
3 | if (it != m_hooks.end() && it->second->get_type() == HookType::Mid) |
| 594 | { | ||
| 595 |
2/6std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_Success_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 45 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_NotFound_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 51 not taken.
std::optional<std::invoke_result<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}, DetourModKit::MidHook&>::type> DetourModKit::HookManager::try_with_mid_hook<HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}>(std::basic_string_view<char, std::char_traits<char> >, HookManagerTest_TryWithMidHook_CallbackExecutesSuccessfully_Test::TestBody()::{lambda(DetourModKit::MidHook&)#1}&&):
✓ Branch 35 → 36 taken 1 time.
✗ Branch 35 → 51 not taken.
|
4 | return std::invoke(std::forward<F>(fn), static_cast<MidHook &>(*it->second)); |
| 596 | } | ||
| 597 | 1 | return std::nullopt; | |
| 598 | 3 | } | |
| 599 | |||
| 600 | private: | ||
| 601 | explicit HookManager(Logger &logger = Logger::get_instance()); | ||
| 602 | |||
| 603 | mutable std::shared_mutex m_hooks_mutex; | ||
| 604 | std::unordered_map<std::string, std::unique_ptr<Hook>> m_hooks; | ||
| 605 | Logger &m_logger; | ||
| 606 | std::shared_ptr<safetyhook::Allocator> m_allocator; | ||
| 607 | std::atomic<bool> m_shutdown_called{false}; | ||
| 608 | |||
| 609 | 42 | [[nodiscard]] int &get_reentrancy_guard() noexcept | |
| 610 | { | ||
| 611 | thread_local int reentrancy_counter{0}; | ||
| 612 | 42 | return reentrancy_counter; | |
| 613 | } | ||
| 614 | |||
| 615 | struct ReentrancyGuard | ||
| 616 | { | ||
| 617 | int &counter; | ||
| 618 | 21 | explicit ReentrancyGuard(int &cnt) noexcept : counter(cnt) { ++counter; } | |
| 619 | 21 | ~ReentrancyGuard() noexcept { --counter; } | |
| 620 | ReentrancyGuard(const ReentrancyGuard &) = delete; | ||
| 621 | ReentrancyGuard &operator=(const ReentrancyGuard &) = delete; | ||
| 622 | ReentrancyGuard(ReentrancyGuard &&) = delete; | ||
| 623 | ReentrancyGuard &operator=(ReentrancyGuard &&) = delete; | ||
| 624 | }; | ||
| 625 | |||
| 626 | std::string error_to_string(const safetyhook::InlineHook::Error &err) const; | ||
| 627 | std::string error_to_string(const safetyhook::MidHook::Error &err) const; | ||
| 628 | |||
| 629 | // Non-locking variant - caller must already hold m_hooks_mutex | ||
| 630 | bool hook_id_exists_locked(std::string_view hook_id) const; | ||
| 631 | }; | ||
| 632 | } // namespace DetourModKit | ||
| 633 | |||
| 634 | #endif // DETOURMODKIT_HOOK_MANAGER_HPP | ||
| 635 |