summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE7
-rw-r--r--README.md26
-rw-r--r--__init__.py68
-rw-r--r--plugin.json35
-rw-r--r--screenshots/example.pngbin0 -> 165892 bytes
5 files changed, 136 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..b94cb54
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,7 @@
+Copyright (c) 2026 Gerard
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..6f5aa1b
--- /dev/null
+++ b/README.md
@@ -0,0 +1,26 @@
+# il-expr-graph
+Author: **Gerard**
+
+_il-expr-graph_
+
+## Description:
+
+Builds a visual graph from the currently selected LLIL SSA instruction
+
+Useful to get a visual representation of an instruction.
+
+## Example:
+
+![Example graph of an instruction](./screenshots/example.png)
+
+## Minimum Version
+
+9740
+
+## License
+
+This plugin is released under an [MIT license](./LICENSE).
+
+## Metadata Version
+
+2
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..c0e2126
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,68 @@
+from binaryninja import *
+from binaryninjaui import UIAction, UIActionHandler, Menu
+from PySide6.QtGui import QKeySequence
+
+
+def main(ctx):
+ from binaryninja.lowlevelil import LowLevelILInstruction, LowLevelILOperation
+ from binaryninja import log_info
+
+ def get_curr_llil_ssa(ctx):
+ """Retrieves the currently selected (UI) IL instruction"""
+ func = ctx.function
+ view = ctx.view
+ if not func:
+ log_info("Not inside a function")
+ return None
+ if view.getILViewType().view_type != FunctionGraphType.LowLevelILSSAFormFunctionGraph:
+ log_info("Function is not in llil ssa mode")
+ return None
+
+ # Get the currently selected instruction (UI)
+ ssa_idx = view.getCurrentILInstructionIndex()
+ if ssa_idx is None:
+ log_info("Failed to retrieve currently selected inst index")
+ return None
+ llil_ssa_func = func.low_level_il.ssa_form
+ inst = llil_ssa_func[ssa_idx]
+ return inst
+
+ def visit(graph, parent_node, expr, ops):
+ """Recursively visit each expression and build graph of the expression tree"""
+ if expr is None:
+ return
+ op = expr.operation
+
+ # Build graph node
+ child_node = FlowGraphNode(graph)
+ child_node.lines = [f"{op.name}"]
+ graph.append(child_node)
+ # If this is the first node in the tree it has no parent
+ if parent_node is not None:
+ parent_node.add_outgoing_edge(BranchType.UnconditionalBranch, child_node)
+
+ # Recurse through children
+ for name, kind in ops[op]:
+ print(f"{kind}: {name}")
+ if kind == "expr":
+ visit(graph, child_node, getattr(expr, name), ops)
+ elif kind == "expr_list":
+ for sub in getattr(expr, name):
+ visit(graph, child_node, sub, ops)
+
+ il_ops = LowLevelILInstruction.ILOperations
+ inst = get_curr_llil_ssa(ctx)
+ if inst is None:
+ return
+
+ graph = FlowGraph()
+ visit(graph, None, inst, il_ops)
+ # This spawns a new tab with our little graph in it
+ show_graph_report("Expression tree", graph)
+
+
+# Register a keybind for the analysis
+UIAction.registerAction("Graph LLIL SSA AST", QKeySequence("Ctrl + F3"))
+UIActionHandler.globalActions().bindAction("Graph LLIL SSA AST", UIAction(main))
+
+Menu.mainMenu("Plugins").addAction("Analyze Instruction", "Plugins")
diff --git a/plugin.json b/plugin.json
new file mode 100644
index 0000000..3db5341
--- /dev/null
+++ b/plugin.json
@@ -0,0 +1,35 @@
+{
+ "pluginmetadataversion": 2,
+ "name": "il-expr-graph",
+ "type": [
+ "core",
+ "ui",
+ "architecture",
+ "binaryview",
+ "helper"
+ ],
+ "api": [
+ "python3"
+ ],
+ "description": "il-expr-graph",
+ "longdescription": "",
+ "license": {
+ "name": "MIT",
+ "text": "Copyright (c) 2026 <user>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
+ },
+ "platforms": [
+ "Darwin",
+ "Linux",
+ "Windows"
+ ],
+ "installinstructions": {
+ "Darwin": "",
+ "Linux": "",
+ "Windows": ""
+ },
+ "dependencies": {
+ },
+ "version": "1.0.0",
+ "author": "user",
+ "minimumbinaryninjaversion": 9740
+}
diff --git a/screenshots/example.png b/screenshots/example.png
new file mode 100644
index 0000000..3e093ef
--- /dev/null
+++ b/screenshots/example.png
Binary files differ