diff options
author | spacehen <root@spacehen.io> | 2022-12-30 12:05:55 +0200 |
---|---|---|
committer | Dylan Muller <dylan.muller@corigine.com> | 2023-09-07 11:54:25 +0200 |
commit | 0142fb19905808101878148ca188161f016eba5e (patch) | |
tree | ced6edf7fd130190394a2f997c87536b5ee6a8dc /tests | |
download | cdl86-0142fb19905808101878148ca188161f016eba5e.tar.gz cdl86-0142fb19905808101878148ca188161f016eba5e.zip |
CDL: Compact Detour Library
Initial commit for the CDL x86_64 detour library.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile | 16 | ||||
-rw-r--r-- | tests/basic_jmp.c | 52 | ||||
-rw-r--r-- | tests/basic_swbp.c | 52 |
3 files changed, 120 insertions, 0 deletions
diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..d28b133 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,16 @@ +IDIR=../
+CC=gcc
+CFLAGS=-I$(IDIR)
+CFILES_CDL=../cdl.c
+
+all: basic_jmp basic_swbp
+
+basic_jmp: basic_jmp.c
+ $(CC) $(CFLAGS) basic_jmp.c $(CFILES_CDL) -o basic_jmp
+basic_swbp: basic_swbp.c
+ $(CC) $(CFLAGS) basic_swbp.c $(CFILES_CDL) -o basic_swbp
+
+.PHONY: clean
+clean:
+ rm -f basic_jmp
+ rm -f basic_swbp
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;
+}
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 |