Пример #1
0
    def invoke(self, args, from_tty):
        self.dont_repeat()
        if not os.access(pwngef.config.PWNGEF_RC, os.R_OK):
            return None

        quiet = args.lower() == "quiet"
        cfg = configparser.ConfigParser()
        cfg.read(pwngef.config.PWNGEF_RC)

        for section in cfg.sections():
            if section == "aliases":
                # load the aliases
                for key in cfg.options(section):
                    SelfAlias(key, cfg.get(section, key))
                continue

            # load the other options
            for optname in cfg.options(section):
                try:
                    key = "{:s}.{:s}".format(section, optname)
                    _value, _doc = pwngef.config.get(key, get_all=True)
                    new_value = cfg.get(section, optname)
                    if isinstance(_value, bool):
                        new_value = True if new_value == "True" else False
                    new_value = int(new_value) if new_value.isdigit(
                    ) or isinstance(_value, int) else new_value
                    pwngef.config.set(key, new_value, _doc)
                except Exception:
                    pass

        if not quiet:
            message.success("Configuration from '{:s}' restored".format(
                Color.colorify(pwngef.config.PWNGEF_RC, "bold blue")))
        return None
Пример #2
0
    def invoke(self, args, from_tty):
        self.dont_repeat()
        cfg = configparser.RawConfigParser()
        old_sect = None

        # save the configuration
        for key in sorted(pwngef.config.__config__):
            sect, optname = key.split(".", 1)
            value = pwngef.config.get(key)

            if old_sect != sect:
                cfg.add_section(sect)
                old_sect = sect

            cfg.set(sect, optname, value)

        # save the aliases
        cfg.add_section("aliases")
        for alias in __aliases__:
            cfg.set("aliases", alias._alias, alias._command)

        with open(pwngef.config.PWNGEF_RC, "w") as fd:
            cfg.write(fd)

        message.success("Configuration saved to '{:s}'".format(
            pwngef.config.PWNGEF_RC))
        return None
Пример #3
0
 def invoke(self, args, from_tty):
     self.dont_repeat()
     message.success("Aliases defined:")
     for _alias in __aliases__:
         print("{:30s} {} {}".format(_alias._alias,
                                     pwngef.config.RIGHT_ARROW,
                                     _alias._command))
     return None
Пример #4
0
    def invoke(self, args, from_tty):
        self.dont_repeat()
        config_arrow_right = pwngef.config.get('theme.chain_arrow_right')
        missing_commands = pwngef.config.__pwngef__.missing_commands.keys()
        if not missing_commands:
            message.success("No missing command")
            return None

        for missing_command in missing_commands:
            reason = pwngef.config.__pwngef__.missing_commands[missing_command]
            message.warn("Command `{}` is missing, reason {} {}".format(
                missing_command, config_arrow_right, reason))
        return None
Пример #5
0
 def context_additional_information(self):
     if not __context_messages__:
         return None
     self.context_title("extra")
     for level, text in __context_messages__:
         if level == "error":
             message.error(text)
         elif level == "warn":
             message.warn(text)
         elif level == "success":
             message.success(text)
         else:
             message.notice(text)
     return None
Пример #6
0
    def list_custom_structures(self):
        path = self.get_struct_path()
        if path is None:
            message.error(
                "Cannot open '{0}': check directory and/or `gef config {0}` "
                "setting, currently: '{1}'".format(
                    "pcustom.struct_path", self.get_setting("struct_path")))
            return None

        message.hint("Listing custom structures from '{:s}'".format(path))
        for filen in os.listdir(path):
            name, ext = os.path.splitext(filen)
            if ext != ".py":
                continue
            _modz = self.list_all_structs(name)
            message.success("{:s} {:s} ({:s})".format(RIGHT_ARROW, name,
                                                      ", ".join(_modz)))
        return None
Пример #7
0
    def screen_setup(self):
        """Hackish equivalent of the tmux_setup() function for screen."""
        screen = which("screen")
        sty = os.getenv("STY")
        message.success("screen session found, splitting window...")
        fd_script, script_path = tempfile.mkstemp()
        fd_tty, tty_path = tempfile.mkstemp()
        os.close(fd_tty)

        with os.fdopen(fd_script, "w") as f:
            f.write("startup_message off\n")
            f.write("split -v\n")
            f.write("focus right\n")
            f.write("screen /bin/bash -c 'tty > {}; clear; cat'\n".format(
                tty_path))
            f.write("focus left\n")

        gdb.execute("""! {} -r {} -m -d -X source {}""".format(
            screen, sty, script_path))
        # artificial delay to make sure `tty_path` is populated
        time.sleep(0.25)
        with open(tty_path, "r") as f:
            pty = f.read().strip()
        message.success("Setting `context.redirect` to '{}'...".format(pty))
        gdb.execute("pwngef config context.redirect {}".format(pty))
        message.success("Done!")
        os.unlink(script_path)
        os.unlink(tty_path)
        return None
Пример #8
0
 def __load_extra_plugins(self):
     nb_added = -1
     try:
         nb_inital = len(self.loaded_commands)
         directories = pwngef.config.get("self.extra_plugins_dir")
         if directories:
             for directory in directories.split(";"):
                 directory = os.path.realpath(os.path.expanduser(directory))
                 if os.path.isdir(directory):
                     sys.path.append(directory)
                     for fname in os.listdir(directory):
                         if not fname.endswith(".py"):
                             continue
                         fpath = "{:s}/{:s}".format(directory, fname)
                         if os.path.isfile(fpath):
                             gdb.execute("source {:s}".format(fpath))
         nb_added = len(self.loaded_commands) - nb_inital
         if nb_added > 0:
             message.success("{:s} extra commands added from '{:s}'".format(
                 Color.colorify(nb_added, "bold green"),
                 Color.colorify(directory, "bold blue")))
     except gdb.error as e:
         message.error("failed: {}".format(str(e)))
     return nb_added
Пример #9
0
 def tmux_setup(self):
     """Prepare the tmux environment by vertically splitting the current pane, and
     forcing the context to be redirected there."""
     tmux = which("tmux")
     message.success("tmux session found, splitting window...")
     old_ptses = set(os.listdir("/dev/pts"))
     gdb.execute("! {} split-window -h 'clear ; cat'".format(tmux))
     gdb.execute("! {} select-pane -L".format(tmux))
     new_ptses = set(os.listdir("/dev/pts"))
     pty = list(new_ptses - old_ptses)[0]
     pty = "/dev/pts/{}".format(pty)
     message.success("Setting `context.redirect` to '{}'...".format(pty))
     gdb.execute("pwngef config context.redirect {}".format(pty))
     message.success("Done!")
     return None
Пример #10
0
 def update_breakpoints(self):
     gdb.execute('delete breakpoints', from_tty=False)
     for bp in self.get_breakpoints():
         message.success('Set new breakpoint at %#x' % bp)
         gdb.Breakpoint('*%#x' % bp)