Skip to main content

Python cross-version byte-code disassembler and marshal routines

Project description

TravisCI CircleCI PyPI Installs Latest Version Supported Python Versions

packagestatus

xdis

A Cross-Python bytecode disassembler, bytecode/wordcode and magic-number manipulation library/package.

Introduction

The Python dis module allows you to disassemble bytecode from the same version of Python that you are running on. But what about bytecode from different versions?

That’s what this package is for. It can “marshal load” Python bytecodes from different versions of Python. The command-line routine pydisasm will show disassembly output using Python 3.8 disassembly conventions.

Also, if you need to modify and write bytecode, the routines here can be of help. There are routines to pack and unpack the read-only tuples in Python’s Code type. For interoperability between Python 2 and 3 we provide our own versions of the Code type, and we provide routines to reduce the tedium in writing a bytecode file.

This package also has an extensive knowledge of Python bytecode magic numbers, including Pypy and others, and how to translate from sys.sys_info major, minor, and release numbers to the corresponding magic value.

So If you want to write a cross-version assembler, or a bytecode-level optimizer this package may also be useful. In addition to the kinds of instruction categorization that dis offers, we have additional categories for things that would be useful in such a bytecode optimizer.

The programs here accept bytecodes from Python version 1.0 to 3.8 or so. The code requires Python 2.4 or later and has been tested on Python running lots of Python versions.

To install versions for Python before 2.6 install via eggs or use the python-2.4 branch of git in github.

Installation

The standard Python routine:

$ pip install -e .
$ pip install -r requirements-dev.txt

A GNU makefile is also provided so make install (possibly as root or sudo) will do the steps above.

Testing

$ make check

A GNU makefile has been added to smooth over setting running the right command, and running tests from fastest to slowest.

If you have remake installed, you can see the list of all tasks including tests via remake --tasks.

Usage

Run

$ ./bin/pydisasm -h

for usage help.

As a drop-in replacement for dis

xdis also provides some support as a drop in replacement for the the Python library dis module. This is may be desirable when you want to use the improved API from Python 3.4 or later from an earlier Python version.

For example:

>>> # works in Python 2 and 3
>>> import xdis.std as dis
>>> [x.opname for x in dis.Bytecode('a = 10')]
['LOAD_CONST', 'STORE_NAME', 'LOAD_CONST', 'RETURN_VALUE']

There may some small differences in output produced for formatted disassembly or how we show compiler flags. We expect you’ll find the xdis output more informative though.

See Also

Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for xdis, version 5.0.1
Filename, size File type Python version Upload date Hashes
Filename, size xdis-5.0.1-py2.4.egg (253.5 kB) File type Egg Python version 2.4 Upload date Hashes View
Filename, size xdis-5.0.1-py2.5.egg (248.8 kB) File type Egg Python version 2.5 Upload date Hashes View
Filename, size xdis-5.0.1-py2.6.egg (238.6 kB) File type Egg Python version 2.6 Upload date Hashes View
Filename, size xdis-5.0.1-py26-none-any.whl (121.1 kB) File type Wheel Python version py26 Upload date Hashes View
Filename, size xdis-5.0.1-py2.7.egg (238.2 kB) File type Egg Python version 2.7 Upload date Hashes View
Filename, size xdis-5.0.1-py27-none-any.whl (125.3 kB) File type Wheel Python version py27 Upload date Hashes View
Filename, size xdis-5.0.1-py3.2.egg (240.7 kB) File type Egg Python version 3.2 Upload date Hashes View
Filename, size xdis-5.0.1-py32-none-any.whl (121.1 kB) File type Wheel Python version py32 Upload date Hashes View
Filename, size xdis-5.0.1-py3.3.egg (243.6 kB) File type Egg Python version 3.3 Upload date Hashes View
Filename, size xdis-5.0.1-py33-none-any.whl (121.1 kB) File type Wheel Python version py33 Upload date Hashes View
Filename, size xdis-5.0.1-py3.4.egg (242.4 kB) File type Egg Python version 3.4 Upload date Hashes View
Filename, size xdis-5.0.1-py34-none-any.whl (125.2 kB) File type Wheel Python version py34 Upload date Hashes View
Filename, size xdis-5.0.1-py3.5.egg (241.6 kB) File type Egg Python version 3.5 Upload date Hashes View
Filename, size xdis-5.0.1-py35-none-any.whl (125.2 kB) File type Wheel Python version py35 Upload date Hashes View
Filename, size xdis-5.0.1-py3.6.egg (237.5 kB) File type Egg Python version 3.6 Upload date Hashes View
Filename, size xdis-5.0.1-py36-none-any.whl (125.3 kB) File type Wheel Python version py36 Upload date Hashes View
Filename, size xdis-5.0.1-py3.7.egg (237.3 kB) File type Egg Python version 3.7 Upload date Hashes View
Filename, size xdis-5.0.1-py37-none-any.whl (125.3 kB) File type Wheel Python version py37 Upload date Hashes View
Filename, size xdis-5.0.1-py3.8.egg (238.0 kB) File type Egg Python version 3.8 Upload date Hashes View
Filename, size xdis-5.0.1-py38-none-any.whl (125.3 kB) File type Wheel Python version py38 Upload date Hashes View
Filename, size xdis-5.0.1.tar.gz (231.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page