x86 библиотека для хуков с полной поддержкой функторов, лямбд с захватами и прочих
Примеры кода:
C++:
Код:
int
CFASTCALL
func1
(
float
a
,
float
b
)
{
print_info
(
a
,
b
)
;
a
=
50
;
b
=
100
;
return
5
;
}
int
main
(
)
{
// func_ptr is pointer to function
auto
func_ptr
=
&
func1
;
// func_type is int(CFASTCALL*)(float, float)
using
func_type
=
decltype
(
&
func1
)
;
// Creating simple hook object with function type is template parameter and function pointer in constructor
kthook
::
kthook_signal
hook
{
func_ptr
}
;
// Connecting lambda callback that receiving function arguments by references
hook
.
before
+=
[
]
(
const
auto
&
hook
,
float
&
a
,
float
&
b
)
{
print_info
(
a
,
b
)
;
return
true
;
}
;
/*
[operator () at 31]: a = 30; b = 20
[func1 at 16 ]: a = 30; b = 20
*/
func1
(
30.f
,
20.f
)
;
}
C++:
Код:
int
main
(
)
{
auto
func_ptr
=
&
func1
;
using
func_type
=
decltype
(
&
func1
)
;
kthook
::
kthook_simple_t
hook
{
func_ptr
}
;
hook
.
before
.
connect
(
[
]
(
const
auto
&
hook
,
float
&
a
,
float
&
b
)
{
print_info
(
a
,
b
)
;
// changing arguments
a
=
50.f
,
b
=
30.f
;
return
true
;
}
)
;
// connect after callback
hook
.
after
.
connect
(
[
]
(
const
auto
&
hook
,
int
&
return_value
,
float
&
a
,
float
&
b
)
{
print_info
(
a
,
b
)
;
print_return_value
(
return_value
)
;
// changing return_value
return_value
=
20
;
return
true
;
}
)
;
/*
[operator () at 31]: a = 30; b = 20
[func1 at 16 ]: a = 50; b = 30
[operator () at 34]: a = 50; b = 30
[operator () at 34]: return_value = 5;
[main at 20]: return_value = 20;
*/
auto
ret_val
=
func1
(
30.f
,
20.f
)
;
print_return_value
(
ret_val
)
}