コード例 #1
0
    def run(self, args):
        proc = self.proc
        dbg_obj = self.core.debugger

        # We'll use a rough estimate of 4 bytes per instruction and
        # go off listsize
        listsize = dbg_obj.settings['listsize'] * 4
        curframe = proc.curframe

        opts = {
            'highlight': self.settings['highlight'],
            'start_line': 1,
            'end_line': None,
            'start_offset': None,
            'end_offset': None,
            'relative_pos': False,
        }

        do_parse = True
        if len(args) == 2:
            try:
                obj = self.proc.eval(args[1])
                opts['start_offset'] = 0
                is_offset = True
                start = 0
                last = dbg_obj.settings['listsize'] * 4
                last_is_offset = False
                if (inspect.ismethod(obj) or inspect.isfunction(obj)
                        or inspect.isgeneratorfunction(obj)
                        or inspect.isgenerator(obj) or inspect.isframe(obj)
                        or inspect.iscode(obj)):
                    do_parse = False
            except:
                pass

        if do_parse:
            (bytecode_file, start, is_offset, last, last_is_offset,
             obj) = parse_addr_list_cmd(proc, args, listsize)
            if bytecode_file is None: return

        if is_offset:
            opts['start_offset'] = start
        else:
            opts['start_line'] = start
        if last_is_offset:
            opts['end_offset'] = last
        else:
            opts['end_line'] = last

        if not (obj or bytecode_file.endswith('.pyo')
                or bytecode_file.endswith('pyc')):
            bytecode_file = cache_from_source(bytecode_file)
            if bytecode_file and Mfile.readable(bytecode_file):
                self.msg("Reading %s ..." % bytecode_file)
                (version, timestamp, magic_int, obj, is_pypy,
                 source_size) = load_module(bytecode_file)
            elif not curframe:
                self.errmsg("No frame selected.")
                return
            else:
                try:
                    obj = self.proc.eval(args[1])
                    opts['start_line'] = -1
                except:
                    self.errmsg(("Object '%s' is not something we can" +
                                 " disassemble.") % args[1])
                    return

        # We now have all  information. Do the listing.
        (self.object, proc.list_offset) = Mdis.dis(self.msg, self.msg_nocr,
                                                   self.section, self.errmsg,
                                                   obj, **opts)
        return False
コード例 #2
0
ファイル: disassemble.py プロジェクト: rocky/python2-trepan
    def run(self, args):
        proc = self.proc

        # FIXME: add a setting for assembler list size
        listsize = 4

        opts = {
            "highlight": self.settings["highlight"],
            "start_line": 1,
            "end_line": None,
            "start_offset": None,
            "end_offset": None,
            "relative_pos": False,
            "asm_format": self.settings["asmfmt"],
        }

        curframe = proc.curframe
        if curframe:
            line_no = inspect.getlineno(curframe)
            opts["start_line"] = line_no - 1
            opts["end_line"] = line_no + 1

        do_parse = True
        if len(args) == 2:
            if args[1].endswith("()"):
                eval_args = args[1][:-2]
            else:
                eval_args = args[1]
            try:
                obj = self.proc.eval(eval_args, show_error=False)
            except:
                obj = None
            else:
                if (inspect.ismethod(obj) or inspect.isfunction(obj)
                        or inspect.isgeneratorfunction(obj)
                        or inspect.isgenerator(obj) or inspect.isframe(obj)
                        or inspect.iscode(obj)):
                    opts["start_offset"] = 0
                    last_is_offset = is_offset = True
                    start = 0
                    opts["start_line"] = 0
                    opts["end_line"] = last = None
                    do_parse = False
                    bytecode_file = None

        if do_parse:
            (
                bytecode_file,
                start,
                is_offset,
                last,
                last_is_offset,
                obj,
            ) = parse_addr_list_cmd(proc, args, listsize)
            if bytecode_file is None:
                return

        if is_offset:
            opts["start_offset"] = start
        else:
            opts["start_line"] = start
        if last_is_offset:
            opts["end_offset"] = last
        else:
            opts["end_line"] = last

        if not obj and (bytecode_file and (not bytecode_file.endswith(".pyo")
                                           or bytecode_file.endswith("pyc"))):
            # bytecode_file may be a source file. Try to tun it into a bytecode file for diassembly.
            bytecode_file = cache_from_source(bytecode_file)
            if bytecode_file and Mfile.readable(bytecode_file):
                self.msg("Reading %s ..." % bytecode_file)
                (
                    version,
                    timestamp,
                    magic_int,
                    obj,
                    is_pypy,
                    source_size,
                    sip_hash,
                ) = load_module(bytecode_file)
            elif not curframe:
                self.errmsg("No frame selected.")
                return
            else:
                try:
                    obj = self.proc.eval(args[1])
                    opts["start_line"] = -1
                except:
                    self.errmsg(("Object '%s' is not something we can" +
                                 " disassemble.") % args[1])
                    return

        # We now have all  information. Do the listing.
        (obj, proc.list_offset) = dis(self.msg, self.msg_nocr, self.section,
                                      self.errmsg, obj, **opts)
        return False
