Files
libradhook/tests/test_execution_flow.cpp
nexusverypro 3192afe07d initial commit
2026-07-03 02:00:27 +01:00

30 lines
576 B
C++

#include <cassert>
#include "radhook/radhook.h"
static int fn() { return 42; }
static int detour() { return 1337; }
using Fn = int(*)();
int main() {
RadHookHandle h = nullptr;
RadHookCreate((void*)fn, (void*)detour, &h);
// must trigger detour
assert(fn() == 1337);
// disable restores original
RadHookDisable(h);
assert(fn() == 42);
// re-enable restores hook
RadHookEnable(h);
assert(fn() == 1337);
// trampoline correctness
auto orig = RadHookGetOriginalAs<Fn>(h);
assert(orig() == 42);
RadHookDestroy(h);
}