forked from pkmoore/CrashSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetdents_parser.py
More file actions
50 lines (46 loc) · 1.34 KB
/
getdents_parser.py
File metadata and controls
50 lines (46 loc) · 1.34 KB
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
DIRENT_TYPES = {
'DT_UNKNOWN': 0,
'DT_FIFO': 1,
'DT_CHR': 2,
'DT_DIR': 4,
'DT_BLK': 6,
'DT_REG': 8,
'DT_LNK': 10,
'DT_SOCK': 12,
'DT_WHT': 14,
}
def parse_getdents_structure(syscall_object):
if 'getdents' not in syscall_object.name:
raise ValueError('Received argument is not a getdents(64) syscall '
'object')
if syscall_object.args[1].value == '{}':
return []
left_brace = syscall_object.original_line.find('{')
right_brace = syscall_object.original_line.rfind('}')
line = syscall_object.original_line[left_brace+2:right_brace-1]
entries = line.split('} {')
tmp = []
for i in entries:
tmp += [i.split(', ')]
entries = tmp
tmp = []
tmp_dict = {}
for i in entries:
for j in i:
s = j.split('=')
k = s[0]
v = s[1]
tmp_dict[k] = v
tmp += [tmp_dict]
tmp_dict = {}
entries = tmp
for i in entries:
i['d_name'] = i['d_name'].lstrip('"').rstrip('"')
try:
i['d_type'] = DIRENT_TYPES[i['d_type']]
except KeyError:
raise NotImplementedError('Unsupported d_type: {}', i['d_type'])
i['d_ino'] = int(i['d_ino'])
i['d_reclen'] = int(i['d_reclen'])
i['d_off'] = int(i['d_off'])
return entries