├── examples ├── list_comments.png ├── textify_function.png ├── flowgraph-babypwn.png └── flowgraph-babypwn-recv.png ├── README.md ├── list_comments.py ├── LICENSE ├── __init__.py ├── plugin.json ├── textify_function.py └── flowgraph.py /examples/list_comments.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rick2600/binoculars/HEAD/examples/list_comments.png -------------------------------------------------------------------------------- /examples/textify_function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rick2600/binoculars/HEAD/examples/textify_function.png -------------------------------------------------------------------------------- /examples/flowgraph-babypwn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rick2600/binoculars/HEAD/examples/flowgraph-babypwn.png -------------------------------------------------------------------------------- /examples/flowgraph-babypwn-recv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rick2600/binoculars/HEAD/examples/flowgraph-babypwn-recv.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BINoculars (v1.0.13) 2 | Author: **rick2600** 3 | 4 | _Plugin for Binary Ninja to centralize features useful in static analysis._ 5 | 6 | ## Description: 7 | 8 | Plugin for Binary Ninja to centralize features useful in static analysis. 9 | 10 | ## Minimum Version 11 | 12 | This plugin requires the following minimum version of Binary Ninja: 13 | 14 | * release - 9999 15 | * dev - 1.0.13 16 | 17 | 18 | ## Required Dependencies 19 | 20 | The following dependencies are required for this plugin: 21 | 22 | * graphviz - graphviz 23 | 24 | 25 | ## License 26 | 27 | This plugin is released under a [MIT](LICENSE) license. 28 | 29 | 30 | -------------------------------------------------------------------------------- /list_comments.py: -------------------------------------------------------------------------------- 1 | from binaryninja import * 2 | 3 | 4 | class BinocularsListComments(BackgroundTaskThread): 5 | 6 | def __init__(self, bv, *args, **kwargs): 7 | BackgroundTaskThread.__init__(self, '', True) 8 | self.progress = "Binoculars Collecting User Comments..." 9 | self.bv = bv 10 | 11 | def do_formatting(self, comment): 12 | return comment.replace("\n", "\\n") 13 | 14 | def multi_line(self): 15 | content = "" 16 | for function in self.bv.functions: 17 | for address, comment in function.comments.iteritems(): 18 | content += (" 0x%x " %(int(address))).center(80, '=') + "\n" 19 | content += comment + "\n\n" 20 | 21 | show_plain_text_report("Binoculars List Comments", content) 22 | 23 | 24 | def run(self): 25 | self.multi_line() 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 rick2600 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | from binaryninja import * 2 | from flowgraph import * 3 | from list_comments import * 4 | from textify_function import * 5 | 6 | 7 | 8 | def __flowgraph(bv, function): 9 | flowgraph = BinocularsFlowgraph(bv, None) 10 | flowgraph.start() 11 | 12 | def __flowgraph_to_function(bv, function): 13 | flowgraph = BinocularsFlowgraph(bv, function) 14 | flowgraph.start() 15 | 16 | def __list_comments(bv): 17 | list_comments = BinocularsListComments(bv) 18 | list_comments.start() 19 | 20 | def __textify_function(bv, function): 21 | textify_function = BinocularsTextifyFunction(bv, function) 22 | textify_function.start() 23 | 24 | PluginCommand.register("[BINoculars] List Comments", "", __list_comments) 25 | PluginCommand.register_for_function("[BINoculars] Textify Function", "", __textify_function) 26 | PluginCommand.register_for_function("[BINoculars] Flowgraph (all)", "", __flowgraph) 27 | PluginCommand.register_for_function("[BINoculars] Flowgraph (this function)", "", __flowgraph_to_function) 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugin": { 3 | "name": "BINoculars", 4 | "type": ["ui"], 5 | "api": "python2", 6 | "description": "Plugin for Binary Ninja to centralize features useful in static analysis.", 7 | "longdescription": "Plugin for Binary Ninja to centralize features useful in static analysis.", 8 | "license": { 9 | "name": "MIT", 10 | "text": "Copyright (c) 2016 rick2600\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." 11 | }, 12 | "dependencies": { 13 | "graphviz": ["graphviz"] 14 | }, 15 | "version": "1.0.13", 16 | "author": "rick2600", 17 | "minimumBinaryNinjaVersion": { 18 | "dev": "1.0.13", 19 | "release": "9999" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /textify_function.py: -------------------------------------------------------------------------------- 1 | from binaryninja import * 2 | 3 | 4 | class BinocularsTextifyFunction(BackgroundTaskThread): 5 | 6 | def __init__(self, bv, function, *args, **kwargs): 7 | BackgroundTaskThread.__init__(self, '', True) 8 | self.progress = "Binoculars Textifying Function" 9 | self.bv = bv 10 | self.function = function 11 | 12 | 13 | def textify_function_plain(self): 14 | output = '' 15 | basic_blocks = sorted(self.function.basic_blocks, key=lambda bb: bb.start) 16 | 17 | for basic_block in basic_blocks: 18 | for inst in basic_block.get_disassembly_text(): 19 | if str(inst.tokens[0]) == self.function.name: continue 20 | 21 | addr = hex(inst.address).replace("L", "") 22 | offset = inst.address - self.function.start 23 | output += "%s <%s+%d>: %s\n" %\ 24 | (addr, self.function.name, offset, str(inst)) 25 | 26 | print output 27 | show_plain_text_report("Binoculars Text Disasm", output) 28 | 29 | 30 | # TODO: syntax highlight 31 | def textify_function_html(self): 32 | output = '' 33 | basic_blocks = sorted(self.function.basic_blocks, key=lambda bb: bb.start) 34 | 35 | for basic_block in basic_blocks: 36 | for inst in basic_block.get_disassembly_text(): 37 | if str(inst.tokens[0]) == self.function.name: continue 38 | 39 | addr = hex(inst.address).replace("L", "") 40 | offset = inst.address - self.function.start 41 | output += "%s <%s+%d>: %s\n" %\ 42 | (addr, self.function.name, offset, str(inst)) 43 | 44 | html = """ 45 | 46 | 47 | 48 | %s 49 | 50 | 51 | """ %(output) 52 | print html 53 | show_html_report("Binoculars Text Disasm", output) 54 | 55 | 56 | def run(self): 57 | #self.textify_function_html() 58 | self.textify_function_plain() 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /flowgraph.py: -------------------------------------------------------------------------------- 1 | from binaryninja import * 2 | import graphviz 3 | import tempfile 4 | import os 5 | 6 | # reference: http://matthiaseisen.com/articles/graphviz/ 7 | 8 | class BinocularsFlowgraph(BackgroundTaskThread): 9 | 10 | def __init__(self, bv, function, *args, **kwargs): 11 | BackgroundTaskThread.__init__(self, '', True) 12 | self.progress = "Binoculars Flowgraph Running..." 13 | self.bv = bv 14 | self.function = function 15 | 16 | def get_styles(self, label): 17 | styles = { 18 | 'graph': { 19 | 'label': label, 20 | 'fontsize': '16', 21 | 'fontcolor': 'white', 22 | #'bgcolor': '#333333', 23 | 'bgcolor': '#101010', 24 | #'rankdir': 'LR', 25 | }, 26 | 'nodes': { 27 | 'fontname': 'Helvetica', 28 | 'shape': 'box', 29 | 'fontcolor': 'white', 30 | 'color': 'white', 31 | 'style': 'filled', 32 | 'fillcolor': '#006699', 33 | }, 34 | 'edges': { 35 | #'style': 'dashed', 36 | 'color': 'white', 37 | 'arrowhead': 'open', 38 | 'fontname': 'Courier', 39 | 'fontsize': '12', 40 | 'fontcolor': 'white', 41 | } 42 | } 43 | return styles 44 | 45 | def apply_styles(self, graph, styles): 46 | graph.graph_attr.update(('graph' in styles and styles['graph']) or {}) 47 | graph.node_attr.update(('nodes' in styles and styles['nodes']) or {}) 48 | graph.edge_attr.update(('edges' in styles and styles['edges']) or {}) 49 | return graph 50 | 51 | def view_flowgraph_to_bin(self): 52 | g = graphviz.Digraph(format='png') 53 | flowgraph = self.build_flowgraph_to_bin() 54 | for node in flowgraph.keys(): 55 | g.node(node) 56 | dst = node 57 | for src in flowgraph[dst]: 58 | g.edge(src, dst) 59 | 60 | styles = self.get_styles('flowgraph') 61 | g = self.apply_styles(g, styles) 62 | g.view() 63 | 64 | def view_flowgraph_to_function(self): 65 | g = graphviz.Digraph(format='png') 66 | filename = "%s-%s" % (os.path.basename(self.bv.file.filename), self.function.symbol.name) 67 | fullpath = os.path.join(tempfile.gettempdir(), filename) 68 | 69 | flowgraph = {} 70 | self.build_flowgraph_to_function_recursive(self.function, flowgraph) 71 | for node in flowgraph.keys(): 72 | g.node(node) 73 | dst = node 74 | for src in flowgraph[node].keys(): 75 | for xref_addr in flowgraph[node][src]: 76 | g.edge(src, dst, label=hex(xref_addr).replace("L", "")) 77 | styles = self.get_styles("flowgraph '%s'" % filename) 78 | g = self.apply_styles(g, styles) 79 | filename = "%s.png" % self.function.symbol.name 80 | 81 | filename = "%s-%s" % (os.path.basename(self.bv.file.filename), self.function.symbol.name) 82 | fullpath = os.path.join(tempfile.gettempdir(), filename) 83 | g.render(fullpath) 84 | 85 | output = """ 86 | 87 | 88 | 89 |
90 | 91 |
92 | 93 | 94 | """ % (fullpath) 95 | show_html_report("Binoculars Flowgraph (this function)", output) 96 | #print flowgraph 97 | 98 | def build_flowgraph_to_bin(self): 99 | flowgraph = {} 100 | for function in self.bv.functions: 101 | flowgraph[function.symbol.name] = [] 102 | for xref in self.bv.get_code_refs(function.symbol.address): 103 | if xref.function.symbol.name not in flowgraph[function.symbol.name]: 104 | flowgraph[function.symbol.name].append(xref.function.symbol.name) 105 | return flowgraph 106 | 107 | 108 | def build_flowgraph_to_function_recursive(self, function, flowgraph): 109 | if function.symbol.name not in flowgraph.keys(): 110 | flowgraph[function.symbol.name] = {} 111 | 112 | for xref in self.bv.get_code_refs(function.symbol.address): 113 | if xref.function.symbol.name not in flowgraph[function.symbol.name].keys(): 114 | flowgraph[function.symbol.name][xref.function.symbol.name] = [] 115 | if xref.address not in flowgraph[function.symbol.name][xref.function.symbol.name]: 116 | flowgraph[function.symbol.name][xref.function.symbol.name].append(xref.address) 117 | self.build_flowgraph_to_function_recursive(xref.function, flowgraph) 118 | 119 | def run(self): 120 | if self.function == None: 121 | self.view_flowgraph_to_bin() 122 | else: 123 | self.view_flowgraph_to_function() 124 | --------------------------------------------------------------------------------