├── README.md ├── LICENSE ├── __init__.py └── plugin.json /README.md: -------------------------------------------------------------------------------- 1 | # Binary Ninja HLIL Dump 2 | 3 | ## Description 4 | 5 | This is a Binary Ninja plugin written in Python that allows you to decompile the whole binary, 6 | and then dump all that in a directory. There are some scenarios where this might be helpful, 7 | for example: 8 | 9 | * Using your favorite text editor (such as Sublime) to read/find code. 10 | * Being able to `diff -u` source. 11 | * etc. 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, Wei Chen 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Description: 3 | # This is a Binary Ninja plugin that allows you to decompile all the codebase in 4 | # HLIL, so that you can do interesting things at the source level. 5 | # 6 | # Author: 7 | # Wei Chen (atxsinn3r) 8 | # https://github.com/atxsinn3r/BinjaHLILDump 9 | # 10 | 11 | from binaryninja import * 12 | import re 13 | import platform 14 | 15 | class HlilDump(BackgroundTaskThread): 16 | def __init__(self, bv, dest): 17 | BackgroundTaskThread.__init__(self, 'Dumping HLIL...', True) 18 | self.bv = bv 19 | self.dest = dest 20 | 21 | def normalize_path(self, path): 22 | if 'Windows' in platform.system(): 23 | # https://gist.github.com/doctaphred/d01d05291546186941e1b7ddc02034d3 24 | return re.sub(r'[><:"/\\|\?\*]', '_', path) 25 | else: 26 | return re.sub(r'/', '_', path) 27 | 28 | def run(self): 29 | count = 1 30 | print("Number of functions to decompile: %d" %(len(self.bv.functions))) 31 | for function in self.bv.functions: 32 | function_name = "sub_%x" %(function.start) 33 | symbol = self.bv.get_symbol_at(function.start) 34 | if hasattr(symbol, 'short_name'): 35 | func_short_name = symbol.short_name 36 | if len(self.dest) + len(func_short_name) <= 255: 37 | function_name = func_short_name 38 | 39 | print("Dumping function: %s" %(function_name)) 40 | self.progress = "Dumping HLIL: %d/%d" %(count, len(self.bv.functions)) 41 | source = '\n'.join(map(str, function.hlil.root.lines)) 42 | dest_name = os.path.join(self.dest, self.normalize_path(function_name)) 43 | f = open(dest_name, 'w') 44 | f.write(source) 45 | f.close() 46 | count += 1 47 | print('Done.') 48 | 49 | def dump_hlil(bv, function): 50 | dest = get_directory_name_input('Destination') 51 | if dest == None: 52 | print('No destination directory provided to save the decompiled source') 53 | return 54 | dest = str(dest.decode()) 55 | dump = HlilDump(bv, dest) 56 | dump.start() 57 | 58 | PluginCommand.register_for_address('HLIL Dump', 'Dumps HLIL for the whole code base', dump_hlil) 59 | -------------------------------------------------------------------------------- /plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "pluginmetadataversion": 2, 3 | "name": "HLIL Dump", 4 | "type": ["helper"], 5 | "api": ["python2", "python3"], 6 | "description": "Dumps HLIL code to a directory", 7 | "longdescription": "This plugin will dump all the code in a directory of your choice.", 8 | "license": { 9 | "name": "BSD-3-Clause", 10 | "text": "Copyright (c) 2020, Wei Chen\nAll rights reserved.\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n1. Redistributions of source code must retain the above copyright notice, this\nlist of conditions and the following disclaimer.\n2. Redistributions in binary form must reproduce the above copyright notice,\nthis list of conditions and the following disclaimer in the documentation\nand/or other materials provided with the distribution.\n3. Neither the name of the copyright holder nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 11 | }, 12 | "platforms" : ["Darwin", "Linux", "Windows"], 13 | "installinstructions" : { 14 | "Darwin" : "no special instructions, package manager is recommended", 15 | "Linux" : "no special instructions, package manager is recommended", 16 | "Windows" : "no special instructions, package manager is recommended" 17 | }, 18 | "version": "1.1", 19 | "author": "atxsinn3r", 20 | "minimumbinaryninjaversion": 2096 21 | } 22 | --------------------------------------------------------------------------------