-
Notifications
You must be signed in to change notification settings - Fork 26
/
gen_syscalls.py
executable file
·82 lines (72 loc) · 3.47 KB
/
gen_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
#!/usr/bin/python3
import ctags, re, simplejson, sys, os
from ctags import CTags, TagEntry
# file generated by ctags --fields=afmikKlnsStz --c-kinds=+pc -R
tags = CTags('tags')
entry = TagEntry()
sct_file = open('syscall_64.tbl', 'r')
sys_calls = []
i = 0
for line in sct_file:
if line.startswith("#"):
continue
parts = line.split()
if(len(parts) > 3 and parts[0] >= '0'):
name = parts[3]
if tags.find(entry, name.encode('utf-8'), ctags.TAG_FULLMATCH | ctags.TAG_OBSERVECASE):
found_sym = False
while(not found_sym):
if(entry['kind'] == b'prototype'):
found_sym = True
details = [i, name, entry[b'signature']]
if(entry[b'signature'] != "(void)"):
sig = entry[b'signature'].strip(b'()').split(b',')
else:
sig = [];
regs = {};
details.append("%0#4x"%(i));
if(len(sig) < 7):
for param in sig:
par = param.strip()
par_def = None
if(param.find(b"struct") != -1):
type_match = re.search("struct (\w+)", param.decode('utf-8'))
if(type_match):
par_entry = TagEntry()
if(tags.find(par_entry, type_match.group(1).encode('utf-8'), ctags.TAG_FULLMATCH|ctags.TAG_OBSERVECASE)):
if(par_entry['kind'] == 'struct'):
par_def = {'file': par_entry['file'], 'line': int(par_entry['lineNumber'])}
details.append({'type': par, 'def': par_def})
else:
details.append("param addr*")
remaining = 10 - len(details)
for x in range(0, remaining):
details.append("")
pattern = "SYSCALL_DEFINE%d(%s"%(len(sig), name.replace("sys_", ""))
search = "SYSCALL_DEFINE%d"%(len(sig))
if tags.find(entry, search.encode('utf-8'), ctags.TAG_FULLMATCH | ctags.TAG_OBSERVECASE):
found = False
while(found == False):
if(entry['pattern'].decode('utf-8').find(pattern) == 2):
#details['found'] = entry['pattern']
details.append(entry['file'])
details.append(int(entry['lineNumber']))
found = True
break
if(not tags.findNext(entry)):
details.append("not found")
details.append("")
break
else:
details.append("not found")
details.append("")
sys_calls.append(details)
else:
if(not tags.findNext(entry)):
sys_calls.append([i, "", "", "", "", "", "", "", "", "", "", ""])
break
i += 1
else:
sys_calls.append([i, "not implemented", "", "%0#4x"%(i), "", "", "", "", "", "", "", ""])
i += 1
print(simplejson.dumps({'aaData': sys_calls}, indent=" "))