Chrysalis - Hooks
Loading...
Searching...
No Matches
BaseHook.h
Go to the documentation of this file.
1#ifndef CHRYSALIS_BASEHOOK_H
2#define CHRYSALIS_BASEHOOK_H
3
4#include <polyhook2/Detour/x64Detour.hpp>
5
7
8// ── BaseHook ──────────────────────────────────────────────────────────
9// Base class stored in the hooks map. Owns the PLH detour lifetime.
10//
11// IMPORTANT: hook() is NOT called in the constructor. Subclasses must call
12// install() explicitly after all instance state (_instance, _address) is
13// fully initialized. This prevents a race where the hooked function fires
14// between _detour.hook() and the assignment of _instance.
16public:
17 explicit BaseHook(uint64_t function, uint64_t hook, uint64_t* original);
18 // Activate the detour. Must be called after _instance is set.
19 // Returns false if polyhook could not patch the target — most
20 // commonly because the function's compiled prologue is shorter than
21 // the minimum bytes an x64 detour needs to overwrite (a handful of
22 // bytes; trivial one-line functions under aggressive optimization
23 // can fall below this). On false, NO redirection has occurred: the
24 // function still runs completely untouched. The caller must not
25 // proceed as though hooking succeeded — see Hook<Target>'s ctor.
26 bool install();
27 virtual ~BaseHook();
28protected:
29 PLH::x64Detour detour_;
30};
31
32#endif // CHRYSALIS_BASEHOOK_H
#define HOOKS
Definition HooksLibraryExport.h:11
bool install()
Definition BaseHook.cpp:6
BaseHook(uint64_t function, uint64_t hook, uint64_t *original)
Definition BaseHook.cpp:3
PLH::x64Detour detour_
Definition BaseHook.h:29