-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.h
92 lines (75 loc) · 1.42 KB
/
main.h
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
86
87
88
89
90
91
92
#define TASK_COMM_LEN 16
#define MAX_NAME 8
#define MAX_PIPE_NUM 10
struct event_t {
u32 pid;
u32 ret;
char hidden_pid[MAX_NAME];
char comm[TASK_COMM_LEN];
};
struct pipe_pair_t {
int read_fd;
int write_fd;
};
struct pipe_point_t {
u32 pid;
int *fildes;
};
struct pipe_fd_key_t {
u32 pid;
int fd;
};
struct pipe_fd_val_t {
int read_fd;
int write_fd;
};
struct fork_t {
u32 ppid;
u32 pid;
};
struct dup_fd_key_t {
u32 pid;
int src_fd;
};
struct dup_fd_val_t {
int target_fd;
};
struct read_buf_key_t {
u32 pid;
void *buf;
};
struct read_buf_t {
long unsigned int buf_p;
int read_count;
};
struct write_buf_t {
int write_count;
};
static __always_inline void get_file_path(const struct file *file, char *buf, size_t size)
{
struct qstr dname;
dname = BPF_CORE_READ(file, f_path.dentry, d_name);
bpf_probe_read_kernel(buf, size, dname.name);
}
static __always_inline bool str_eq(const char *a, const char *b, int len)
{
#pragma unroll
for (int i = 0; i < len; i++) {
if (a[i] != b[i])
return false;
if (a[i] == '\0')
break;
}
return true;
}
static __always_inline int str_len(const char *s, int max_len)
{
#pragma unroll
for (int i = 0; i < max_len; i++) {
if (s[i] == '\0')
return i;
}
if (s[max_len - 1] != '\0')
return max_len;
return 0;
}