forked from dirtyharrycallahan/pystrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapCsvtoStr.py
More file actions
78 lines (72 loc) · 1.64 KB
/
mapCsvtoStr.py
File metadata and controls
78 lines (72 loc) · 1.64 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
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
'''
map csv file to str
usage: python mapCsvtoStr.py full_path
output strdir/stand/test-case.str (contains str for 10 tests)
'''
import sys
import os
import glob
import csv
def Start(csv_list):
syscall_map = {"arch_prctl":'a',\
"pipe":'b',\
"fcntl":'c',\
"ioctl":'d',\
"write":'e',\
"mmap":'f',\
"getrlimit":'g',\
"rt_sigprocmask":'h',\
"open":'i',\
"YSCAL":'j',\
"getdents":'k',\
"set_tid_address":'l',\
"rt_sigaction":'m',\
"setrlimit":'n',\
"SIGCHLD":'o',\
"execve":'p',\
"wait4":'q',\
"munmap":'r',\
"close":'s',\
"set_robust_list":'t',\
"chdir":'u',\
"brk":'v',\
"futex":'w',\
"KILL":'x',\
"rt_sigreturn":'y',\
"mprotect":'z',\
"openat":'A',\
"read":'B',\
"getcwd":'C',\
"exit_group":'D',\
"SIGSEGV":'E',\
"fstat":'F',\
"stat":'G',\
"vfork":'H',\
"access":'I',\
"writev":'J',\
"lseek":'K',\
"madvise":'L',\
"mremap":'M'}
'''
YSCAL is SYSCALL, truncated because no "" in the log
'''
for root, dirs, csvfiles in os.walk(csv_list):
for csvfile in csvfiles:
if csvfile[-4:] == ".csv":
res_str = ""
src_file = os.path.join(root, csvfile)
#print src_file
with open(src_file, 'r') as csv_fd:
for line in csv_fd.readlines():
syscall = line.strip().split(',')[1]
res_str += syscall_map[syscall[1:-1]] #remove the ""
subdir = src_file.split('/')[-2] + '/'
dest_file = "/home/ruimin/pystrace/strdir/" + subdir + csvfile[:-4] + ".str"
#print dest_file
with open(dest_file,'a+') as f:
f.write(res_str + '\n')
#
# Entry point to the application
#
if __name__ == '__main__':
Start(sys.argv[1])