102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
hook_registry.c File Reference
#include <stdint.h>
#include <string.h>
#include <dttr_runtime.h>
#include <dttr_test_support.h>

Go to the source code of this file.

Typedefs

typedef int(* hook_target_fn) (int value)

Functions

static void test_patch_bytes_detach_restores_original (void **state)
static void test_pointer_hook_detach_restores_original (void **state)
static void test_owner_detach_only_detaches_matching_owner (void **state)
static void test_cleanup_all_restores_hooks_and_allows_reuse (void **state)
static void test_overlapping_byte_patches_are_rejected (void **state)
 __attribute__ ((noinline))
static void chain_log (int id)
static int chain_detour_a (int value)
static int chain_detour_b (int value)
static void test_function_hooks_chain_and_detach (void **state)

Variables

static uint8_t patch_target [4] = {0x10, 0x20, 0x30, 0x40}
static voidpointer_target = (void *)0x11112222u
static hook_target_fn chain_original_a = NULL
static hook_target_fn chain_original_b = NULL
static int chain_call_log [2]
static size_t chain_call_count = 0
static const DTTR_TestCase TEST_CASES []

Typedef Documentation

◆ hook_target_fn

typedef int(* hook_target_fn) (int value)

Definition at line 130 of file hook_registry.c.

Function Documentation

◆ __attribute__()

__attribute__ ( (noinline) )

Definition at line 136 of file hook_registry.c.

◆ chain_detour_a()

int chain_detour_a ( int value)
static

Definition at line 146 of file hook_registry.c.

References chain_log(), and chain_original_a.

Referenced by test_function_hooks_chain_and_detach().

◆ chain_detour_b()

int chain_detour_b ( int value)
static

Definition at line 152 of file hook_registry.c.

References chain_log(), and chain_original_b.

Referenced by test_function_hooks_chain_and_detach().

◆ chain_log()

void chain_log ( int id)
static

Definition at line 141 of file hook_registry.c.

References chain_call_count, chain_call_log, DTTR_TEST_ARRAY_COUNT, and id.

Referenced by chain_detour_a(), and chain_detour_b().

◆ test_cleanup_all_restores_hooks_and_allows_reuse()

void test_cleanup_all_restores_hooks_and_allows_reuse ( void ** state)
static

Definition at line 84 of file hook_registry.c.

References DTTR_Core_HookCleanupAll(), DTTR_Core_HookPatchBytes(), state, and target.

◆ test_function_hooks_chain_and_detach()

◆ test_overlapping_byte_patches_are_rejected()

void test_overlapping_byte_patches_are_rejected ( void ** state)
static

◆ test_owner_detach_only_detaches_matching_owner()

void test_owner_detach_only_detaches_matching_owner ( void ** state)
static

◆ test_patch_bytes_detach_restores_original()

void test_patch_bytes_detach_restores_original ( void ** state)
static

◆ test_pointer_hook_detach_restores_original()

void test_pointer_hook_detach_restores_original ( void ** state)
static

Variable Documentation

◆ chain_call_count

size_t chain_call_count = 0
static

Definition at line 134 of file hook_registry.c.

Referenced by chain_log(), and test_function_hooks_chain_and_detach().

◆ chain_call_log

int chain_call_log[2]
static

Definition at line 133 of file hook_registry.c.

Referenced by chain_log(), and test_function_hooks_chain_and_detach().

◆ chain_original_a

hook_target_fn chain_original_a = NULL
static

Definition at line 131 of file hook_registry.c.

Referenced by chain_detour_a(), and test_function_hooks_chain_and_detach().

◆ chain_original_b

hook_target_fn chain_original_b = NULL
static

Definition at line 132 of file hook_registry.c.

Referenced by chain_detour_b(), and test_function_hooks_chain_and_detach().

◆ patch_target

uint8_t patch_target[4] = {0x10, 0x20, 0x30, 0x40}
static

Definition at line 7 of file hook_registry.c.

◆ pointer_target

void* pointer_target = (void *)0x11112222u
static

Definition at line 8 of file hook_registry.c.

Referenced by test_pointer_hook_detach_restores_original().

◆ TEST_CASES

const DTTR_TestCase TEST_CASES[]
static
Initial value:
= {
{"hook-registry-patch-bytes", test_patch_bytes_detach_restores_original},
{"hook-registry-pointer", test_pointer_hook_detach_restores_original},
{"hook-registry-owner-detach", test_owner_detach_only_detaches_matching_owner},
{"hook-registry-cleanup-all", test_cleanup_all_restores_hooks_and_allows_reuse},
{"hook-registry-overlap", test_overlapping_byte_patches_are_rejected},
{"hook-registry-function-chain", test_function_hooks_chain_and_detach},
}
static void test_owner_detach_only_detaches_matching_owner(void **state)
static void test_patch_bytes_detach_restores_original(void **state)
static void test_pointer_hook_detach_restores_original(void **state)
static void test_overlapping_byte_patches_are_rejected(void **state)
static void test_function_hooks_chain_and_detach(void **state)
static void test_cleanup_all_restores_hooks_and_allows_reuse(void **state)

Definition at line 201 of file hook_registry.c.