def __init__(self, name, arch, base_address=0, level=logging.WARNING, parser_type=None): super(MemoryFinder, self).__init__(name, arch, base_address, level) self.parser = factories.get_parser_from_name(parser_type)(name, base_address, level)
def __init__(self, files, libraries, arch, level = logging.WARNING, parser_type = None): logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") self.logger = logging.getLogger(self.__class__.__name__) self.logger.setLevel(level) self.level = level self.arch = arch parser_class = factories.get_parser_from_name(parser_type) self.files = [] for binary_file, gadget_file, base_address in files: finder = parser = None parser = parser_class(binary_file, base_address, level) if gadget_file != None: finder = factories.get_finder_from_name("file")(gadget_file, arch, base_address, level, parser_type) else: finder = factories.get_finder_from_name("mem")(binary_file, arch, base_address, level, parser_type) self.files.append((binary_file, parser, finder)) self.libraries = {} for lib in libraries: self.libraries[lib] = parser_class(lib, 0, level)
def __init__(self, files, libraries, arch, level=logging.WARNING, parser_type=None): logging.basicConfig( format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") self.logger = logging.getLogger(self.__class__.__name__) self.logger.setLevel(level) self.level = level self.arch = arch parser_class = factories.get_parser_from_name(parser_type) self.files = [] for binary_file, gadget_file, base_address in files: finder = parser = None parser = parser_class(binary_file, base_address, level) if gadget_file != None: finder = factories.get_finder_from_name("file")(gadget_file, arch, base_address, level, parser_type) else: finder = factories.get_finder_from_name("mem")(binary_file, arch, base_address, level, parser_type) self.files.append((binary_file, parser, finder)) self.libraries = {} for lib in libraries: self.libraries[lib] = parser_class(lib, 0, level)
help='The type of file parser (cle, pyelf, radare)') parser.add_argument( '-base_address', type=str, default="0", help='The address the file is loaded at (in hex). Only needed' + ' for PIE/PIC binaries. When creating a reusable gadgets file, do not specify' ) parser.add_argument('-v', required=False, action='store_true', help='Verbose mode') parser.add_argument( 'target', type=str, help='The file (executable/library) to find symbols in') parser.add_argument('symbol', nargs="*", type=str, help='The symbol to resolve') args = parser.parse_args() parser_type = factories.get_parser_from_name(args.parser_type) logging_level = logging.DEBUG if args.v else logging.WARNING parser = parser_type(args.target, int(args.base_address, 16), logging_level) for symbol in args.symbol: address = parser.get_symbol_address(symbol) if address != None: address = hex(address) print symbol, address
def get_symbols_address(self, names): """This function tries to resolve a series of symbols""" addresses = {} for name in names: try: address = self.get_symbol_address(name) except: address = None addresses[name] = address return addresses if __name__ == "__main__": import argparse parser = argparse.ArgumentParser(description="Resolve a symbol from the supplied binary") parser.add_argument('-parser_type', type=str, default="cle", help='The type of file parser (cle, pyelf, radare)') parser.add_argument('-base_address', type=str, default="0", help='The address the file is loaded at (in hex). Only needed' + ' for PIE/PIC binaries. When creating a reusable gadgets file, do not specify') parser.add_argument('-v', required=False, action='store_true', help='Verbose mode') parser.add_argument('target', type=str, help='The file (executable/library) to find symbols in') parser.add_argument('symbol', nargs="*", type=str, help='The symbol to resolve') args = parser.parse_args() parser_type = factories.get_parser_from_name(args.parser_type) logging_level = logging.DEBUG if args.v else logging.WARNING parser = parser_type(args.target, int(args.base_address, 16), logging_level) for symbol in args.symbol: address = parser.get_symbol_address(symbol) if address != None: address = hex(address) print symbol, address
def __init__(self, name, arch, base_address = 0, level = logging.WARNING, parser_type = None): super(MemoryFinder, self).__init__(name, arch, base_address, level) self.parser = factories.get_parser_from_name(parser_type)(name, base_address, level)