-
Notifications
You must be signed in to change notification settings - Fork 2
/
processtap.h
161 lines (131 loc) · 4.26 KB
/
processtap.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
Copyright notice
================
Copyright (C) 2010
Lorenzo Martignoni <[email protected]>
Roberto Paleari <[email protected]>
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
ProcessTap is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __processtap_h__
#define __processtap_h__
#include "bloomfilter.h"
#if !defined(__i386__) && !defined(__x86_64__)
#error "unsupported cpu"
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
FUNCTION_CALL = 1,
FUNCTION_RETURN = 2,
SYSCALL_ENTRY = 4,
SYSCALL_EXIT = 8,
MEMORY_READ = 16,
MEMORY_WRITE = 32,
MEMORY_EXECUTE = 64,
} ptap_event_type_t;
typedef enum {
#if defined(__i386__) || defined(__x86_64__)
RAX = 0,
RBX,
RCX,
RDX,
RSI,
RDI,
RSP,
RBP,
RFLAGS,
RIP,
#endif
#if defined(__i386__)
EAX = 0,
EBX,
ECX,
EDX,
ESI,
EDI,
ESP,
EBP,
EFLAGS,
EIP,
#elif defined(__x86_64__)
R8,
R9,
R10,
R11,
R12,
R13,
R14,
R15,
#endif
} ptap_reg_t;
extern unsigned int event_filter;
extern bloomfilter_t *process_thread_filter;
extern bloomfilter_t *module_filter;
extern bloomfilter_t *function_filter;
extern bloomfilter_t *syscall_filter;
typedef int (*ptap_read_reg_t)(ptap_reg_t, void **);
typedef int (*ptap_write_reg_t)(ptap_reg_t, void **);
typedef int (*ptap_read_mem_t)(void *, size_t, unsigned char *);
typedef int (*ptap_write_mem_t)(void *, size_t, unsigned char *);
int ptap_init(const char *exe, const char *,
ptap_read_reg_t, ptap_write_reg_t,
ptap_read_mem_t, ptap_write_mem_t);
int ptap_fini();
int ptap_dispatch_syscall_entry(int pid, int tid, void *instrptr, void *stackptr, void *sysno);
int ptap_dispatch_syscall_exit(int pid, int tid, void *instrptr, void *stackptr, void *sysno, void *retval);
int ptap_dispatch_function_call(int pid, int tid, void *instrptr, void *stackptr, void *funcaddr);
int ptap_dispatch_function_return(int pid, int tid, void *instrptr, void *stackptr, void *funcaddr, void *retaddr, void *retval);
int ptap_add_module(int pid, const char *name, void *base, size_t size, int is_lib);
int ptap_del_module(void *base);
int ptap_add_symbol(const char *name, void *base, size_t size);
int ptap_del_symbol(void *base);
inline int ptap_instrument_event(unsigned int e) {
return (e & event_filter) > 0;
}
inline int ptap_instrument_process_thread(int id) {
return bloomfilter_contain(process_thread_filter, (unsigned char *) &id, sizeof(id));
}
inline int ptap_instrument_module(void *addr_) {
unsigned long addr = (unsigned long) addr_;
return addr < 0x10000000;
// addr &= ~0xFFF;
// return bloomfilter_contain(module_filter, (unsigned char *) &addr, sizeof(addr));
}
inline int ptap_instrument_function(void *funcaddr) {
return 1;
// return bloomfilter_contain(function_filter, (unsigned char *) &funcaddr, sizeof(funcaddr));
}
inline int ptap_instrument_syscall(void *sysno) {
return bloomfilter_contain(syscall_filter, (unsigned char *) &sysno, sizeof(sysno));
}
#if 0
inline int ptap_instrument_memory_read(void *addr, size_t size) {
unsigned char *tmp;
for (tmp = (unsigned char *) addr; tmp < ((unsigned char *) addr) + size; tmp++) {
if (!bloomfilter_contain(memory_read_filter, (unsigned char *) &tmp, sizeof(tmp)))
return 0;
}
return 1;
}
inline int ptap_instrument_memory_write(void *addr, size_t size) {
unsigned char *tmp;
for (tmp = (unsigned char *) addr; tmp < ((unsigned char *) addr) + size; tmp++) {
if (!bloomfilter_contain(memory_write_filter, (unsigned char *) &tmp, sizeof(tmp)))
return 0;
}
return 1;
}
#endif
#ifdef __cplusplus
};
#endif
#endif