forked from ossf/fuzz-introspector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata.py
More file actions
111 lines (94 loc) · 4.2 KB
/
metadata.py
File metadata and controls
111 lines (94 loc) · 4.2 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Copyright 2022 Fuzz Introspector Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Analysis for showing metadata"""
import os
import logging
from typing import (
List, )
from fuzz_introspector import analysis
from fuzz_introspector import html_helpers
from fuzz_introspector import json_report
from fuzz_introspector.datatypes import (
project_profile,
fuzzer_profile,
)
logger = logging.getLogger(name=__name__)
class MetadataAnalysis(analysis.AnalysisInterface):
"""Creates HTML logic for saving metadata files used."""
name: str = "MetadataAnalysis"
def __init__(self) -> None:
self.json_string_result = "[]"
@classmethod
def get_name(cls):
return cls.name
def get_json_string_result(self):
return self.json_string_result
def set_json_string_result(self, json_string):
self.json_string_result = json_string
def analysis_func(self,
table_of_contents: html_helpers.HtmlTableOfContents,
tables: List[str],
proj_profile: project_profile.MergedProjectProfile,
profiles: List[fuzzer_profile.FuzzerProfile],
basefolder: str, coverage_url: str,
conclusions: List[html_helpers.HTMLConclusion],
out_dir) -> str:
logger.info('- Running analysis %s', self.get_name())
html_string = ""
html_string += "<div class=\"report-box\">"
html_string += html_helpers.html_add_header_with_link(
"Metadata section", html_helpers.HTML_HEADING.H1,
table_of_contents)
html_string += "<div class=\"collapsible\">"
html_string += """<p>This sections shows the raw data that is used
to produce this report. This is mainly used for further processing
and developer debugging.</p>
"""
html_string += "<p>"
tables.append(f"myTable{len(tables)}")
html_string += html_helpers.html_create_table_head(
tables[-1], [("Fuzzer", ""), ("Calltree file", ""),
("Program data file", ""), ("Coverage file", "")])
for profile in profiles:
if profile.coverage is None:
continue
base_datafile = os.path.basename(profile.introspector_data_file)
full_yaml_path = profile.introspector_data_file + ".yaml"
base_yamlfile = os.path.basename(full_yaml_path)
coverage_file_link_str = ""
cov_prof_files = []
for idx, cov_prof in enumerate(profile.coverage.coverage_files):
cov_prof = profile.coverage.coverage_files[idx]
cov_prof = os.path.basename(cov_prof)
cov_prof_files.append(cov_prof)
coverage_file_link_str += f"<a href=\"{cov_prof}\">{cov_prof}</a>"
if idx < len(profile.coverage.coverage_files) - 1:
coverage_file_link_str += ","
json_report.add_fuzzer_key_value_to_report(
profile.identifier, "metadata-files", {
"calltree": base_datafile,
"program-data": base_yamlfile,
"coverage": cov_prof_files
}, out_dir)
html_string += html_helpers.html_table_add_row([
profile.identifier,
f"<a href=\"{base_datafile}\">{base_datafile}</a>",
f"<a href=\"{base_yamlfile}\">{base_yamlfile}</a>",
f"{coverage_file_link_str}"
])
html_string += "</p>"
html_string += "</div>" # .collapsible
html_string += "</div>" # report-box
logger.info('- Completed analysis %s', self.get_name())
return html_string