コード例 #3
0
ファイル: disassemble.py プロジェクト: zed/python3-trepan
    def run(self, args):
        relative_pos = False
        opts = {
            'highlight': self.settings['highlight'],
            'start_line': -1,
            'end_line': None
        }

        if len(args) > 1:
            start, opts['relative_pos'], is_offset = self.parse_arg(args[1])
            if start is None:
                # First argument should be an evaluatable object
                # or a filename
                bytecode_file = args[1]
                have_code = False
                if not (bytecode_file.endswith('.pyo')
                        or bytecode_file.endswith('pyc')):
                    bytecode_file = cache_from_source(bytecode_file)
                if bytecode_file and Mfile.readable(bytecode_file):
                    print("Reading %s ..." % bytecode_file)
                    version, timestamp, magic_int, obj = uncompyle6.load.load_module(
                        bytecode_file)
                    have_code = True
                elif not self.proc.curframe:
                    self.errmsg("No frame selected.")
                    return
                else:
                    try:
                        obj = self.proc.eval(args[1])
                        opts['start_line'] = -1
                    except:
                        self.errmsg(("Object '%s' is not something we can" +
                                     " disassemble.") % args[1])
                        return
                    pass
                if len(args) > 2:
                    start, opts['relative_pos'], is_offset = self.parse_arg(
                        args[2])
                    if start is None:
                        ilk = 'line' if is_offset else 'offset'

                        self.errmsg = ('Start %s should be a number. Got %s.' %
                                       (ilk, args[2]))
                        return
                    else:
                        opts['start_offset'
                             if is_offset else 'start_line'] = start
                    if len(args) == 4:
                        finish, relative_pos, is_offset = self.parse_arg(
                            args[3])
                        if finish is None:
                            self.errmsg = ('End %s should be a number. ' +
                                           ' Got %s.' % (ilk, args[3]))
                            return
                        else:
                            opts['end_offset'
                                 if is_offset else 'end_line'] = finish
                        pass
                    elif len(args) > 4:
                        self.errmsg("Expecting 0-3 parameters. Got %d" %
                                    len(args) - 1)
                        return
                    pass
                elif not have_code:
                    try:
                        obj = Mcmdfns.get_val(self.proc.curframe, self.errmsg,
                                              args[1])
                    except:
                        return
                    pass
                Mdis.dis(self.msg, self.msg_nocr, self.section, self.errmsg,
                         obj, **opts)
                return False
            else:
                opts['start_offset' if is_offset else 'start_line'] = start
                if len(args) == 3:
                    finish, not_used, is_offset = self.parse_arg(args[2])
                    if finish is None:
                        self.errmsg = ('End line should be a number. ' +
                                       ' Got %s.' % args[2])
                        return
                    else:
                        opts[
                            'end_offset' if is_offset else 'end_line'] = finish
                    pass
                elif len(args) > 3:
                    self.errmsg("Expecting 1-2 line parameters. Got %d." %
                                len(args) - 1)
                    return False
                pass
            pass
        elif not self.proc.curframe:
            self.errmsg("No frame selected.")
            return

        Mdis.dis(self.msg, self.msg_nocr, self.section, self.errmsg,
                 self.proc.curframe, **opts)
        return False
コード例 #4
0
    def run(self, args):
        start_line = -1
        end_line = None
        relative_pos = False
        if len(args) > 1:
            start_line, relative_pos = self.parse_arg(args[1])
            if start_line is None:
                # First argument should be an evaluatable object
                # or a filename
                if args[1].endswith('.pyc') and Mfile.readable(args[1]):
                    magic, moddate, modtime, obj = Mdis.pyc2code(args[1])
                elif not self.proc.curframe:
                        self.errmsg("No frame selected.")
                        return
                else:
                    try:
                        obj=self.proc.eval(args[1])
                        start_line = -1
                    except:
                        self.errmsg(("Object '%s' is not something we can"
                                     + " disassemble.") % args[1])
                        return
                    pass
                if len(args) > 2:
                    start_line, relative_pos = self.parse_arg(args[2])
                    if start_line is None:
                        self.errmsg = ('Start line should be a number. Got %s.'
                                       % args[2])
                        return
                    if len(args) == 4:
                        end_line, relative_pos = self.parse_arg(args[3])
                        if end_line is None:
                            self.errmsg = ('End line should be a number. ' +
                                           ' Got %s.' % args[3])
                            return
                        pass
                    elif len(args) > 4:
                        self.errmsg("Expecting 0-3 parameters. Got %d" %
                                    len(args)-1)
                        return
                    pass
                else:
                    try:
                        obj=Mcmdfns.get_val(self.proc.curframe,
                                            self.errmsg, args[1])
                    except:
                        return
                    pass
                Mdis.dis(self.msg, self.msg_nocr, self.section, self.errmsg,
                         obj, start_line=start_line, end_line=end_line,
                         relative_pos=relative_pos)
                return False
            else:
                if len(args) == 3:
                    end_line, not_used = self.parse_arg(args[2])
                    if end_line is None:
                        self.errmsg = ('End line should be a number. ' +
                                       ' Got %s.' % args[2])
                        return
                    pass
                elif len(args) > 3:
                    self.errmsg("Expecting 1-2 line parameters. Got %d." %
                                len(args)-1)
                    return False
                pass
            pass
        elif not self.proc.curframe:
            self.errmsg("No frame selected.")
            return

        Mdis.dis(self.msg, self.msg_nocr, self.section, self.errmsg,
                 self.proc.curframe,
                 start_line=start_line, end_line=end_line,
                 relative_pos=relative_pos)
        return False
