Current Path: > > opt > alt > python38 > lib64 > python3.8
Operation : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 Software : Apache Server IP : 162.0.232.56 | Your IP: 216.73.216.111 Domains : 1034 Domain(s) Permission : [ 0755 ]
Name | Type | Size | Last Modified | Actions |
---|---|---|---|---|
__pycache__ | Directory | - | - | |
asyncio | Directory | - | - | |
collections | Directory | - | - | |
concurrent | Directory | - | - | |
config-3.8-x86_64-linux-gnu | Directory | - | - | |
ctypes | Directory | - | - | |
curses | Directory | - | - | |
dbm | Directory | - | - | |
distutils | Directory | - | - | |
Directory | - | - | ||
encodings | Directory | - | - | |
ensurepip | Directory | - | - | |
html | Directory | - | - | |
http | Directory | - | - | |
importlib | Directory | - | - | |
json | Directory | - | - | |
lib-dynload | Directory | - | - | |
lib2to3 | Directory | - | - | |
logging | Directory | - | - | |
multiprocessing | Directory | - | - | |
pydoc_data | Directory | - | - | |
site-packages | Directory | - | - | |
sqlite3 | Directory | - | - | |
unittest | Directory | - | - | |
urllib | Directory | - | - | |
venv | Directory | - | - | |
wsgiref | Directory | - | - | |
xml | Directory | - | - | |
xmlrpc | Directory | - | - | |
LICENSE.txt | File | 13937 bytes | September 06 2024 20:41:55. | |
__future__.py | File | 5147 bytes | September 06 2024 20:41:55. | |
__phello__.foo.py | File | 64 bytes | September 06 2024 20:41:55. | |
_bootlocale.py | File | 1801 bytes | September 06 2024 20:41:55. | |
_collections_abc.py | File | 26100 bytes | September 06 2024 20:41:55. | |
_compat_pickle.py | File | 8749 bytes | September 06 2024 20:41:55. | |
_compression.py | File | 5340 bytes | September 06 2024 20:41:55. | |
_dummy_thread.py | File | 6027 bytes | September 06 2024 20:41:55. | |
_markupbase.py | File | 14598 bytes | September 06 2024 20:41:55. | |
_osx_support.py | File | 21774 bytes | September 06 2024 20:41:55. | |
_py_abc.py | File | 6189 bytes | September 06 2024 20:41:55. | |
_pydecimal.py | File | 228666 bytes | September 06 2024 20:41:55. | |
_pyio.py | File | 93177 bytes | September 06 2024 20:41:55. | |
_sitebuiltins.py | File | 3115 bytes | September 06 2024 20:41:55. | |
_strptime.py | File | 25268 bytes | September 06 2024 20:41:55. | |
_sysconfigdata__linux_x86_64-linux-gnu.py | File | 41679 bytes | September 23 2024 11:25:15. | |
_sysconfigdata_d_linux_x86_64-linux-gnu.py | File | 41438 bytes | September 23 2024 11:17:38. | |
_threading_local.py | File | 7220 bytes | September 06 2024 20:41:55. | |
_weakrefset.py | File | 5735 bytes | September 06 2024 20:41:55. | |
abc.py | File | 4489 bytes | September 06 2024 20:41:55. | |
aifc.py | File | 32814 bytes | September 06 2024 20:41:55. | |
antigravity.py | File | 477 bytes | September 06 2024 20:41:55. | |
argparse.py | File | 96015 bytes | September 06 2024 20:41:55. | |
ast.py | File | 19234 bytes | September 06 2024 20:41:55. | |
asynchat.py | File | 11328 bytes | September 06 2024 20:41:55. | |
asyncore.py | File | 20094 bytes | September 06 2024 20:41:55. | |
base64.py | File | 20395 bytes | September 06 2024 20:41:55. | |
bdb.py | File | 32056 bytes | September 06 2024 20:41:55. | |
binhex.py | File | 13954 bytes | September 06 2024 20:41:55. | |
bisect.py | File | 2214 bytes | September 06 2024 20:41:55. | |
bz2.py | File | 12558 bytes | September 06 2024 20:41:55. | |
cProfile.py | File | 7023 bytes | September 06 2024 20:41:55. | |
calendar.py | File | 24832 bytes | September 06 2024 20:41:55. | |
cgi.py | File | 33945 bytes | September 06 2024 20:41:55. | |
cgitb.py | File | 12096 bytes | September 06 2024 20:41:55. | |
chunk.py | File | 5435 bytes | September 06 2024 20:41:55. | |
cmd.py | File | 14860 bytes | September 06 2024 20:41:55. | |
code.py | File | 10622 bytes | September 06 2024 20:41:55. | |
codecs.py | File | 36667 bytes | September 06 2024 20:41:55. | |
codeop.py | File | 6330 bytes | September 06 2024 20:41:55. | |
colorsys.py | File | 4064 bytes | September 06 2024 20:41:55. | |
compileall.py | File | 13678 bytes | September 06 2024 20:41:55. | |
configparser.py | File | 54374 bytes | September 06 2024 20:41:55. | |
contextlib.py | File | 24995 bytes | September 06 2024 20:41:55. | |
contextvars.py | File | 129 bytes | September 06 2024 20:41:55. | |
copy.py | File | 8661 bytes | September 06 2024 20:41:55. | |
copyreg.py | File | 7135 bytes | September 06 2024 20:41:55. | |
crypt.py | File | 3610 bytes | September 06 2024 20:41:55. | |
csv.py | File | 16144 bytes | September 06 2024 20:41:55. | |
dataclasses.py | File | 49973 bytes | September 06 2024 20:41:55. | |
datetime.py | File | 88287 bytes | September 06 2024 20:41:55. | |
decimal.py | File | 320 bytes | September 06 2024 20:41:55. | |
difflib.py | File | 84058 bytes | September 06 2024 20:41:55. | |
dis.py | File | 20570 bytes | September 06 2024 20:41:55. | |
doctest.py | File | 104543 bytes | September 06 2024 20:41:55. | |
dummy_threading.py | File | 2815 bytes | September 06 2024 20:41:55. | |
enum.py | File | 38136 bytes | September 06 2024 20:41:55. | |
filecmp.py | File | 9830 bytes | September 06 2024 20:41:55. | |
fileinput.py | File | 14709 bytes | September 06 2024 20:41:55. | |
fnmatch.py | File | 4079 bytes | September 06 2024 20:41:55. | |
formatter.py | File | 15143 bytes | September 06 2024 20:41:55. | |
fractions.py | File | 24329 bytes | September 06 2024 20:41:55. | |
ftplib.py | File | 35129 bytes | September 06 2024 20:41:55. | |
functools.py | File | 37406 bytes | September 06 2024 20:41:55. | |
genericpath.py | File | 4975 bytes | September 06 2024 20:41:55. | |
getopt.py | File | 7489 bytes | September 06 2024 20:41:55. | |
getpass.py | File | 5994 bytes | September 06 2024 20:41:55. | |
gettext.py | File | 27138 bytes | September 06 2024 20:41:55. | |
glob.py | File | 5697 bytes | September 06 2024 20:41:55. | |
gzip.py | File | 21413 bytes | September 06 2024 20:41:55. | |
hashlib.py | File | 9730 bytes | September 06 2024 20:41:55. | |
heapq.py | File | 22877 bytes | September 06 2024 20:41:55. | |
hmac.py | File | 6629 bytes | September 06 2024 20:41:55. | |
imaplib.py | File | 53606 bytes | September 06 2024 20:41:55. | |
imghdr.py | File | 3808 bytes | September 06 2024 20:41:55. | |
imp.py | File | 10536 bytes | September 06 2024 20:41:55. | |
inspect.py | File | 118550 bytes | September 06 2024 20:41:55. | |
io.py | File | 3541 bytes | September 06 2024 20:41:55. | |
ipaddress.py | File | 74899 bytes | September 06 2024 20:41:55. | |
keyword.py | File | 945 bytes | September 06 2024 20:41:55. | |
linecache.py | File | 5330 bytes | September 06 2024 20:41:55. | |
locale.py | File | 78191 bytes | September 06 2024 20:41:55. | |
lzma.py | File | 12983 bytes | September 06 2024 20:41:55. | |
mailbox.py | File | 78661 bytes | September 06 2024 20:41:55. | |
mailcap.py | File | 9067 bytes | September 06 2024 20:41:55. | |
mimetypes.py | File | 21664 bytes | September 06 2024 20:41:55. | |
modulefinder.py | File | 24430 bytes | September 06 2024 20:41:55. | |
netrc.py | File | 5566 bytes | September 06 2024 20:41:55. | |
nntplib.py | File | 43261 bytes | September 06 2024 20:41:55. | |
ntpath.py | File | 27734 bytes | September 06 2024 20:41:55. | |
nturl2path.py | File | 2887 bytes | September 06 2024 20:41:55. | |
numbers.py | File | 10244 bytes | September 06 2024 20:41:55. | |
opcode.py | File | 5808 bytes | September 06 2024 20:41:55. | |
operator.py | File | 10711 bytes | September 06 2024 20:41:55. | |
optparse.py | File | 60369 bytes | September 06 2024 20:41:55. | |
os.py | File | 38995 bytes | September 06 2024 20:41:55. | |
pathlib.py | File | 52610 bytes | September 06 2024 20:41:55. | |
pdb.py | File | 62751 bytes | September 06 2024 20:41:55. | |
pickle.py | File | 64467 bytes | September 06 2024 20:41:55. | |
pickletools.py | File | 93486 bytes | September 06 2024 20:41:55. | |
pipes.py | File | 8916 bytes | September 06 2024 20:41:55. | |
pkgutil.py | File | 21500 bytes | September 06 2024 20:41:55. | |
platform.py | File | 40438 bytes | September 06 2024 20:41:55. | |
plistlib.py | File | 32220 bytes | September 06 2024 20:41:55. | |
poplib.py | File | 15077 bytes | September 06 2024 20:41:55. | |
posixpath.py | File | 15627 bytes | September 06 2024 20:41:55. | |
pprint.py | File | 21484 bytes | September 06 2024 20:41:55. | |
profile.py | File | 23559 bytes | September 06 2024 20:41:55. | |
pstats.py | File | 27345 bytes | September 06 2024 20:41:55. | |
pty.py | File | 4807 bytes | September 06 2024 20:41:55. | |
py_compile.py | File | 8203 bytes | September 23 2024 11:15:42. | |
pyclbr.py | File | 15255 bytes | September 06 2024 20:41:55. | |
pydoc.py | File | 106700 bytes | September 23 2024 11:26:08. | |
queue.py | File | 11356 bytes | September 06 2024 20:41:55. | |
quopri.py | File | 7265 bytes | September 06 2024 20:41:55. | |
random.py | File | 28802 bytes | September 06 2024 20:41:55. | |
re.py | File | 15861 bytes | September 06 2024 20:41:55. | |
reprlib.py | File | 5267 bytes | September 06 2024 20:41:55. | |
rlcompleter.py | File | 7097 bytes | September 06 2024 20:41:55. | |
runpy.py | File | 12052 bytes | September 06 2024 20:41:55. | |
sched.py | File | 6442 bytes | September 06 2024 20:41:55. | |
secrets.py | File | 2038 bytes | September 06 2024 20:41:55. | |
selectors.py | File | 18561 bytes | September 06 2024 20:41:55. | |
shelve.py | File | 8527 bytes | September 06 2024 20:41:55. | |
shlex.py | File | 13325 bytes | September 06 2024 20:41:55. | |
shutil.py | File | 51761 bytes | September 06 2024 20:41:55. | |
signal.py | File | 2273 bytes | September 06 2024 20:41:55. | |
site.py | File | 21877 bytes | September 23 2024 11:15:42. | |
smtpd.py | File | 34722 bytes | September 06 2024 20:41:55. | |
smtplib.py | File | 45014 bytes | September 06 2024 20:41:55. | |
sndhdr.py | File | 7099 bytes | September 06 2024 20:41:55. | |
socket.py | File | 35464 bytes | September 06 2024 20:41:55. | |
socketserver.py | File | 27296 bytes | September 06 2024 20:41:55. | |
sre_compile.py | File | 26695 bytes | September 06 2024 20:41:55. | |
sre_constants.py | File | 7154 bytes | September 06 2024 20:41:55. | |
sre_parse.py | File | 40230 bytes | September 06 2024 20:41:55. | |
ssl.py | File | 52533 bytes | September 06 2024 20:41:55. | |
stat.py | File | 5485 bytes | September 06 2024 20:41:55. | |
statistics.py | File | 39690 bytes | September 06 2024 20:41:55. | |
string.py | File | 10535 bytes | September 06 2024 20:41:55. | |
stringprep.py | File | 12917 bytes | September 06 2024 20:41:55. | |
struct.py | File | 257 bytes | September 06 2024 20:41:55. | |
subprocess.py | File | 78250 bytes | September 06 2024 20:41:55. | |
sunau.py | File | 18375 bytes | September 06 2024 20:41:55. | |
symbol.py | File | 2109 bytes | September 23 2024 11:18:30. | |
symtable.py | File | 8021 bytes | September 06 2024 20:41:55. | |
sysconfig.py | File | 24893 bytes | September 23 2024 11:15:42. | |
tabnanny.py | File | 11419 bytes | September 06 2024 20:41:55. | |
tarfile.py | File | 106031 bytes | September 06 2024 20:41:55. | |
telnetlib.py | File | 23254 bytes | September 06 2024 20:41:55. | |
tempfile.py | File | 27822 bytes | September 06 2024 20:41:55. | |
textwrap.py | File | 19407 bytes | September 06 2024 20:41:55. | |
this.py | File | 1003 bytes | September 06 2024 20:41:55. | |
threading.py | File | 50820 bytes | September 06 2024 20:41:55. | |
timeit.py | File | 13493 bytes | September 06 2024 20:41:55. | |
token.py | File | 2368 bytes | September 06 2024 20:41:55. | |
tokenize.py | File | 25841 bytes | September 06 2024 20:41:55. | |
trace.py | File | 29883 bytes | September 06 2024 20:41:55. | |
traceback.py | File | 23611 bytes | September 06 2024 20:41:55. | |
tracemalloc.py | File | 17076 bytes | September 06 2024 20:41:55. | |
tty.py | File | 879 bytes | September 06 2024 20:41:55. | |
types.py | File | 9713 bytes | September 06 2024 20:41:55. | |
typing.py | File | 68962 bytes | September 06 2024 20:41:55. | |
uu.py | File | 7277 bytes | September 23 2024 11:26:07. | |
uuid.py | File | 30466 bytes | September 06 2024 20:41:55. | |
warnings.py | File | 19688 bytes | September 06 2024 20:41:55. | |
wave.py | File | 18230 bytes | September 06 2024 20:41:55. | |
weakref.py | File | 21387 bytes | September 06 2024 20:41:55. | |
webbrowser.py | File | 24096 bytes | September 06 2024 20:41:55. | |
xdrlib.py | File | 5913 bytes | September 06 2024 20:41:55. | |
zipapp.py | File | 7535 bytes | September 06 2024 20:41:55. | |
zipfile.py | File | 88476 bytes | September 06 2024 20:41:55. | |
zipimport.py | File | 30765 bytes | September 06 2024 20:41:55. |
"""Disassembler of Python byte code into mnemonics.""" import sys import types import collections import io from opcode import * from opcode import __all__ as _opcodes_all __all__ = ["code_info", "dis", "disassemble", "distb", "disco", "findlinestarts", "findlabels", "show_code", "get_instructions", "Instruction", "Bytecode"] + _opcodes_all del _opcodes_all _have_code = (types.MethodType, types.FunctionType, types.CodeType, classmethod, staticmethod, type) FORMAT_VALUE = opmap['FORMAT_VALUE'] FORMAT_VALUE_CONVERTERS = ( (None, ''), (str, 'str'), (repr, 'repr'), (ascii, 'ascii'), ) MAKE_FUNCTION = opmap['MAKE_FUNCTION'] MAKE_FUNCTION_FLAGS = ('defaults', 'kwdefaults', 'annotations', 'closure') def _try_compile(source, name): """Attempts to compile the given source, first as an expression and then as a statement if the first approach fails. Utility function to accept strings in functions that otherwise expect code objects """ try: c = compile(source, name, 'eval') except SyntaxError: c = compile(source, name, 'exec') return c def dis(x=None, *, file=None, depth=None): """Disassemble classes, methods, functions, and other compiled objects. With no argument, disassemble the last traceback. Compiled objects currently include generator objects, async generator objects, and coroutine objects, all of which store their code object in a special attribute. """ if x is None: distb(file=file) return # Extract functions from methods. if hasattr(x, '__func__'): x = x.__func__ # Extract compiled code objects from... if hasattr(x, '__code__'): # ...a function, or x = x.__code__ elif hasattr(x, 'gi_code'): #...a generator object, or x = x.gi_code elif hasattr(x, 'ag_code'): #...an asynchronous generator object, or x = x.ag_code elif hasattr(x, 'cr_code'): #...a coroutine. x = x.cr_code # Perform the disassembly. if hasattr(x, '__dict__'): # Class or module items = sorted(x.__dict__.items()) for name, x1 in items: if isinstance(x1, _have_code): print("Disassembly of %s:" % name, file=file) try: dis(x1, file=file, depth=depth) except TypeError as msg: print("Sorry:", msg, file=file) print(file=file) elif hasattr(x, 'co_code'): # Code object _disassemble_recursive(x, file=file, depth=depth) elif isinstance(x, (bytes, bytearray)): # Raw bytecode _disassemble_bytes(x, file=file) elif isinstance(x, str): # Source code _disassemble_str(x, file=file, depth=depth) else: raise TypeError("don't know how to disassemble %s objects" % type(x).__name__) def distb(tb=None, *, file=None): """Disassemble a traceback (default: last traceback).""" if tb is None: try: tb = sys.last_traceback except AttributeError: raise RuntimeError("no last traceback to disassemble") from None while tb.tb_next: tb = tb.tb_next disassemble(tb.tb_frame.f_code, tb.tb_lasti, file=file) # The inspect module interrogates this dictionary to build its # list of CO_* constants. It is also used by pretty_flags to # turn the co_flags field into a human readable list. COMPILER_FLAG_NAMES = { 1: "OPTIMIZED", 2: "NEWLOCALS", 4: "VARARGS", 8: "VARKEYWORDS", 16: "NESTED", 32: "GENERATOR", 64: "NOFREE", 128: "COROUTINE", 256: "ITERABLE_COROUTINE", 512: "ASYNC_GENERATOR", } def pretty_flags(flags): """Return pretty representation of code flags.""" names = [] for i in range(32): flag = 1<<i if flags & flag: names.append(COMPILER_FLAG_NAMES.get(flag, hex(flag))) flags ^= flag if not flags: break else: names.append(hex(flags)) return ", ".join(names) def _get_code_object(x): """Helper to handle methods, compiled or raw code objects, and strings.""" # Extract functions from methods. if hasattr(x, '__func__'): x = x.__func__ # Extract compiled code objects from... if hasattr(x, '__code__'): # ...a function, or x = x.__code__ elif hasattr(x, 'gi_code'): #...a generator object, or x = x.gi_code elif hasattr(x, 'ag_code'): #...an asynchronous generator object, or x = x.ag_code elif hasattr(x, 'cr_code'): #...a coroutine. x = x.cr_code # Handle source code. if isinstance(x, str): x = _try_compile(x, "<disassembly>") # By now, if we don't have a code object, we can't disassemble x. if hasattr(x, 'co_code'): return x raise TypeError("don't know how to disassemble %s objects" % type(x).__name__) def code_info(x): """Formatted details of methods, functions, or code.""" return _format_code_info(_get_code_object(x)) def _format_code_info(co): lines = [] lines.append("Name: %s" % co.co_name) lines.append("Filename: %s" % co.co_filename) lines.append("Argument count: %s" % co.co_argcount) lines.append("Positional-only arguments: %s" % co.co_posonlyargcount) lines.append("Kw-only arguments: %s" % co.co_kwonlyargcount) lines.append("Number of locals: %s" % co.co_nlocals) lines.append("Stack size: %s" % co.co_stacksize) lines.append("Flags: %s" % pretty_flags(co.co_flags)) if co.co_consts: lines.append("Constants:") for i_c in enumerate(co.co_consts): lines.append("%4d: %r" % i_c) if co.co_names: lines.append("Names:") for i_n in enumerate(co.co_names): lines.append("%4d: %s" % i_n) if co.co_varnames: lines.append("Variable names:") for i_n in enumerate(co.co_varnames): lines.append("%4d: %s" % i_n) if co.co_freevars: lines.append("Free variables:") for i_n in enumerate(co.co_freevars): lines.append("%4d: %s" % i_n) if co.co_cellvars: lines.append("Cell variables:") for i_n in enumerate(co.co_cellvars): lines.append("%4d: %s" % i_n) return "\n".join(lines) def show_code(co, *, file=None): """Print details of methods, functions, or code to *file*. If *file* is not provided, the output is printed on stdout. """ print(code_info(co), file=file) _Instruction = collections.namedtuple("_Instruction", "opname opcode arg argval argrepr offset starts_line is_jump_target") _Instruction.opname.__doc__ = "Human readable name for operation" _Instruction.opcode.__doc__ = "Numeric code for operation" _Instruction.arg.__doc__ = "Numeric argument to operation (if any), otherwise None" _Instruction.argval.__doc__ = "Resolved arg value (if known), otherwise same as arg" _Instruction.argrepr.__doc__ = "Human readable description of operation argument" _Instruction.offset.__doc__ = "Start index of operation within bytecode sequence" _Instruction.starts_line.__doc__ = "Line started by this opcode (if any), otherwise None" _Instruction.is_jump_target.__doc__ = "True if other code jumps to here, otherwise False" _OPNAME_WIDTH = 20 _OPARG_WIDTH = 5 class Instruction(_Instruction): """Details for a bytecode operation Defined fields: opname - human readable name for operation opcode - numeric code for operation arg - numeric argument to operation (if any), otherwise None argval - resolved arg value (if known), otherwise same as arg argrepr - human readable description of operation argument offset - start index of operation within bytecode sequence starts_line - line started by this opcode (if any), otherwise None is_jump_target - True if other code jumps to here, otherwise False """ def _disassemble(self, lineno_width=3, mark_as_current=False, offset_width=4): """Format instruction details for inclusion in disassembly output *lineno_width* sets the width of the line number field (0 omits it) *mark_as_current* inserts a '-->' marker arrow as part of the line *offset_width* sets the width of the instruction offset field """ fields = [] # Column: Source code line number if lineno_width: if self.starts_line is not None: lineno_fmt = "%%%dd" % lineno_width fields.append(lineno_fmt % self.starts_line) else: fields.append(' ' * lineno_width) # Column: Current instruction indicator if mark_as_current: fields.append('-->') else: fields.append(' ') # Column: Jump target marker if self.is_jump_target: fields.append('>>') else: fields.append(' ') # Column: Instruction offset from start of code sequence fields.append(repr(self.offset).rjust(offset_width)) # Column: Opcode name fields.append(self.opname.ljust(_OPNAME_WIDTH)) # Column: Opcode argument if self.arg is not None: fields.append(repr(self.arg).rjust(_OPARG_WIDTH)) # Column: Opcode argument details if self.argrepr: fields.append('(' + self.argrepr + ')') return ' '.join(fields).rstrip() def get_instructions(x, *, first_line=None): """Iterator for the opcodes in methods, functions or code Generates a series of Instruction named tuples giving the details of each operations in the supplied code. If *first_line* is not None, it indicates the line number that should be reported for the first source line in the disassembled code. Otherwise, the source line information (if any) is taken directly from the disassembled code object. """ co = _get_code_object(x) cell_names = co.co_cellvars + co.co_freevars linestarts = dict(findlinestarts(co)) if first_line is not None: line_offset = first_line - co.co_firstlineno else: line_offset = 0 return _get_instructions_bytes(co.co_code, co.co_varnames, co.co_names, co.co_consts, cell_names, linestarts, line_offset) def _get_const_info(const_index, const_list): """Helper to get optional details about const references Returns the dereferenced constant and its repr if the constant list is defined. Otherwise returns the constant index and its repr(). """ argval = const_index if const_list is not None: argval = const_list[const_index] return argval, repr(argval) def _get_name_info(name_index, name_list): """Helper to get optional details about named references Returns the dereferenced name as both value and repr if the name list is defined. Otherwise returns the name index and its repr(). """ argval = name_index if name_list is not None: argval = name_list[name_index] argrepr = argval else: argrepr = repr(argval) return argval, argrepr def _get_instructions_bytes(code, varnames=None, names=None, constants=None, cells=None, linestarts=None, line_offset=0): """Iterate over the instructions in a bytecode string. Generates a sequence of Instruction namedtuples giving the details of each opcode. Additional information about the code's runtime environment (e.g. variable names, constants) can be specified using optional arguments. """ labels = findlabels(code) starts_line = None for offset, op, arg in _unpack_opargs(code): if linestarts is not None: starts_line = linestarts.get(offset, None) if starts_line is not None: starts_line += line_offset is_jump_target = offset in labels argval = None argrepr = '' if arg is not None: # Set argval to the dereferenced value of the argument when # available, and argrepr to the string representation of argval. # _disassemble_bytes needs the string repr of the # raw name index for LOAD_GLOBAL, LOAD_CONST, etc. argval = arg if op in hasconst: argval, argrepr = _get_const_info(arg, constants) elif op in hasname: argval, argrepr = _get_name_info(arg, names) elif op in hasjrel: argval = offset + 2 + arg argrepr = "to " + repr(argval) elif op in haslocal: argval, argrepr = _get_name_info(arg, varnames) elif op in hascompare: argval = cmp_op[arg] argrepr = argval elif op in hasfree: argval, argrepr = _get_name_info(arg, cells) elif op == FORMAT_VALUE: argval, argrepr = FORMAT_VALUE_CONVERTERS[arg & 0x3] argval = (argval, bool(arg & 0x4)) if argval[1]: if argrepr: argrepr += ', ' argrepr += 'with format' elif op == MAKE_FUNCTION: argrepr = ', '.join(s for i, s in enumerate(MAKE_FUNCTION_FLAGS) if arg & (1<<i)) yield Instruction(opname[op], op, arg, argval, argrepr, offset, starts_line, is_jump_target) def disassemble(co, lasti=-1, *, file=None): """Disassemble a code object.""" cell_names = co.co_cellvars + co.co_freevars linestarts = dict(findlinestarts(co)) _disassemble_bytes(co.co_code, lasti, co.co_varnames, co.co_names, co.co_consts, cell_names, linestarts, file=file) def _disassemble_recursive(co, *, file=None, depth=None): disassemble(co, file=file) if depth is None or depth > 0: if depth is not None: depth = depth - 1 for x in co.co_consts: if hasattr(x, 'co_code'): print(file=file) print("Disassembly of %r:" % (x,), file=file) _disassemble_recursive(x, file=file, depth=depth) def _disassemble_bytes(code, lasti=-1, varnames=None, names=None, constants=None, cells=None, linestarts=None, *, file=None, line_offset=0): # Omit the line number column entirely if we have no line number info show_lineno = linestarts is not None if show_lineno: maxlineno = max(linestarts.values()) + line_offset if maxlineno >= 1000: lineno_width = len(str(maxlineno)) else: lineno_width = 3 else: lineno_width = 0 maxoffset = len(code) - 2 if maxoffset >= 10000: offset_width = len(str(maxoffset)) else: offset_width = 4 for instr in _get_instructions_bytes(code, varnames, names, constants, cells, linestarts, line_offset=line_offset): new_source_line = (show_lineno and instr.starts_line is not None and instr.offset > 0) if new_source_line: print(file=file) is_current_instr = instr.offset == lasti print(instr._disassemble(lineno_width, is_current_instr, offset_width), file=file) def _disassemble_str(source, **kwargs): """Compile the source string, then disassemble the code object.""" _disassemble_recursive(_try_compile(source, '<dis>'), **kwargs) disco = disassemble # XXX For backwards compatibility def _unpack_opargs(code): extended_arg = 0 for i in range(0, len(code), 2): op = code[i] if op >= HAVE_ARGUMENT: arg = code[i+1] | extended_arg extended_arg = (arg << 8) if op == EXTENDED_ARG else 0 else: arg = None yield (i, op, arg) def findlabels(code): """Detect all offsets in a byte code which are jump targets. Return the list of offsets. """ labels = [] for offset, op, arg in _unpack_opargs(code): if arg is not None: if op in hasjrel: label = offset + 2 + arg elif op in hasjabs: label = arg else: continue if label not in labels: labels.append(label) return labels def findlinestarts(code): """Find the offsets in a byte code which are start of lines in the source. Generate pairs (offset, lineno) as described in Python/compile.c. """ byte_increments = code.co_lnotab[0::2] line_increments = code.co_lnotab[1::2] bytecode_len = len(code.co_code) lastlineno = None lineno = code.co_firstlineno addr = 0 for byte_incr, line_incr in zip(byte_increments, line_increments): if byte_incr: if lineno != lastlineno: yield (addr, lineno) lastlineno = lineno addr += byte_incr if addr >= bytecode_len: # The rest of the lnotab byte offsets are past the end of # the bytecode, so the lines were optimized away. return if line_incr >= 0x80: # line_increments is an array of 8-bit signed integers line_incr -= 0x100 lineno += line_incr if lineno != lastlineno: yield (addr, lineno) class Bytecode: """The bytecode operations of a piece of code Instantiate this with a function, method, other compiled object, string of code, or a code object (as returned by compile()). Iterating over this yields the bytecode operations as Instruction instances. """ def __init__(self, x, *, first_line=None, current_offset=None): self.codeobj = co = _get_code_object(x) if first_line is None: self.first_line = co.co_firstlineno self._line_offset = 0 else: self.first_line = first_line self._line_offset = first_line - co.co_firstlineno self._cell_names = co.co_cellvars + co.co_freevars self._linestarts = dict(findlinestarts(co)) self._original_object = x self.current_offset = current_offset def __iter__(self): co = self.codeobj return _get_instructions_bytes(co.co_code, co.co_varnames, co.co_names, co.co_consts, self._cell_names, self._linestarts, line_offset=self._line_offset) def __repr__(self): return "{}({!r})".format(self.__class__.__name__, self._original_object) @classmethod def from_traceback(cls, tb): """ Construct a Bytecode from the given traceback """ while tb.tb_next: tb = tb.tb_next return cls(tb.tb_frame.f_code, current_offset=tb.tb_lasti) def info(self): """Return formatted information about the code object.""" return _format_code_info(self.codeobj) def dis(self): """Return a formatted view of the bytecode operations.""" co = self.codeobj if self.current_offset is not None: offset = self.current_offset else: offset = -1 with io.StringIO() as output: _disassemble_bytes(co.co_code, varnames=co.co_varnames, names=co.co_names, constants=co.co_consts, cells=self._cell_names, linestarts=self._linestarts, line_offset=self._line_offset, file=output, lasti=offset) return output.getvalue() def _test(): """Simple test program to disassemble a file.""" import argparse parser = argparse.ArgumentParser() parser.add_argument('infile', type=argparse.FileType('rb'), nargs='?', default='-') args = parser.parse_args() with args.infile as infile: source = infile.read() code = compile(source, args.infile.name, "exec") dis(code) if __name__ == "__main__": _test()
SILENT KILLER Tool