示例#1
0
文件: ida.py 项目: int-0x03/pwngef
 def do_invoke(self, argv):
     # check connect
     if self._ida is None:
         # trying to reconnect
         self._ida = connect()
         if self._ida is None:
             self.disconnect()
             return None
     # check help
     if len(argv) == 0 or argv[0] in ("-h", "--help"):
         method_name = argv[1] if len(argv) > 1 else None
         self.usage(method_name)
         return None
     # send methods
     method_name = argv[0]
     if method_name == "versions":
         self.versions = self._ida.versions()
         message.hint(
             'Python: %(python)s\nHexRays: %(hexrays)s\nIDA: %(ida)s' %
             self.versions)
         return None
     elif method_name == 'bp':
         self.update_breakpoints()
     else:
         method = getattr(self._ida, method_name)
         if len(argv) > 1:
             args = pwngef.commands.parse_arguments(argv[1:])
             res = method(*args)
         else:
             res = method()
         print(res)
     return
示例#2
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
示例#3
0
def handle(name='Error'):
    """Displays an exception to the user, optionally displaying a full traceback
    and spawning an interactive post-moretem debugger.

    Notes:
        - ``set exception-verbose on`` enables stack traces.
        - ``set exception-debugger on`` enables the post-mortem debugger.
    """

    # This is for unit tests so they fail on exceptions instead of displaying them.
    if getattr(sys, '_pwngef_unittest_run', False) is True:
        E, V, T = sys.exc_info()
        e = E(V)
        e.__traceback__ = T
        raise e

    # Display the error
    if debug or verbose:
        exception_msg = traceback.format_exc()
        print(exception_msg)
        inform_report_issue(exception_msg)

    else:
        exc_type, exc_value, exc_traceback = sys.exc_info()

        print(
            message.error('Exception occured: {}: {} ({})'.format(
                name, exc_value, exc_type)))

        print(
            message.notice('For more info invoke `') +
            message.hint('gef config gef.exception_verbose True') +
            message.notice(
                '` and rerun the command\nor debug it by yourself with `') +
            message.hint('gef config gef.exception_debugger True') +
            message.notice('`'))

    # Break into the interactive debugger
    if debug:
        with pwngef.stdio.stdio:
            pdb.post_mortem()
示例#4
0
def inform_report_issue(exception_msg):
    """
    Informs user that he can report an issue.
    The use of `memoize` makes it reporting only once for a given exception message.
    """
    print(
        message.notice(
            "If that is an issue, you can report it on https://github.com/pwngef/pwngef/issues\n"
            "(Please don't forget to search if it hasn't been reported before)\n"
            "To generate the report and open a browser, you may run ") +
        message.hint("`bugreport --run-browser`") +
        message.notice("\nPS: Pull requests are welcome"))
示例#5
0
    def create_or_edit_structure(self, mod_name, struct_name):
        path = self.get_struct_path()
        if path is None:
            message.error("Invalid struct path")
            return None

        fullname = self.pcustom_filepath(mod_name)
        if not self.is_valid_struct(mod_name):
            message.hint("Creating '{:s}' from template".format(fullname))
            with open(fullname, "w") as f:
                f.write(self.get_template(struct_name))
                f.flush()
        else:
            message.hint("Editing '{:s}'".format(fullname))

        cmd = os.getenv("EDITOR").split() if os.getenv("EDITOR") else [
            "nano",
        ]
        cmd.append(fullname)
        retcode = subprocess.call(cmd)
        return retcode