Skip to content

Commit

Permalink
GUI: A bit of cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-carciofini committed Aug 13, 2024
1 parent 48926d7 commit d7c1b35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
14 changes: 9 additions & 5 deletions pate_binja/pate.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ def processTraceConstraints(self, traceConstraints: list[tuple[TraceVar, str, st
out.write(r']"')
verifierTraceConstraintInput = out.getvalue()

print('verifierTraceConstraintInput:', verifierTraceConstraintInput)
self.debug_io = True
#print('verifierTraceConstraintInput:', verifierTraceConstraintInput)
#self.debug_io = True
self._command('0')
# TODO: Consider generalizing command_loop rather than this processing?
while True:
Expand Down Expand Up @@ -772,7 +772,7 @@ def get_parents(self, node: CFARNode) -> list[CFARNode]:


class TraceVar:
def __init__(self, kind, raw):
def __init__(self, prefix, kind, raw):
self.kind = kind
self.raw = raw
self.pretty = 'unknown'
Expand All @@ -783,6 +783,8 @@ def __init__(self, kind, raw):
match self.kind:
case 'reg_op':
with io.StringIO() as out:
out.write(prefix)
out.write(" ")
pprint_reg(self.raw, out=out)
self.pretty = out.getvalue()
self.type = self.raw['val']['offset']['type']
Expand All @@ -791,6 +793,8 @@ def __init__(self, kind, raw):
case 'mem_op':
mem_op = raw['snd']
with io.StringIO() as out:
out.write(prefix)
out.write(" ")
out.write(f'{get_addr_id(raw["fst"])}: {mem_op["direction"]} {get_value_id(mem_op["addr"])} ')
self.pretty = out.getvalue()
offset = mem_op['value']['offset']
Expand All @@ -804,9 +808,9 @@ def extractTraceVars(rawFootprint) -> list[TraceVar]:
#for r in raw['fp_initial_regs']['reg_op']['map']:
# traceVars.append(TraceVar('reg_op', r))
for r in rawFootprint['original']['fp_mem']:
traceVars.append(TraceVar('mem_op', r))
traceVars.append(TraceVar('original', 'mem_op', r))
for r in rawFootprint['patched']['fp_mem']:
traceVars.append(TraceVar('mem_op', r))
traceVars.append(TraceVar('patched', 'mem_op', r))
# TODO: sort by instruction addr, but reverse seems to work for now
traceVars.reverse()
return traceVars
Expand Down
19 changes: 7 additions & 12 deletions pate_binja/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ def __init__(self, cfarNode, parent=None):
self.trueTraceWidget = TraceWidget(self)
trueTraceBoxLayout = QVBoxLayout()
trueTraceBoxLayout.addWidget(QLabel("Trace showing EQUIVALENT behaviour:"))
trueTraceBoxLayout.addWidget(trueTraceConstraintButton)
trueTraceBoxLayout.addWidget(self.trueTraceWidget)
trueTraceBox = QWidget()
trueTraceBox.setLayout(trueTraceBoxLayout)
Expand All @@ -510,13 +509,15 @@ def __init__(self, cfarNode, parent=None):
mainSplitter.addWidget(trueFalseSplitter)

# Main Layout
main_layout = QHBoxLayout()
main_layout = QVBoxLayout()
main_layout.addWidget(mainSplitter)
main_layout.addWidget(trueTraceConstraintButton)
self.setLayout(main_layout)

self.updateFromCfarNode()

def updateFromCfarNode(self):
self.eqCondField.clear()
with io.StringIO() as out:
pate.pprint_symbolic(out, self.cfarNode.predicate)
self.eqCondField.appendPlainText(out.getvalue())
Expand All @@ -527,23 +528,17 @@ def showTrueTraceConstraintDialog(self):
d = PateTraceConstraintDialog(self.cfarNode, parent=self)
#d.setWindowTitle(f'{d.windowTitle()} - {cfarNode.id}')
if d.exec():
print(d.getConstraints())
# TODO:
# - Get constraint form dialog
# - Send constraint to pate
# - Wait for pate to compute
# - Get new result node form pate
# TODO: Spin dialog?
traceConstraints = d.getConstraints()
#print(traceConstraints)
pw: Optional[PateWidget] = getAncestorInstanceOf(self, PateWidget)
# TODO: Better way to do this?
pw.pate_thread.pate_wrapper.processTraceConstraints(d.getConstraints())
# - update traces widgit
pw.pate_thread.pate_wrapper.processTraceConstraints(traceConstraints)
self.updateFromCfarNode()
# TODO: report failed constraint?
QMessageBox.warning(self, "Warning", "TODO: process trace constraint")

traceConstraintRelations = ["EQ", "NEQ", "LTs", "LTu", "GTs", "GTu", "LEs", "LEu", "GEs", "GEu"]


class PateTraceConstraintDialog(QDialog):
def __init__(self, cfarNode: pate.CFARNode, parent=None):
super().__init__(parent)
Expand Down

0 comments on commit d7c1b35

Please sign in to comment.