├── LICENSE ├── README.md └── idb2gdb.py /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2018, Andrea Fioraldi 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 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * 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 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # idb2gdb 2 | Load function names from an IDA Pro database inside GDB 3 | 4 | ## commands 5 | 6 | + `idb_load ` Load function names from an IDA Pro database 7 | + `idb_list` List all function names and addresses associated to the IDB 8 | + `idb_solve ` Solve an IDB name to its address 9 | + `idb_break ` Set a breakpoint from an IDB name 10 | + `idb_clean` Delete all loaded names 11 | 12 | ## function 13 | 14 | + `$idb("function_name")` GDB function to solve an IDB name to its address 15 | 16 | e.g. `b *$idb("main")` set a breakpoint on main 17 | 18 | ## install 19 | 20 | ``` 21 | python3 -m pip install python-idb 22 | echo 'source /path/to/idb2gdb.py' >> ~/.gdbinit 23 | ``` 24 | -------------------------------------------------------------------------------- /idb2gdb.py: -------------------------------------------------------------------------------- 1 | __author__ = "Andrea Fioraldi" 2 | __copyright__ = "Copyright 2018, Andrea Fioraldi" 3 | __license__ = "BSD 2-Clause" 4 | __email__ = "andreafioraldi@gmail.com" 5 | 6 | import idb 7 | import gdb 8 | 9 | def _image_base(): 10 | try: 11 | mappings = gdb.execute("info proc mappings", to_string=True) 12 | first_num_pos = mappings.find("0x") 13 | return int(mappings[first_num_pos: mappings.find(" ", first_num_pos)], 16) 14 | except: 15 | return 0 16 | 17 | _ida_names = {} 18 | 19 | class IdbloadCommand(gdb.Command): 20 | ''' 21 | Load function names from an IDA Pro database 22 | ''' 23 | 24 | def __init__(self): 25 | super(IdbloadCommand, self).__init__("idb_load", gdb.COMPLETE_FILENAME) 26 | 27 | def invoke(self, arg, from_tty): 28 | global _ida_names 29 | self.dont_repeat() 30 | 31 | with idb.from_file(arg) as db: 32 | api = idb.IDAPython(db) 33 | base = api.idaapi.get_imagebase() 34 | for ea in api.idautils.Functions(): 35 | _ida_names[api.idc.GetFunctionName(ea)] = ea - base 36 | 37 | 38 | class IdblistCommand(gdb.Command): 39 | ''' 40 | List all function names and addresses associated to the IDB 41 | ''' 42 | 43 | def __init__(self): 44 | super(IdblistCommand, self).__init__("idb_list", gdb.COMMAND_DATA) 45 | 46 | def invoke(self, arg, from_tty): 47 | global _ida_names 48 | self.dont_repeat() 49 | 50 | if len(_ida_names) == 0: 51 | return 52 | 53 | base_addr = _image_base() 54 | long_size = gdb.lookup_type("long").sizeof * 2 55 | 56 | max_name_len = max(map(len, list(_ida_names))) 57 | for name in sorted(_ida_names, key=lambda n: _ida_names[n]): 58 | print("0x" + ("%x" % (base_addr + _ida_names[name])).zfill(long_size) + " (base+0x%x)" % _ida_names[name] + " " + name.ljust(max_name_len, " ") ) 59 | 60 | 61 | class IdbsolveCommand(gdb.Command): 62 | ''' 63 | Solve an IDB function name to its address 64 | ''' 65 | 66 | def __init__(self): 67 | super(IdbsolveCommand, self).__init__("idb_solve", gdb.COMMAND_DATA) 68 | 69 | def invoke(self, arg, from_tty): 70 | global _ida_names 71 | self.dont_repeat() 72 | 73 | try: 74 | print("0x%x" % (_image_base() + _ida_names[arg])) 75 | except KeyError: 76 | print("error: name %s not found" % arg) 77 | 78 | class IdbbreakCommand(gdb.Command): 79 | ''' 80 | Set a breakpoint from an IDB function name 81 | ''' 82 | 83 | def __init__(self): 84 | super(IdbbreakCommand, self).__init__("idb_break", gdb.COMMAND_BREAKPOINTS) 85 | 86 | def invoke(self, arg, from_tty): 87 | global _ida_names 88 | self.dont_repeat() 89 | 90 | try: 91 | addr = _image_base() + _ida_names[arg] 92 | except KeyError: 93 | print("error: name %s not found" % arg) 94 | return 95 | 96 | gdb.execute("break *0x%x" % addr) 97 | 98 | class IdbcleanCommand(gdb.Command): 99 | ''' 100 | Delete all loaded names 101 | ''' 102 | 103 | def __init__(self): 104 | super(IdbcleanCommand, self).__init__("idb_clean", gdb.COMMAND_USER) 105 | 106 | def invoke(self, arg, from_tty): 107 | global _ida_names 108 | self.dont_repeat() 109 | 110 | _ida_names = {} 111 | 112 | 113 | class IdbFunction(gdb.Function): 114 | ''' 115 | Function to solve IDB function names to its address 116 | ''' 117 | 118 | def __init__(self): 119 | super(IdbFunction, self).__init__("idb") 120 | 121 | def invoke(self, arg): 122 | global _ida_names 123 | 124 | try: 125 | return (_image_base() + _ida_names[arg.string()]) 126 | except KeyError: 127 | print("error: name %s not found" % arg) 128 | 129 | 130 | 131 | IdbloadCommand() 132 | IdblistCommand() 133 | IdbsolveCommand() 134 | IdbbreakCommand() 135 | IdbcleanCommand() 136 | IdbFunction() 137 | --------------------------------------------------------------------------------