Exemplo n.º 1
0
def uncompyle(version, co, out=None, showasm=False, showast=False,
              timestamp=None, showgrammar=False, code_objects={}):
    """
    disassembles and deparses a given code block 'co'
    """

    assert iscode(co)

    # store final output stream for case of error
    real_out = out or sys.stdout
    print('# Python %s (decompiled from Python %s)' % (version, PYTHON_VERSION),
          file=real_out)
    if co.co_filename:
        print('# Embedded file name: %s' % co.co_filename,
              file=real_out)
    if timestamp:
        print('# Compiled at: %s' % datetime.datetime.fromtimestamp(timestamp),
              file=real_out)

    try:
        pysource.deparse_code(version, co, out, showasm, showast, showgrammar,
                              code_objects=code_objects)
    except pysource.SourceWalkerError as e:
        # deparsing failed
        if real_out != out:
            print(e, file=real_out)
        raise
Exemplo n.º 2
0
def uncompyle(
        version, co, out=None, showasm=False, showast=False,
        timestamp=None, showgrammar=False, code_objects={},
        is_pypy=False, magic_int=None):
    """
    disassembles and deparses a given code block 'co'
    """
    assert iscode(co)

    # store final output stream for case of error
    real_out = out or sys.stdout
    co_pypy_str = 'PyPy ' if is_pypy else ''
    run_pypy_str = 'PyPy ' if IS_PYPY else ''
    print('# %sPython bytecode %s%s disassembled from %sPython %s' %
          (co_pypy_str, version,
           " (%d)" % magic_int if magic_int else "",
           run_pypy_str, PYTHON_VERSION),
          file=real_out)
    if co.co_filename:
        print('# Embedded file name: %s' % co.co_filename,
              file=real_out)
    if timestamp:
        print('# Compiled at: %s' % datetime.datetime.fromtimestamp(timestamp),
              file=real_out)

    try:
        pysource.deparse_code(version, co, out, showasm, showast, showgrammar,
                              code_objects=code_objects, is_pypy=is_pypy)
    except pysource.SourceWalkerError as e:
        # deparsing failed
        print("\n")
        print(co.co_filename)
        if real_out != out:
            print("\n", file=real_out)
            print(e, file=real_out)
Exemplo n.º 3
0
def decompile(bytecode_version,
              co,
              out=None,
              showasm=None,
              showast=False,
              timestamp=None,
              showgrammar=False,
              code_objects={},
              source_size=None,
              is_pypy=False,
              magic_int=None):
    """
    ingests and deparses a given code block 'co'
    """
    assert iscode(co)

    # store final output stream for case of error
    real_out = out or sys.stdout
    co_pypy_str = 'PyPy ' if is_pypy else ''
    run_pypy_str = 'PyPy ' if IS_PYPY else ''
    print('# uncompyle6 version %s\n'
          '# %sPython bytecode %s%s\n# Decompiled from: %sPython %s' %
          (VERSION, co_pypy_str, bytecode_version,
           " (%d)" % magic_int if magic_int else "", run_pypy_str, '\n# '.join(
               sys.version.split('\n'))),
          file=real_out)
    if co.co_filename:
        print('# Embedded file name: %s' % co.co_filename, file=real_out)
    if timestamp:
        print('# Compiled at: %s' % datetime.datetime.fromtimestamp(timestamp),
              file=real_out)
    if source_size:
        print('# Size of source mod 2**32: %d bytes' % source_size,
              file=real_out)

    try:
        pysource.deparse_code(bytecode_version,
                              co,
                              out,
                              showasm,
                              showast,
                              showgrammar,
                              code_objects=code_objects,
                              is_pypy=is_pypy)
    except pysource.SourceWalkerError as e:
        # deparsing failed
        raise pysource.SourceWalkerError(str(e))
Exemplo n.º 4
0
def deparse_fn(code):
    try:
        from uncompyle6.semantics.pysource import deparse_code
    except ImportError:
        return None
    sys_version = sys.version_info.major + (sys.version_info.minor / 10.0)
    try:
        out = io.StringIO()
        deparsed = deparse_code(sys_version, code, out)
        return deparsed.text
    except:
        raise
    return None
Exemplo n.º 5
0
def deparse_fn(code):
    try:
        from uncompyle6.semantics.pysource import deparse_code
    except ImportError:
        return None
    sys_version = sys.version_info.major + (sys.version_info.minor / 10.0)
    try:
        out = io.StringIO()
        deparsed = deparse_code(sys_version, code, out)
        return deparsed.text
    except:
        raise
    return None
Exemplo n.º 6
0
def uncompyle(version,
              co,
              out=None,
              showasm=False,
              showast=False,
              timestamp=None,
              showgrammar=False,
              code_objects={}):
    """
    disassembles and deparses a given code block 'co'
    """

    assert iscode(co)

    # store final output stream for case of error
    real_out = out or sys.stdout
    print('# Python %s (decompiled from Python %s)' %
          (version, PYTHON_VERSION),
          file=real_out)
    if co.co_filename:
        print('# Embedded file name: %s' % co.co_filename, file=real_out)
    if timestamp:
        print('# Compiled at: %s' % datetime.datetime.fromtimestamp(timestamp),
              file=real_out)

    try:
        pysource.deparse_code(version,
                              co,
                              out,
                              showasm,
                              showast,
                              showgrammar,
                              code_objects=code_objects)
    except pysource.SourceWalkerError as e:
        # deparsing failed
        if real_out != out:
            print(e, file=real_out)
        raise
Exemplo n.º 7
0
def decompile(
        bytecode_version, co, out=None, showasm=None, showast=False,
        timestamp=None, showgrammar=False, code_objects={},
        source_size=None, is_pypy=False, magic_int=None):
    """
    ingests and deparses a given code block 'co'
    """
    assert iscode(co)

    # store final output stream for case of error
    real_out = out or sys.stdout
    co_pypy_str = 'PyPy ' if is_pypy else ''
    run_pypy_str = 'PyPy ' if IS_PYPY else ''
    print('# uncompyle6 version %s\n'
          '# %sPython bytecode %s%s\n# Decompiled from: %sPython %s' %
          (VERSION, co_pypy_str, bytecode_version,
           " (%d)" % magic_int if magic_int else "",
           run_pypy_str, '\n# '.join(sys.version.split('\n'))),
           file=real_out)
    if co.co_filename:
        print('# Embedded file name: %s' % co.co_filename,
              file=real_out)
    if timestamp:
        print('# Compiled at: %s' % datetime.datetime.fromtimestamp(timestamp),
              file=real_out)
    if source_size:
        print('# Size of source mod 2**32: %d bytes' % source_size,
               file=real_out)

    try:
        pysource.deparse_code(bytecode_version, co, out, showasm, showast,
                              showgrammar, code_objects=code_objects,
                              is_pypy=is_pypy)
    except pysource.SourceWalkerError as e:
        # deparsing failed
        raise pysource.SourceWalkerError(str(e))