From 6492b2f828ce669162eaf6d6c3c4b260fd341b47 Mon Sep 17 00:00:00 2001 From: Ryan Stortz Date: Fri, 10 Apr 2020 10:40:18 -0400 Subject: [PATCH] SSA Variables and new graph api * Support SSARegisters, SSAVariables, and Variables in the grapher * Support SSAVariables in the match generator * Update to use newly fixed graph display api --- __init__.py | 45 ++++++++++++++++++++++++++++++++++++++++++++- plugin.json | 2 +- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 4a1a60c..582cb4b 100644 --- a/__init__.py +++ b/__init__.py @@ -49,6 +49,20 @@ if sys.version_info > (3,): long = int +def show_graph_report(bv, g, name): + + # 1.3.2086-dev + major, minor, patch = binaryninja.core_version().split('.') + major = int(major) + minor = int(minor) + patch = int(patch.split('-')[0]) + + if major == 1 and minor <= 3 and patch < 2086: + g.show(name) + return + + bv.show_graph_report(name, g) + def graph_il_insn(g, head, il, label=None): # type: (FlowGraph, FlowGraphNode, LowLevelILInstruction, Optional[str]) -> None @@ -107,6 +121,27 @@ def graph_il_insn(g, head, il, label=None): InstructionTextTokenType.IntegerToken, "{:x}".format(il), value=il ) ) + elif isinstance(il, lowlevelil.SSARegister): + tokens.append( + InstructionTextToken(InstructionTextTokenType.TextToken, "") + ) + + graph_il_insn(g, record, il.reg, "reg") + graph_il_insn(g, record, il.version, "version") + elif isinstance(il, mediumlevelil.SSAVariable): + tokens.append( + InstructionTextToken(InstructionTextTokenType.TextToken, "") + ) + + graph_il_insn(g, record, il.var, "var") + graph_il_insn(g, record, il.version, "version") + elif isinstance(il, function.Variable): + tokens.append( + InstructionTextToken(InstructionTextTokenType.TextToken, "") + ) + + graph_il_insn(g, record, il.name, "name") + graph_il_insn(g, record, il.type, "type") else: tokens.append( InstructionTextToken(InstructionTextTokenType.TextToken, str(il)) @@ -216,7 +251,7 @@ def graph_bnil(bv, addr): graph_ils(bv, g, head, function, addr) - g.show("Instruction Graph ({:#x})".format(addr)) + show_graph_report(bv, g, "Instruction Graph ({:#x})".format(addr)) def match_condition(name, o): @@ -277,6 +312,14 @@ def match_condition(name, o): match += ["if {}.version != {}:".format(name, o.version)] match += [" return False\n"] + elif isinstance(o, SSAVariable): + match += ["if {}.var.name != '{}':".format(name, o.var.name)] + match += [" return False\n"] + + match += ["if {}.version != {}:".format(name, o.version)] + match += [" return False\n"] + + else: match += ["if {} != {}:".format(name, o)] match += [" return False\n"] diff --git a/plugin.json b/plugin.json index 4528b82..55b9322 100644 --- a/plugin.json +++ b/plugin.json @@ -25,6 +25,6 @@ "Windows": "", "Linux": "" }, - "version": "1.2.1", + "version": "1.2.2", "minimumbinaryninjaversion": 0 }