winIDEA SDK
flow_chart.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5"""
6This script generates a flow chart for a function from its disassembly information.
7Graphwiz must be installed on the system, and its bin directory in system PATH.
8"""
9
10
11import isystem.connect as ic
12import isystem.flowChart as fchart
13import isystem.diagutils as diagutils
14import subprocess as sp
15
16
17winidea_id = ''
18
19
20def main():
21 cmgr = ic.ConnectionMgr()
22 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
23
24 outFileName = 'flowChart.svg'
25
26 graphFileName = diagutils.createGraphFileName(outFileName, 'flow')
27
28 functionName = 'Func4'
29 isExpanded = True
30 isSingleCallNode = True
31 isAutoRank = True
32 isOpenInSystemViewer = True
33
34 with open(graphFileName, 'w') as outf:
35
36 graph = fchart.analyzeFunction(cmgr,
37 functionName,
38 isExpanded,
39 isSingleCallNode,
40 isAutoRank,
41 outf)
42
43 # this statement must NOT be in with statement above. as outf must be
44 # closed for dot to see complete file
45 diagutils.createGraphImage('',
46 graphFileName,
47 outFileName)
48
49 if isOpenInSystemViewer:
50 try:
51 # this opens default viewer on Windows
52 sp.check_call('start ' + outFileName, shell=True)
53 except:
54 # try with default viewer on KUbuntu
55 sp.check_call('gwenview ' + outFileName, shell=True)
56
57 print(' Done!')
58
59
60if __name__ == "__main__":
61 main()