Skip to content

Commit

Permalink
GUI: Observable diff traces now on node rather than exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-carciofini committed Nov 22, 2024
1 parent 044ea97 commit c377010
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
33 changes: 20 additions & 13 deletions pate_binja/pate.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,28 +371,34 @@ def extract_graph_rec(self,
existing_cfar_node = cfar_graph.get(id)
cfar_node = cfar_graph.add_node(id, this, rec)

# Look for observable difference trace for this node
for n in rec['trace_node_contents']:
if n.get('pretty') == 'Observable difference found':
traceContent = rec['trace_node_contents'][n['index'] + 1]
cfar_node.observableDiffTrace = traceContent['content']
break

elif rec['trace_node_kind'] == 'blocktarget':
id = get_blocktarget_id(rec, context, cfar_parent)
existing_cfar_node = cfar_graph.get(id)
cfar_node = cfar_graph.add_node(id, this, rec)

# If we created a CFAR node and have a parent, link them up.
if cfar_node and cfar_parent:
# connect block target (ie exit) to parent
cfar_exit = cfar_node
cfar_parent.addExit(cfar_node)

if rec['trace_node_kind'] == 'blocktarget':
for c in rec['trace_node_contents']:
if c.get('content') and c['content'].get('traces', {}):
cfar_parent.addExitMetaData(cfar_exit, 'event_trace', c['content'])
# Look for event trace on this exit
for c in rec['trace_node_contents']:
if c.get('content') and c['content'].get('traces', {}):
cfar_parent.addExitMetaData(cfar_exit, 'event_trace', c['content'])
break

observableDiff = next(
(n for n in rec['trace_node_contents'] if n.get('pretty') == 'Observable difference found'), None)
if observableDiff:
traceContent = rec['trace_node_contents'][observableDiff['index'] + 1]
cfar_parent.addExitMetaData(cfar_exit, 'observable_diff_trace', traceContent['content'])
# don't go any deeper
return
# Look for observable difference trace for this node
for n in rec['trace_node_contents']:
if n.get('pretty') == 'Observable difference found':
traceContent = rec['trace_node_contents'][n['index'] + 1]
cfar_parent.observableDiffTrace = traceContent['content']
break

if self.debug_cfar:
print('CFAR ID (parent):', cfar_parent.id)
Expand Down Expand Up @@ -762,6 +768,7 @@ def __init__(self, id: str, desc: str, data: dict):
self.traceConstraints = None
self.instruction_trees = None
self.wideningInfo = None
self.observableDiffTrace = None

# After default initializations above, update the node
self.update_node(desc, data)
Expand Down
18 changes: 11 additions & 7 deletions pate_binja/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,11 @@ def nodePopupMenu(self, event: QMouseEvent, node: FlowGraphNode):
action.triggered.connect(lambda _: self.showWideningInfoDialog(cfarNode))
menu.addAction(action)

if cfarNode.observableDiffTrace:
action = QAction(f'Show Observable Diff Trace', self)
action.triggered.connect(lambda _: self.showObservableDiffTrace(cfarNode, 'Observable Diff Trace'))
menu.addAction(action)

if menu.actions():
menu.exec_(event.globalPos())

Expand All @@ -1256,6 +1261,12 @@ def showWideningInfoDialog(self, cfarNode: pate.CFARNode):
d = PateWideningInfoDialog(cfarNode, parent=self)
d.show()

def showObservableDiffTrace(self, cfarNode: pate.CFARNode, label: str = None):
d = PateCfarExitDialog(self)
d.setWindowTitle(f'Observable Diff Trace - {cfarNode.id}')
d.setTrace(cfarNode.observableDiffTrace, label)
d.show()

def edgePopupMenu(self, event: QMouseEvent, edgeTuple: tuple[FlowGraphEdge, bool]):
edge = edgeTuple[0]
incoming = edgeTuple[1] # Direction of edge depends on which half was clicked
Expand Down Expand Up @@ -1283,13 +1294,6 @@ def edgePopupMenu(self, event: QMouseEvent, edgeTuple: tuple[FlowGraphEdge, bool
sourceCfarNode.id + " to exit " + exitCfarNode.id))
menu.addAction(action)

if exitMetaData.get('observable_diff_trace'):
action = QAction(f'Show Observable Diff Trace', self)
action.triggered.connect(lambda _: self.showExitTraceInfo(sourceCfarNode, exitCfarNode,
exitMetaData['observable_diff_trace'],
'Observable Diff Trace'))
menu.addAction(action)

if menu.actions():
menu.exec_(event.globalPos())

Expand Down

0 comments on commit c377010

Please sign in to comment.