コード例 #5
0
ファイル: disassemble.py プロジェクト: melviso/python2-trepan
    def run(self, args):
        relative_pos = False
        opts = {'highlight': self.settings['highlight'],
                'start_line': -1,
                'end_line': None
                }

        if len(args) > 1:
            start, opts['relative_pos'], is_offset = self.parse_arg(args[1])
            if start is None:
                # First argument should be an evaluatable object
                # or a filename
                if args[1].endswith('.pyc') and Mfile.readable(args[1]):
                    magic, moddate, modtime, obj = Mdis.pyc2code(args[1])
                elif not self.proc.curframe:
                        self.errmsg("No frame selected.")
                        return
                else:
                    try:
                        obj=self.proc.eval(args[1])
                        opts['start_line'] = -1
                    except:
                        self.errmsg(("Object '%s' is not something we can"
                                     + " disassemble.") % args[1])
                        return
                    pass
                if len(args) > 2:
                    start, opts['relative_pos'], is_offset = self.parse_arg(args[2])
                    if start is None:
                        ilk = 'line' if is_offset else 'offset'

                        self.errmsg = ('Start %s should be a number. Got %s.'
                                       % (ilk, args[2]))
                        return
                    else:
                        opts['start_offset' if is_offset else 'start_line'] = start
                    if len(args) == 4:
                        finish, relative_pos, is_offset = self.parse_arg(args[3])
                        if finish is None:
                            self.errmsg = ('End %s should be a number. ' +
                                           ' Got %s.' % (ilk, args[3]))
                            return
                        else:
                            opts['end_offset' if is_offset else 'end_line'] = finish
                        pass
                    elif len(args) > 4:
                        self.errmsg("Expecting 0-3 parameters. Got %d" %
                                    len(args)-1)
                        return
                    pass
                else:
                    try:
                        obj=Mcmdfns.get_val(self.proc.curframe,
                                            self.errmsg, args[1])
                    except:
                        return
                    pass
                Mdis.dis(self.msg, self.msg_nocr, self.section, self.errmsg,
                         obj, **opts)
                return False
            else:
                opts['start_offset' if is_offset else 'start_line'] = start
                if len(args) == 3:
                    finish, not_used, is_offset = self.parse_arg(args[2])
                    if finish is None:
                        self.errmsg = ('End line should be a number. ' +
                                       ' Got %s.' % args[2])
                        return
                    else:
                        opts['end_offset' if is_offset else 'end_line'] = finish
                    pass
                elif len(args) > 3:
                    self.errmsg("Expecting 1-2 line parameters. Got %d." %
                                len(args)-1)
                    return False
                pass
            pass
        elif not self.proc.curframe:
            self.errmsg("No frame selected.")
            return

        Mdis.dis(self.msg, self.msg_nocr, self.section, self.errmsg,
                 self.proc.curframe,  **opts)
        return False
