sarif-to-dot: to reduce graph clutter, add option --no-edges-to-scalars

This commit is contained in:
Michael Hohn
2022-01-26 00:41:31 -08:00
committed by =Michael Hohn
parent d7d566c5db
commit 153eba8346
2 changed files with 15 additions and 6 deletions

View File

@@ -26,9 +26,15 @@ parser.add_argument('-t', '--typedef-signatures', action="store_true",
help='Give every object signature a type and report by types')
parser.add_argument('-d', '--dot-output', action="store_true",
help='Output type table as dot graph. Implies -t -u')
parser.add_argument('-n', '--no-edges-to-scalars', action="store_true",
help='Suppress edges to int/bool/string types in dot graph. Implies -d')
parser.add_argument('-f', '--fill-structure', action="store_true",
help='Fill in missing (optional) entries in sarif input before other steps.')
args = parser.parse_args()
if args.no_edges_to_scalars:
args.dot_output = True
if args.dot_output:
args.unique_array_signatures = True
args.typedef_signatures = True
@@ -54,7 +60,7 @@ if args.dot_output:
for typedef, sig in struct_graph:
S.write_node(sys.stdout, typedef, sig)
for typedef, sig in struct_graph:
S.write_edges(sys.stdout, typedef, sig)
S.write_edges(args, sys.stdout, typedef, sig)
S.write_footer(sys.stdout)
elif args.typedef_signatures:

View File

@@ -137,7 +137,7 @@ def write_node(fp, typedef, sig):
""".format(name=typedef, head=typedef, body=label)
fp.write(node)
def write_edges(fp, typedef, sig):
def write_edges(args, fp, typedef, sig):
""" Write edges in dot format.
"""
if sig in ["string", "int", "bool"]:
@@ -158,10 +158,13 @@ def write_edges(fp, typedef, sig):
field_name, field_type = field
label = ""
dest = str(field_type)
edge = """ {src_node}:"{src_port}" -> {dest} [label="{label}"];
""".format(src_node=typedef, src_port=field_name, dest=field_type,
label=label)
fp.write(edge)
if dest in ["String", "Int", "Bool"] and args.no_edges_to_scalars:
pass
else:
edge = """ {src_node}:"{src_port}" -> {dest} [label="{label}"];
""".format(src_node=typedef, src_port=field_name, dest=field_type,
label=label)
fp.write(edge)
else:
raise Exception("unknown signature: " + str(sig))