forked from droundy/fac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
categorize_bsd_syscalls.py
89 lines (68 loc) · 2.19 KB
/
categorize_bsd_syscalls.py
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
#!/usr/bin/python2
import sys, re, os
if len(sys.argv) != 2:
print "usage: python2 %s syscalls-file > syscalls.h" % sys.argv[0]
sys.exit(1)
linux_dir = sys.argv[1]
re_syscall = re.compile(r'/\* (\d+) = (\S+)')
def bool_table(name, syscalls):
print """
const int %s[] = {""" % (name)
for i in range(maxnum):
if sysnames[i] in syscalls:
print ' 1,'
else:
print ' 0,'
if sysnames[maxnum] in syscalls:
print ' 1'
else:
print ' 0'
print "};\n"
def argument_table(name, syscall_argument):
print """
const int %s[] = {""" % (name)
for i in range(maxnum):
if sysnames[i] in syscall_argument:
print ' %d,' % syscall_argument[sysnames[i]]
else:
print ' -1,'
if sysnames[maxnum] in syscall_argument:
print ' %d' % syscall_argument[sysnames[maxnum]]
else:
print ' -1'
print "};\n"
with open(sys.argv[1], 'r') as syscalls_file:
syscalls = syscalls_file.read()
sysnames = {}
sysnums = {}
maxnum = 0
for (num, syscall) in re_syscall.findall(syscalls):
num = int(num)
sysnames[num] = syscall
sysnames[syscall] = num
maxnum = max(maxnum, num)
print "\nconst char *syscalls[] = {"
for i in range(maxnum):
if i not in sysnames:
sysnames[i] = 'unused'
for i in range(maxnum):
print ' "%s",' % sysnames[i]
print ' "%s"' % sysnames[maxnum]
print "};\n"
argument_table('write_string', {'rename': 1,
'truncate': 0})
argument_table('read_string', {'rename': 1,
'stat': 0,
'lstat': 0,
'stat64': 0,
'lstat64': 0,
'execve': 0,
'truncate': 0})
argument_table('unlink_string', {'unlink': 0,
'rmdir': 0,
'rename': 0})
argument_table('unlinkat_string', {'unlinkat': 0,
'renameat': 0})
argument_table('renameat_string', {'renameat': 2})
argument_table('readdir_fd', {'getdents': 0,
'getdents64': 0})