From 8493ca2ad26d4f6b2aaab8b7600bda2e52b2b131 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sun, 27 Mar 2022 20:24:16 +0300 Subject: [PATCH 1/2] Optimized the generic dominator calculation a bit by preventing redundant initial calculations --- miasm/core/graph.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/miasm/core/graph.py b/miasm/core/graph.py index 0dfd7e6ac..c414225ec 100644 --- a/miasm/core/graph.py +++ b/miasm/core/graph.py @@ -416,15 +416,11 @@ def _compute_generic_dominators(head, reachable_cb, prev_cb, next_cb): dominators[node] = set(nodes) dominators[head] = set([head]) - todo = set(nodes) + todo = set([succ for succ in next_cb(head)]) while todo: node = todo.pop() - # Heads state must not be changed - if node == head: - continue - # Compute intersection of all predecessors'dominators new_dom = None for pred in prev_cb(node): @@ -446,6 +442,7 @@ def _compute_generic_dominators(head, reachable_cb, prev_cb, next_cb): dominators[node] = new_dom for succ in next_cb(node): todo.add(succ) + return dominators def compute_dominators(self, head): From 9bc1a8f56d7742b17c973a6fffdcbf47ae3432fe Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sun, 27 Mar 2022 21:33:11 +0300 Subject: [PATCH 2/2] Bugfix - the assumption that the head node can never be a sucessor of any node in the graph is correct, but this is a *generic* function, so it should handle postdominators as well, whose head can be a predecessor of some node in the graph. Thus, the node == head check is still required. --- miasm/core/graph.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/miasm/core/graph.py b/miasm/core/graph.py index c414225ec..0d7ce52f4 100644 --- a/miasm/core/graph.py +++ b/miasm/core/graph.py @@ -416,11 +416,15 @@ def _compute_generic_dominators(head, reachable_cb, prev_cb, next_cb): dominators[node] = set(nodes) dominators[head] = set([head]) - todo = set([succ for succ in next_cb(head)]) + todo = set([n for n in next_cb(head)]) while todo: node = todo.pop() + # Head's state must not be changed + if node == head: + continue + # Compute intersection of all predecessors'dominators new_dom = None for pred in prev_cb(node):