-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_securifyreport_to_latex.py
72 lines (52 loc) · 1.68 KB
/
convert_securifyreport_to_latex.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
with open('report_securify_nocolor.txt', 'r') as file:
dataraw = file.read()
data = dataraw.split("\n\n")
print("""
\lstnewenvironment{tabularlstlisting}[1][]
{%
\lstset{aboveskip=-0.05ex,belowskip=-3.5ex,#1}%
}
{}
""")
latexstr="""
\\begin{{table}}[]
\\hskip-1.0cm\\begin{{tabular}}{{|l|m{{17cm}}|}}
\\hline
Severity & {}\\\\ \\hline
Pattern & {}\\\\ \\hline
Description & {}\\\\ \\hline
Code &
\\begin{{tabularlstlisting}}[language=Solidity]
{}
\\end{{tabularlstlisting}}
\\\\ \\hline
\\end{{tabular}}
\\end{{table}}
"""
for d in data:
if "Severity" not in d:
continue
issue = [ i for i in d.split("\n") if i!=""]
beg = [False for i in range(0,6)]
for i in range(0, len(issue)):
if "Severity" in issue[i]:
beg[0] = i
if "Pattern" in issue[i]:
beg[1] = i
if "Description" in issue[i]:
beg[2] = i
if "Type" in issue[i]:
beg[3] = i
if "Source" in issue[i]:
beg[4] = i
#print(beg)
severity = [s for s in issue if "Severity" in s][0].split(":")[1].lstrip()
pattern =[s for s in issue if "Pattern" in s][0].split(":")[1].lstrip()
desc = " ".join([i.lstrip() for i in issue][beg[2]:beg[3]])
type = "\n".join(issue[beg[3]:beg[3]])
code = "\n".join([i[1:].lstrip() for i in issue if i.lstrip() !="" or i.lstrip()][beg[4]+1:])
code= code.replace("^^^", "")
code = code.replace("\n\n", "")
extracted=[severity, pattern, desc, type, code]
#print(extracted)
print(latexstr.format(extracted[0], extracted[1], extracted[2], extracted[4]))