-
Notifications
You must be signed in to change notification settings - Fork 3
/
sysref.py
131 lines (87 loc) · 3.75 KB
/
sysref.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
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
#!/usr/bin/env python3
import re
import sys
import argparse
from tabulate import tabulate
#headers_x86 = ["num", "syscall", "eax", "ebx", "ecx", "edx", "esi", "edi", "REF"]
#headers_x86_64 = ["num", "syscall", "rax", "rdi", "rsi", "rdx", "r10", "r8", "r9", "REF"]
#headers_arm32 = ["num", "syscall", "r7", "r0", "r1", "r2", "r3", "r4", "r5"]
#headers_arm64 = ["num", "syscall", "x8", "x0", "x1", "x2", "x3", "x4", "x5", "REF"]
def get_table(file):
table = []
for line in file:
line = line.strip("\n")
line = line.split(",")
table.append(line)
return table
def open_file(arch):
#parse arch
if arch == "x86":
headers = ["num", "syscall", "eax", "ebx", "ecx", "edx", "esi", "edi", "REF"]
file = open("intel_x86.csv", "r")
elif arch == "x64":
headers = ["num", "syscall", "rax","rdi", "rsi", "rdx", "r10", "r8", "r9", "REF"]
file = open("intel_x86_64.csv", "r")
elif arch == "arm32":
headers = ["num", "syscall", "r7", "r0", "r1", "r2", "r3", "r4", "r5"]
file = open("arm32.csv", "r")
elif arch == "arm64":
headers = ["num", "syscall", "x8", "x0", "x1", "x2", "x3", "x4", "x5", "REF"]
file = open("arm64.csv", "r")
else:
print("You have specified an architecture that is not supported")
sys.exit(0)
table = get_table(file)
return [file, table, headers]
def wide_search(keyword, file_tuple, tformat):
print("")
newtable = []
for array in file_tuple[1]:
for element in array:
if re.search(keyword, element):
newtable.append(array)
break
if (tformat == 'table'):
print(tabulate(newtable, file_tuple[2], tablefmt="fancy_grid"))
elif (tformat == 'text'):
for a in range(len(newtable)):
print(' '.join(newtable[a]))
file_tuple[0].close()
def strict_search(keyword, file_tuple, tformat):
print("")
newtable = []
for array in file_tuple[1]:
for element in array:
if (element == keyword):
newtable.append(array)
break
if (tformat == 'table'):
print(tabulate(newtable, file_tuple[2], tablefmt="fancy_grid", showindex=False))
elif (tformat == 'text'):
for a in range(len(newtable)):
print(','.join(newtable[a]))
else:
sys.exit("You have provided an invalid format.")
file_tuple[0].close()
def main():
parser = argparse.ArgumentParser()
parser.add_argument("keyword", help="Keyword to search for")
parser.add_argument("-a", "--arch", type=str, required=True,
help="Architecture to search for syscalls(x86, x64, arm32, arm64)")
parser.add_argument("-s", "--strictsearch", action="store_true",
help="Perform a specific syscall search(format: sys_open).")
parser.add_argument('--format', nargs='?', default='table', type=str,
help="The format to print the table out (table/text)")
try:
args=parser.parse_args()
except:
print("\n")
sys.exit(0)
file_tuple = open_file(args.arch)
if args.strictsearch:
strict_search(args.keyword, file_tuple, args.format)
else:
wide_search(args.keyword, file_tuple, args.format)
sys.exit(0)
if __name__== "__main__":
main()