From 0142fb19905808101878148ca188161f016eba5e Mon Sep 17 00:00:00 2001 From: spacehen Date: Fri, 30 Dec 2022 12:05:55 +0200 Subject: CDL: Compact Detour Library Initial commit for the CDL x86_64 detour library. --- tests/basic_swbp.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/basic_swbp.c (limited to 'tests/basic_swbp.c') diff --git a/tests/basic_swbp.c b/tests/basic_swbp.c new file mode 100644 index 0000000..684f71d --- /dev/null +++ b/tests/basic_swbp.c @@ -0,0 +1,52 @@ +#include "cdl.h" + +typedef int add_t( + __in int x, + __in int y +); + +add_t* addo = NULL; + +int add( + __in int x, + __in int y +) +{ + printf("Inside original function\n"); + return x + y; +} + +int add_detour( + __in int x, + __in int y +) +{ + printf("Inside detour function\n"); + return addo(5,5); +} + +int main( + __in void +) +{ + struct cdl_swbp_patch swbp_patch = {}; + addo = (add_t*)add; + + printf("Before attach: \n"); + printf("add(1,1) = %i\n\n", add(1,1)); + + swbp_patch = cdl_swbp_attach((void**)&addo, add_detour); + if(swbp_patch.active) + { + printf("After attach: \n"); + printf("add(1,1) = %i\n\n", add(1,1)); + printf("== DEBUG INFO ==\n"); + cdl_swbp_dbg(&swbp_patch); + } + + cdl_swbp_detach(&swbp_patch); + printf("\nAfter detach: \n"); + printf("add(1,1) = %i\n\n", add(1,1)); + + return 0; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2