Skip to content

Commit a4a2b5a

Browse files
committed
Fix the block edges in generated graphs
1 parent c4c0e86 commit a4a2b5a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

crimson_forge/base.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ def size(self):
146146
return len(self.bytes)
147147

148148
class DiGraphBase(networkx.DiGraph):
149+
def _graph_edges(self):
150+
return self.edges
151+
149152
def _graphml_id(self, node):
150153
return node
151154

@@ -168,7 +171,7 @@ def _graphml_graph(self, parent, id_prefix=''):
168171
if hasattr(node, 'to_digraph'):
169172
digraph = node.to_digraph()
170173
digraph._graphml_graph(element, id_prefix=xml_node_id + ':')
171-
for parent_node, child_node in self.edges:
174+
for parent_node, child_node in self._graph_edges():
172175
element = ElementTree.SubElement(graph, 'edge', attrib={
173176
'source': id_prefix + self._graphml_id(parent_node),
174177
'target': id_prefix + self._graphml_id(child_node)

crimson_forge/segment.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import crimson_forge.tailor as tailor
4545

4646
import angr
47+
import boltons.iterutils
4748
import capstone
4849
import keystone
4950

@@ -78,12 +79,16 @@ def __init__(self, blocks, *args, **kwargs):
7879
super(BlocksDiGraph, self).__init__(*args, **kwargs)
7980
self._blocks = blocks
8081
t_blocks = tuple(blk for blk in self._blocks if isinstance(blk, block.BasicBlock))
81-
8282
self.add_nodes_from(t_blocks)
8383
for blk in t_blocks:
8484
for child in blk.children.values():
8585
self.add_edge(blk, child)
8686

87+
def _graph_edges(self):
88+
# override this because block-edges are flow directions and not positional constraints like they are in other
89+
# digraphs
90+
return boltons.iterutils.pairwise(sorted(self.nodes, key=lambda block: block.address))
91+
8792
def _graphml_id(self, blk):
8893
return "block.0x{:04x}".format(blk.address)
8994

0 commit comments

Comments
 (0)