Skip to content

Commit

Permalink
GUI: Minor tweeks
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-carciofini committed Dec 10, 2024
1 parent 2a3de7a commit 073c439
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 15 additions & 6 deletions pate_binja/pate.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,13 @@ def extract_graph_rec(self,
eqCond = ConditionTrace(ccontent)
match this:
case 'Asserted':
#print('Found asserted cond for ', cfar_parent.id)
if cfar_parent.assertedConditionTrace:
cfar_parent.assertedConditionTrace.update(ccontent)
else:
cfar_parent.assertedConditionTrace = ConditionTrace(ccontent)
case 'Equivalence Condition Assumed':
#print('Found assumed cond for ', cfar_parent.id)
if cfar_parent.assumedConditionTrace:
cfar_parent.assumedConditionTrace.update(ccontent)
else:
Expand Down Expand Up @@ -731,6 +733,9 @@ def __init__(self, raw: dict, traceConstraints: Optional[list[tuple[TraceVar, st
self.trace_false = None
self.trace_footprint = None
self.update(raw)
# Debug stub
# vars = extractTraceVars(self)
# pass

def update(self, raw:dict, traceConstraints: Optional[list[tuple[TraceVar, str, str]]] = None):
self.traceConstraints = traceConstraints
Expand Down Expand Up @@ -991,13 +996,17 @@ def traceConstraintsJSONObjectHook(d: dict):
return d


def extractTraceVars(rawFootprint) -> list[TraceVar]:
def extractTraceVars(condition: ConditionTrace) -> list[TraceVar]:
footprint = condition.trace_footprint
pprint.pprint(condition.trace_footprint)
traceVars = []
#for r in raw['fp_initial_regs']['reg_op']['map']:
# traceVars.append(TraceVar('reg_op', r))
for r in rawFootprint['original']['fp_mem']:
# for r in footprint['original']['fp_initial_regs']['reg_op']['map']:
# traceVars.append(TraceVar('original', 'reg_op', r))
for r in footprint['original']['fp_mem']:
traceVars.append(TraceVar('original', 'mem_op', r))
for r in rawFootprint['patched']['fp_mem']:
# for r in footprint['patched']['fp_initial_regs']['reg_op']['map']:
# traceVars.append(TraceVar('patched', 'reg_op', r))
for r in footprint['patched']['fp_mem']:
traceVars.append(TraceVar('patched', 'mem_op', r))
# TODO: sort by instruction addr, but reverse seems to work for now
traceVars.reverse()
Expand Down Expand Up @@ -1682,7 +1691,7 @@ def simplify_sexp(sexp, env=None):
op = sexp[0]
arg = list(map(lambda x: simplify_sexp(x, env), sexp[1:]))

# ('_', 'extract', s, e)(n) => n<s,e>
# ('_', 'extract', s, e)(n) => n<s,e>
if (isinstance(op, list) and len(op) == 4 and op[0] == '_' and op[1] == 'extract'
and len(arg) == 1 and isinstance(arg[0], str)):
return f'{arg[0]}<{op[2]}:{op[3]}>'
Expand Down
4 changes: 3 additions & 1 deletion pate_binja/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,12 @@ def __init__(self, cfarNode: pate.CFARNode, parent=None):

self.cfarNode = cfarNode

self.traceVars = pate.extractTraceVars(self.cfarNode.equivalenceConditionTrace.trace_footprint)
self.traceVars = pate.extractTraceVars(self.cfarNode.equivalenceConditionTrace)
#print('trace vars:', self.traceVars)

# Prune TraceVars with no symbolic_ident
self.traceVars = [tv for tv in self.traceVars if tv.symbolic_ident is not None]
#print('trace vars pruned:', self.traceVars)

#self.resize(1500, 800)
self.setWindowTitle("Trace Constraint")
Expand Down

0 comments on commit 073c439

Please sign in to comment.