mirror of
https://github.com/Cxbx-Reloaded/subhook.git
synced 2024-12-02 16:20:35 +00:00
parent
d2a5756f49
commit
cba3854843
11
subhook.h
11
subhook.h
@ -119,7 +119,10 @@ class SubHook
|
||||
{
|
||||
public:
|
||||
SubHook() : hook_(0) {}
|
||||
SubHook(void *src, void *dst) : hook_(subhook_new(src, dst)) {}
|
||||
SubHook(void *src,
|
||||
void *dst,
|
||||
subhook_options_t options = (subhook_options_t)0)
|
||||
: hook_(subhook_new(src, dst, options)) {}
|
||||
|
||||
~SubHook() {
|
||||
subhook_remove(hook_);
|
||||
@ -134,9 +137,11 @@ public:
|
||||
return subhook_install(hook_) >= 0;
|
||||
}
|
||||
|
||||
bool Install(void *src, void *dst) {
|
||||
bool Install(void *src,
|
||||
void *dst,
|
||||
subhook_options_t options = (subhook_options_t)0) {
|
||||
if (hook_ == 0) {
|
||||
hook_ = subhook_new(src, dst);
|
||||
hook_ = subhook_new(src, dst, options);
|
||||
}
|
||||
return Install();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
add_library(test_lib SHARED test_lib.c test_lib.def)
|
||||
add_library(test_lib SHARED test_lib.cpp test_lib.def)
|
||||
target_link_libraries(test_lib subhook)
|
||||
|
||||
add_executable(test_prog test_prog.c)
|
||||
add_executable(test_prog test_prog.cpp)
|
||||
target_link_libraries(test_prog test_lib)
|
||||
|
||||
add_test(NAME test COMMAND $<TARGET_FILE:test_prog>)
|
||||
|
@ -1,4 +1,4 @@
|
||||
foo_hook\(\) called
|
||||
foo_hooked\(\) called
|
||||
foo\(\) called
|
||||
foo_hook\(\) called
|
||||
foo_hooked\(\) called
|
||||
foo\(\) called
|
||||
|
@ -4,6 +4,6 @@ void foo() {
|
||||
printf("foo() called\n");
|
||||
}
|
||||
|
||||
void foo_hook() {
|
||||
printf("foo_hook() called\n");
|
||||
void foo_hooked() {
|
||||
printf("foo_hooked() called\n");
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
EXPORTS
|
||||
foo
|
||||
foo_hook
|
||||
foo_hooked
|
||||
|
@ -1,19 +0,0 @@
|
||||
#include <subhook.h>
|
||||
|
||||
extern void foo();
|
||||
extern void foo_hook();
|
||||
|
||||
subhook_t hfoo;
|
||||
|
||||
int main() {
|
||||
hfoo = subhook_new((void *)foo, (void *)foo_hook, 0);
|
||||
subhook_install(hfoo);
|
||||
foo();
|
||||
subhook_remove(hfoo);
|
||||
foo();
|
||||
subhook_install(hfoo);
|
||||
foo();
|
||||
subhook_remove(hfoo);
|
||||
foo();
|
||||
subhook_free(hfoo);
|
||||
}
|
17
test/test_prog.cpp
Normal file
17
test/test_prog.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include <subhook.h>
|
||||
|
||||
extern void foo();
|
||||
extern void foo_hooked();
|
||||
|
||||
SubHook foo_hook;
|
||||
|
||||
int main() {
|
||||
foo_hook.Install((void *)foo, (void *)foo_hooked);
|
||||
foo();
|
||||
foo_hook.Remove();
|
||||
foo();
|
||||
foo_hook.Install();
|
||||
foo();
|
||||
foo_hook.Remove();
|
||||
foo();
|
||||
}
|
Loading…
Reference in New Issue
Block a user