summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2018-07-11 20:32:22 -0400
committerRusty Wagner <rusty@vector35.com>2018-07-11 20:32:22 -0400
commitdfe5d28f0aaee75ccad8c733e23879676ed77c37 (patch)
treeb4b15cd48d5126e5e7a097b049fbf9aad2fca475 /python
parentbfa6fce83383e7be1458a917f8e6dbf71bdab28b (diff)
Add APIs for subclassing flow graphs
Diffstat (limited to 'python')
-rw-r--r--python/flowgraph.py40
1 files changed, 37 insertions, 3 deletions
diff --git a/python/flowgraph.py b/python/flowgraph.py
index 1568bc77..25fdc430 100644
--- a/python/flowgraph.py
+++ b/python/flowgraph.py
@@ -24,13 +24,12 @@ import traceback
# Binary Ninja components
import _binaryninjacore as core
-from enums import (BranchType, InstructionTextTokenType, HighlightColorStyle, HighlightStandardColor)
+from enums import (BranchType, InstructionTextTokenType, HighlightStandardColor)
import function
import binaryview
import lowlevelil
import mediumlevelil
import basicblock
-import architecture
import log
import interaction
import highlight
@@ -264,7 +263,12 @@ class FlowGraphNode(object):
class FlowGraph(object):
def __init__(self, handle = None):
if handle is None:
- handle = core.BNCreateFlowGraph()
+ self._ext_cb = core.BNCustomFlowGraph()
+ self._ext_cb.context = 0
+ self._ext_cb.prepareForLayout = self._ext_cb.prepareForLayout.__class__(self._prepare_for_layout)
+ self._ext_cb.populateNodes = self._ext_cb.populateNodes.__class__(self._populate_nodes)
+ self._ext_cb.completeLayout = self._ext_cb.completeLayout.__class__(self._complete_layout)
+ handle = core.BNCreateCustomFlowGraph(self._ext_cb)
self.handle = handle
self._on_complete = None
self._cb = ctypes.CFUNCTYPE(None, ctypes.c_void_p)(self._complete)
@@ -283,6 +287,36 @@ class FlowGraph(object):
return True
return ctypes.addressof(self.handle.contents) != ctypes.addressof(value.handle.contents)
+ def _prepare_for_layout(self, ctxt):
+ try:
+ self.prepare_for_layout()
+ except:
+ log.log_error(traceback.format_exc())
+
+ def _populate_nodes(self, ctxt):
+ try:
+ self.populate_nodes()
+ except:
+ log.log_error(traceback.format_exc())
+
+ def _complete_layout(self, ctxt):
+ try:
+ self.complete_layout()
+ except:
+ log.log_error(traceback.format_exc())
+
+ def finish_prepare_for_layout(self):
+ core.BNFinishPrepareForLayout(self.handle)
+
+ def prepare_for_layout(self):
+ self.finish_prepare_for_layout()
+
+ def populate_nodes(self):
+ pass
+
+ def complete_layout(self):
+ pass
+
@property
def function(self):
"""Function for a flow graph"""