def load(self, initial=False): """Load all the commands and functions defined by UNIGDB into GDB.""" nb_missing = 0 self.commands = [(x._cmdline_, x) for x in unigdb.commands.__commands__] # load all of the functions for function_class_name in unigdb.functions.__functions__: self.loaded_functions.append(function_class_name()) def is_loaded(x): return any(filter(lambda u: x == u[0], self.loaded_commands)) for cmd, class_name in self.commands: if is_loaded(cmd): continue try: self.loaded_commands.append((cmd, class_name, class_name())) if hasattr(class_name, "_aliases_"): aliases = getattr(class_name, "_aliases_") for alias in aliases: SelfAlias(alias, cmd) except Exception as reason: self.missing_commands[cmd] = reason nb_missing += 1 # sort by command name self.loaded_commands = sorted(self.loaded_commands, key=lambda x: x[1]._cmdline_) if initial: print( "{:s} for {:s} ready, type `{:s}' to start, `{:s}' to configure" .format(Color.greenify("UNIGDB"), get_os(), Color.colorify("self", "underline yellow"), Color.colorify("self config", "underline pink"))) ver = "{:d}.{:d}".format(sys.version_info.major, sys.version_info.minor) nb_cmds = len(self.loaded_commands) print("{:s} commands loaded for GDB {:s} using Python engine {:s}". format(Color.colorify(nb_cmds, "bold green"), Color.colorify(gdb.VERSION, "bold yellow"), Color.colorify(ver, "bold red"))) if nb_missing: message.warn( "{:s} command{} could not be loaded, run `{:s}` to know why." .format(Color.colorify(nb_missing, "bold red"), "s" if nb_missing > 1 else "", Color.colorify("self missing", "underline pink"))) return None
def initial_message(): msg = "{:s} for {:s} ready, type `{:s}' to start, `{:s}' to configure\n".format( Color.greenify("UniGDB"), get_os(), Color.colorify("self", "underline yellow"), Color.colorify("self config", "underline pink") ) ver = "{:d}.{:d}".format(sys.version_info.major, sys.version_info.minor) nb_cmds = len(unigdb.commands.__commands__) msg += "{:s} commands loaded using Python engine {:s}".format( Color.colorify(nb_cmds, "bold green"), Color.colorify(ver, "bold red")) return msg
def add_command_to_doc(self, command): """Add command to UNIGDB documentation.""" cmd, class_name, _ = command if " " in cmd: # do not print subcommands in gef help return None doc = getattr(class_name, "__doc__", "").lstrip() doc = "\n ".join(doc.split("\n")) aliases = " (alias: {:s})".format(", ".join( class_name._aliases_)) if hasattr(class_name, "_aliases_") else "" msg = "{cmd:<25s} -- {help:s}{aliases:s}".format( cmd=cmd, help=Color.greenify(doc), aliases=aliases) self.docs.append(msg) return None