コード例 #6
0
ファイル: disassemble.py プロジェクト: whcchoi/python2-trepan
    def run(self, args):
        relative_pos = False
        opts = {'highlight': self.settings['highlight'],
                'start_line': -1,
                'end_line': None
                }

        if len(args) > 1:
            start, opts['relative_pos'], is_offset = self.parse_arg(args[1])
            if start is None:
                # First argument should be an evaluatable object
                # or a filename
                bytecode_file = args[1]
                have_code = False
                if not (bytecode_file.endswith('.pyo') or
                        bytecode_file.endswith('pyc')):
                    bytecode_file = cache_from_source(bytecode_file)
                if bytecode_file and Mfile.readable(bytecode_file):
                    print("Reading %s ..." % bytecode_file)
                    version, timestamp, magic_int, obj = uncompyle6.load.load_module(bytecode_file)
                    have_code = True
                elif not self.proc.curframe:
                        self.errmsg("No frame selected.")
                        return
                else:
                    try:
                        obj=self.proc.eval(args[1])
                        opts['start_line'] = -1
                    except:
                        self.errmsg(("Object '%s' is not something we can"
                                     + " disassemble.") % args[1])
                        return
                    pass
                if len(args) > 2:
                    start, opts['relative_pos'], is_offset = self.parse_arg(args[2])
                    if start is None:
                        ilk = 'line' if is_offset else 'offset'

                        self.errmsg = ('Start %s should be a number. Got %s.'
                                       % (ilk, args[2]))
                        return
                    else:
                        opts['start_offset' if is_offset else 'start_line'] = start
                    if len(args) == 4:
                        finish, relative_pos, is_offset = self.parse_arg(args[3])
                        if finish is None:
                            self.errmsg = ('End %s should be a number. ' +
                                           ' Got %s.' % (ilk, args[3]))
                            return
                        else:
                            opts['end_offset' if is_offset else 'end_line'] = finish
                        pass
                    elif len(args) > 4:
                        self.errmsg("Expecting 0-3 parameters. Got %d" %
                                    len(args)-1)
                        return
                    pass
                elif not have_code:
                    try:
                        obj=Mcmdfns.get_val(self.proc.curframe,
                                            self.errmsg, args[1])
                    except:
                        return
                    pass
                Mdis.dis(self.msg, self.msg_nocr, self.section, self.errmsg,
                         obj, **opts)
                return False
            else:
                opts['start_offset' if is_offset else 'start_line'] = start
                if len(args) == 3:
                    finish, not_used, is_offset = self.parse_arg(args[2])
                    if finish is None:
                        self.errmsg = ('End line should be a number. ' +
                                       ' Got %s.' % args[2])
                        return
                    else:
                        opts['end_offset' if is_offset else 'end_line'] = finish
                    pass
                elif len(args) > 3:
                    self.errmsg("Expecting 1-2 line parameters. Got %d." %
                                len(args)-1)
                    return False
                pass
            pass
        elif not self.proc.curframe:
            self.errmsg("No frame selected.")
            return

        Mdis.dis(self.msg, self.msg_nocr, self.section, self.errmsg,
                 self.proc.curframe,  **opts)
        return False
コード例 #7
0
ファイル: disassemble.py プロジェクト: rocky/python2-trepan
    def run(self, args):
        proc = self.proc
        dbg_obj  = self.core.debugger

        # We'll use a rough estimate of 4 bytes per instruction and
        # go off listsize
        listsize = dbg_obj.settings['listsize'] * 4
        curframe = proc.curframe

        opts = {'highlight': self.settings['highlight'],
                'start_line': 1,
                'end_line': None,
                'start_offset': None,
                'end_offset': None,
                'relative_pos': False,
                }

        do_parse = True
        if len(args) == 2:
            try:
                obj=self.proc.eval(args[1])
                opts['start_offset'] = 0
                is_offset = True
                start = 0
                last = dbg_obj.settings['listsize'] * 4
                last_is_offset = False
                if (inspect.ismethod(obj) or
                    inspect.isfunction(obj) or
                    inspect.isgeneratorfunction(obj) or
                    inspect.isgenerator(obj) or
                    inspect.isframe(obj) or
                    inspect.iscode(obj)):
                    do_parse = False
            except:
                pass

        if do_parse:
            (bytecode_file, start, is_offset, last,
             last_is_offset, obj)  = parse_addr_list_cmd(proc, args, listsize)
            if bytecode_file is None: return

        if is_offset:
            opts['start_offset'] = start
        else:
            opts['start_line'] = start
        if last_is_offset:
            opts['end_offset'] = last
        else:
            opts['end_line'] = last

        if not (obj or bytecode_file.endswith('.pyo') or
                bytecode_file.endswith('pyc')):
            bytecode_file = cache_from_source(bytecode_file)
            if bytecode_file and Mfile.readable(bytecode_file):
                self.msg("Reading %s ..." % bytecode_file)
                (version, timestamp, magic_int, obj,
                 is_pypy, source_size) = load_module(bytecode_file)
            elif not curframe:
                self.errmsg("No frame selected.")
                return
            else:
                try:
                    obj=self.proc.eval(args[1])
                    opts['start_line'] = -1
                except:
                    self.errmsg(("Object '%s' is not something we can"
                                + " disassemble.") % args[1])
                    return

        # We now have all information. Do the listing.
        (self.object,
         proc.list_offset) = Mdis.dis(self.msg, self.msg_nocr, self.section, self.errmsg,
                                      obj, **opts)
        return False