-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
69 lines (59 loc) · 1.03 KB
/
test.c
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
#include "patcher.h"
#include <stdio.h>
int larger_than_ten(int arg1)
{
if (arg1 > 10)
return 1;
else
return 0;
}
int mock(int arg)
{
return 999;
}
int test_mock_simple_function()
{
int ret = 0;
patcher *p = new_patcher(larger_than_ten);
if (!p)
return -1;
ret = p->patch(p, mock);
if (ret == -1)
{
fprintf(stdout, "mock failed\n");
goto out;
}
printf("%d\n", larger_than_ten(0));
out:
p->recover(p);
release_patcher(p);
return ret;
}
int my_printf(const char *__restrict __fmt, ...)
{
fprintf(stdout, "in %s\n", __func__);
return 1;
}
int test_mock_libc_function()
{
int ret = 0;
patcher *p = new_patcher(printf);
if (!p)
return -1;
ret = p->patch(p, my_printf);
if (ret == -1)
{
fprintf(stdout, "mock failed\n");
goto out;
}
printf("hello");
out:
p->recover(p);
release_patcher(p);
return ret;
}
int main()
{
test_mock_libc_function();
test_mock_simple_function();
}