about summary refs log tree commit diff stats
path: root/example/disasm/full.py
diff options
context:
space:
mode:
authorTim Blazytko <tim.blazytko@rub.de>2018-04-11 10:01:49 +0200
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2018-07-09 12:31:29 +0200
commitbb40c1a13c70d308091724755e00f661470046ee (patch)
tree6a3f0b86c6da63f0812f2548064ce051e9ebc9ba /example/disasm/full.py
parent89cb925f74a29f1ab6dc2dc2b2d68c4f6a9d4158 (diff)
downloadmiasm-bb40c1a13c70d308091724755e00f661470046ee.tar.gz
miasm-bb40c1a13c70d308091724755e00f661470046ee.zip
Analysis: Add SSA transformation
Joint work with Niko Schmidt
Diffstat (limited to 'example/disasm/full.py')
-rw-r--r--example/disasm/full.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/example/disasm/full.py b/example/disasm/full.py
index cf52253b..fdd220ca 100644
--- a/example/disasm/full.py
+++ b/example/disasm/full.py
@@ -9,6 +9,7 @@ from miasm2.core.interval import interval
 from miasm2.analysis.machine import Machine
 from miasm2.analysis.data_flow import dead_simp, DiGraphDefUse, ReachingDefinitions
 from miasm2.expression.simplifications import expr_simp
+from miasm2.analysis.ssa import SSAPath, SSADiGraph
 
 log = logging.getLogger("dis")
 console_handler = logging.StreamHandler()
@@ -52,6 +53,8 @@ parser.add_argument('-c', "--rawbinary", default=False, action="store_true",
 parser.add_argument('-d', "--defuse", action="store_true",
                     help="Dump the def-use graph in file 'defuse.dot'."
                     "The defuse is dumped after simplifications if -s option is specified")
+parser.add_argument('-p', "--ssa", action="store_true",
+                    help="Generate the ssa form in  'ssa.dot'.")
 
 args = parser.parse_args()
 
@@ -236,3 +239,13 @@ if args.gen_ir:
             modified |= ircfg_a.merge_blocks()
 
         open('graph_irflow_reduced.dot', 'w').write(ircfg_a.dot())
+
+    if args.ssa:
+        heads = ircfg_a.heads()
+        if len(heads) != 1:
+            raise RuntimeError("Your graph should have only one head")
+        head = list(heads)[0]
+        ssa = SSADiGraph(ircfg_a)
+        ssa.transform(head)
+
+        open("ssa.dot", "wb").write(ssa.graph.dot())