Merge pull request #194 from Terrtia/master

fix doc graph generator and add a data flow graph
This commit is contained in:
Sami Mokaddem 2018-04-06 19:16:10 +02:00 committed by GitHub
commit 699f918bc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 123 additions and 60 deletions

View file

@ -1,7 +1,10 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# -*-coding:UTF-8 -* # -*-coding:UTF-8 -*
import os import os
import argparse
def main():
content = "" content = ""
modules = {} modules = {}
@ -10,23 +13,47 @@ curr_module = ""
streamingPub = {} streamingPub = {}
streamingSub = {} streamingSub = {}
path = os.path.join(os.environ['AIL_BIN'], 'packages/modules.cfg') path = os.path.join(os.environ['AIL_BIN'], 'packages/modules.cfg') # path to module config file
path2 = os.path.join(os.environ['AIL_HOME'], 'doc/all_modules.txt') path2 = os.path.join(os.environ['AIL_HOME'], 'doc/all_modules.txt') # path and name of the output file, this file contain a list off all modules
parser = argparse.ArgumentParser(
description='''This script is a part of the Analysis Information Leak
framework. It create a graph that represent the flow between modules".''',
epilog='Example: ./generate_graph_data.py 0')
parser.add_argument('type', type=int, default=0,
help='''The graph type (default 0),
0: module graph,
1: data graph''',
choices=[0, 1], action='store')
parser.add_argument('spline', type=str, default="ortho",
help='''The graph splines type, spline:default , ortho: orthogonal''',
choices=["ortho", "spline"], action='store')
args = parser.parse_args()
with open(path, 'r') as f: with open(path, 'r') as f:
# get all modules, subscriber and publisher for each module
for line in f: for line in f:
if line[0] != '#': if line[0] != '#':
# module name
if line[0] == '[': if line[0] == '[':
curr_name = line.replace('[','').replace(']','').replace('\n', '').replace(' ', '') curr_name = line.replace('[','').replace(']','').replace('\n', '').replace(' ', '')
all_modules.append(curr_name) all_modules.append(curr_name)
modules[curr_name] = {'sub': [], 'pub': []} modules[curr_name] = {'sub': [], 'pub': []}
curr_module = curr_name curr_module = curr_name
elif curr_module != "": # searching for sub or pub elif curr_module != "": # searching for sub or pub
# subscriber list
if line.startswith("subscribe"): if line.startswith("subscribe"):
curr_subscribers = [w for w in line.replace('\n', '').replace(' ', '').split('=')[1].split(',')] curr_subscribers = [w for w in line.replace('\n', '').replace(' ', '').split('=')[1].split(',')]
modules[curr_module]['sub'] = curr_subscribers modules[curr_module]['sub'] = curr_subscribers
for sub in curr_subscribers: for sub in curr_subscribers:
streamingSub[sub] = curr_module streamingSub[sub] = curr_module
# publisher list
elif line.startswith("publish"): elif line.startswith("publish"):
curr_publishers = [w for w in line.replace('\n', '').replace(' ', '').split('=')[1].split(',')] curr_publishers = [w for w in line.replace('\n', '').replace(' ', '').split('=')[1].split(',')]
modules[curr_module]['pub'] = curr_publishers modules[curr_module]['pub'] = curr_publishers
@ -40,6 +67,11 @@ with open(path, 'r') as f:
for e in all_modules: for e in all_modules:
f2.write(e+"\n") f2.write(e+"\n")
output_text_graph = ""
# flow between modules
if args.type == 0:
for module in modules.keys(): for module in modules.keys():
for stream_in in modules[module]['sub']: for stream_in in modules[module]['sub']:
if stream_in not in streamingPub.keys(): if stream_in not in streamingPub.keys():
@ -50,20 +82,50 @@ with open(path, 'r') as f:
for stream_out in modules[module]['pub']: for stream_out in modules[module]['pub']:
if stream_out not in streamingSub.keys(): if stream_out not in streamingSub.keys():
output_set_graph.add("\"" + stream_out + "\" [color=darkorange1] ;\n") #output_set_graph.add("\"" + stream_out + "\" [color=darkorange1] ;\n")
output_set_graph.add("\"" + stream_out + "\"" + "->" + module + ";\n") output_set_graph.add("\"" + module + "\"" + "->" + stream_out + ";\n")
else: else:
output_set_graph.add("\"" + module + "\"" + "->" + streamingSub[stream_out] + ";\n") output_set_graph.add("\"" + module + "\"" + "->" + streamingSub[stream_out] + ";\n")
# graph head
output_text_graph += "digraph unix {\n"
output_text_graph += "graph [pad=\"0.5\"];\n"
output_text_graph += "size=\"25,25\";\n"
output_text_graph += "splines="
output_text_graph += args.spline
output_text_graph += ";\n"
output_text_graph += "node [color=lightblue2, style=filled];\n"
output_text_graph = ""
output_text_graph += "digraph unix {\n"\
"graph [pad=\"0.5\"];\n"\
"size=\"25,25\";\n"\
"node [color=lightblue2, style=filled];\n"
# flow between data
if args.type == 1:
for module in modules.keys():
for stream_in in modules[module]['sub']:
for stream_out in modules[module]['pub']:
if stream_in not in streamingPub.keys():
output_set_graph.add("\"" + stream_in + "\" [color=darkorange1] ;\n")
output_set_graph.add("\"" + stream_in + "\"" + "->" + stream_out + ";\n")
# graph head
output_text_graph += "digraph unix {\n"
output_text_graph += "graph [pad=\"0.5\"];\n"
output_text_graph += "size=\"25,25\";\n"
output_text_graph += "splines="
output_text_graph += args.spline
output_text_graph += ";\n"
output_text_graph += "node [color=tan, style=filled];\n"
# create final txt graph
for elem in output_set_graph: for elem in output_set_graph:
output_text_graph += elem output_text_graph += elem
output_text_graph += "}" output_text_graph += "}"
print(output_text_graph) print(output_text_graph)
if __name__ == "__main__":
main()

View file

@ -1,3 +1,4 @@
#!/bin/bash #!/bin/bash
python $AIL_HOME/doc/generate_graph_data.py | dot -T png -o $AIL_HOME/doc/module-data-flow.png python3 $AIL_HOME/doc/generate_graph_data.py 0 ortho | dot -T png -o $AIL_HOME/doc/module-data-flow.png
python3 $AIL_HOME/doc/generate_graph_data.py 1 ortho | dot -T png -o $AIL_HOME/doc/data-flow.png