1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/**
* @file basic_swbp.c
* @brief cdl86 asm swbp unit test
*
* cdl86
* Experimental Linux/Windows x86/x86_64 detours library.
* Author: Dylan Müller
*
* +---------------------------------------+
* | .-. .-. .-. |
* | / \ / \ / \ + |
* | \ / \ / \ / |
* | "_" "_" "_" |
* | |
* | _ _ _ _ _ _ ___ ___ _ _ |
* | | | | | | | \| | /_\ | _ \ / __| || | |
* | | |_| |_| | .` |/ _ \| /_\__ \ __ | |
* | |____\___/|_|\_/_/ \_\_|_(_)___/_||_| |
* | |
* | |
* | Lunar RF Labs |
* | https://lunar.sh |
* | |
* | Research Laboratories |
* | Donate XMR @ 'lunar.sh' (OpenAlias) |
* | Copyright (C) 2022-2024 |
* +---------------------------------------+
*/
#include <stdio.h>
#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;
}
|