-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyscall.py
More file actions
executable file
·91 lines (76 loc) · 2.28 KB
/
syscall.py
File metadata and controls
executable file
·91 lines (76 loc) · 2.28 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
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
import re
def getType(splitLine: list[str]) -> str:
r = []
if splitLine[1] == "STD":
for t in splitLine[1:]:
if t == "{":
break
r.append(t)
return " ".join(r)
return splitLine[1]
def getReturn(splitLine):
i = 0
while splitLine[i] != "{":
i += 1
if i == len(splitLine):
return ""
return splitLine[i + 1]
def joinLine(lines, i):
line = lines[i]
while "\\" in lines[i - 1]:
line = lines[i - 1] + line
i = i - 1
return line.replace("\\\n", " ")
def getArgs(line):
pattern = re.compile(r"\(((.*),?)\)")
matches = pattern.findall(line)
if matches == []:
return matches
return matches[0][0].replace("(", "").replace(")", "").split(",")
def getName(splitLine):
i = 0
while "(" not in splitLine[i]:
i += 1
if i == len(splitLine):
return splitLine[-1].strip()
pattern = re.compile(r".*\(")
matches = pattern.findall(splitLine[i])
return matches[0].replace("(", "").replace("*", "")
with open("./syscalls.master") as f:
lines = f.readlines()
tab = []
for i in range(len(lines)):
line = lines[i]
if line[0] == ";" or line[0] == "#":
continue
if line == "\n":
continue
if line[-2] == "\\":
continue
line = joinLine(lines, i)
line = line.replace("\t", " ")
while " " in line:
line = line.replace(" ", " ")
splitLine = line.split(" ")
dic = {"id": splitLine[0], "rax": hex(int(splitLine[0]))}
dic["type"] = getType(splitLine)
dic["return"] = getReturn(splitLine)
dic["args"] = getArgs(line)
dic["name"] = getName(splitLine)
tab.append(dic)
# print(line.strip().encode())
print(
"| NR | SYSCALL NAME | RAX | ARG0 (rdi) | ARG1 (rsi) | ARG2 (rdx) | ARG3 (rcx) | ARG4 (r8) | ARG5 (r9)"
)
print(
"| --------------- | --------------- | --------------- | --------------- | --------------- | --------------- | --------------- | --------------- | --------------- |"
)
for dic in tab:
print(f"|{dic['id']}|{dic['name']}|{dic['rax']}|", end="")
for i in range(6):
if i < len(dic["args"]):
print(f"{dic['args'][i]}", end="|")
else:
print("-", end="|")
print("")