Coder Social home page Coder Social logo

unwind's Introduction

unwind - A disassembler for Python bytecode

This module provides a universal disassembler that is able to disassemble *.pyc files from both Python 2 and Python 3. Example usage:

import unwind
print(unwind.disassemble('example.pyc'))

The disassembler allows one version of Python to unmarshal code compiled by all other versions of Python. This is made possible by scraping information from the official Python repository at http://hg.python.org/cpython. In the example below, the code print('Hello, World') is compiled and disassembled from both Python 2.5 and Python 3.1. Notice how Python 2.5 uses the PRINT_ITEM opcode but Python 3.1 uses the CALL_FUNCTION opcode, since the print statement was removed in Python 3.

$ cat > example.py
print('Hello, World')
$ python2.5 -m py_compile example.py
$ python -c 'import unwind; print unwind.disassemble("example.pyc")'
Module(
    magic = 168686259,
    timestamp = 1318574250,
    python_version = 'Python 2.6a0',
    body = CodeObject(
        co_argcount = 0,
        co_kwonlyargcount = 0,
        co_nlocals = 0,
        co_stacksize = 1,
        co_flags = 64,
        co_filename = 'example.py',
        co_name = '<module>',
        co_firstlineno = 1,
        opcodes = [
            Opcode(offset = 0, opcode = 'LOAD_CONST', argument = 'Hello, World'),
            Opcode(offset = 3, opcode = 'PRINT_ITEM', argument = None),
            Opcode(offset = 4, opcode = 'PRINT_NEWLINE', argument = None),
            Opcode(offset = 5, opcode = 'LOAD_CONST', argument = None),
            Opcode(offset = 8, opcode = 'RETURN_VALUE', argument = None)])))
$ python3.1 -m py_compile example.py
$ python -c 'import unwind; print unwind.disassemble("example.pyc")'
Module(
    magic = 168627279,
    timestamp = 1318574250,
    python_version = 'Python 3.2a0',
    body = CodeObject(
        co_argcount = 0,
        co_kwonlyargcount = 0,
        co_nlocals = 0,
        co_stacksize = 2,
        co_flags = 64,
        co_filename = u'example.py',
        co_name = u'<module>',
        co_firstlineno = 1,
        opcodes = [
            Opcode(offset = 0, opcode = 'LOAD_NAME', argument = u'print'),
            Opcode(offset = 3, opcode = 'LOAD_CONST', argument = u'Hello, World'),
            Opcode(offset = 6, opcode = 'CALL_FUNCTION', argument = 1),
            Opcode(offset = 9, opcode = 'POP_TOP', argument = None),
            Opcode(offset = 10, opcode = 'LOAD_CONST', argument = None),
            Opcode(offset = 13, opcode = 'RETURN_VALUE', argument = None)])))

unwind's People

Contributors

evanw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

unwind's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.