summaryrefslogtreecommitdiff
path: root/tests/basic_jmp.c
diff options
context:
space:
mode:
authorspacehen <root@spacehen.io>2022-12-30 12:05:55 +0200
committerDylan Muller <dylan.muller@corigine.com>2023-09-07 11:54:25 +0200
commit0142fb19905808101878148ca188161f016eba5e (patch)
treeced6edf7fd130190394a2f997c87536b5ee6a8dc /tests/basic_jmp.c
downloadcdl86-0142fb19905808101878148ca188161f016eba5e.tar.gz
cdl86-0142fb19905808101878148ca188161f016eba5e.zip
CDL: Compact Detour Library
Initial commit for the CDL x86_64 detour library.
Diffstat (limited to 'tests/basic_jmp.c')
-rw-r--r--tests/basic_jmp.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/basic_jmp.c b/tests/basic_jmp.c
new file mode 100644
index 0000000..e8aa85a
--- /dev/null
+++ b/tests/basic_jmp.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_jmp_patch jmp_patch = {};
+ addo = (add_t*)add;
+
+ printf("Before attach: \n");
+ printf("add(1,1) = %i\n\n", add(1,1));
+
+ jmp_patch = cdl_jmp_attach((void**)&addo, add_detour);
+ if(jmp_patch.active)
+ {
+ printf("After attach: \n");
+ printf("add(1,1) = %i\n\n", add(1,1));
+ printf("== DEBUG INFO ==\n");
+ cdl_jmp_dbg(&jmp_patch);
+ }
+
+ cdl_jmp_detach(&jmp_patch);
+ printf("\nAfter detach: \n");
+ printf("add(1,1) = %i\n\n", add(1,1));
+
+ return 0;
+}