Skip to main content

Python cross-version byte-code assembler

Project description

Pypi Installs Latest Version Supported Python Versions

xasm

NOTE: this is in beta

A Cross-Python bytecode Assembler

Introduction

The Python xasm module has routines for assembly, and has a command to assemble bytecode for several different versions of Python.

Here are some potential uses:

  • Make small patches to existing Python bytecode when you don’t have source

  • Craft custom and efficient bytecode

  • Write an instruction-level optimizing compiler

  • Experiment with and learn about Python bytecode

  • Foil uncompyle6 so that it can’t disassemble bytecode (at least for now)

This will support bytecodes from Python version 1.0 to 3.8 or so.

The code requires Python 2.7 or later.

Assembly files

More detail will be filled in, but some principles:

  • Preferred extension for Python assembly is .pyasm

  • assembly is designed to work with the output of pydisasm –asm

  • Assembly file labels are at the beginning of the line and end in a colon, e.g. END_IF

  • instruction offsets in the assembly file are ignored and don’t need to be entered

  • in those instructions that refer to offsets, if the if the operand is an int, exactly that value will be used for the operand. Otherwise we will look for labels and match up with that

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.

Example Assembly File

For this Python source code:

def five():
    return 5

print(five())

Here is an assembly for the above:

# Python bytecode 3.6 (3379)

# Method Name:       five
# Filename:          /tmp/five.pl
# Argument count:    0
# Kw-only arguments: 0
# Number of locals:  0
# Stack size:        1
# Flags:             0x00000043 (NOFREE | NEWLOCALS | OPTIMIZED)
# First Line:        1
# Constants:
#    0: None
#    1: 5
  2:
            LOAD_CONST           (5)
            RETURN_VALUE


# Method Name:       <module>
# Filename:          /tmp/five.pl
# Argument count:    0
# Kw-only arguments: 0
# Number of locals:  0
# Stack size:        2
# Flags:             0x00000040 (NOFREE)
# First Line:        1
# Constants:
#    0: <code object five at 0x0000>
#    1: 'five'
#    2: None
# Names:
#    0: five
#    1: print
  1:
            LOAD_CONST           0 (<code object five at 0x0000>)
            LOAD_CONST           ('five')
            MAKE_FUNCTION        0
            STORE_NAME           (five)

  3:
            LOAD_NAME            (print)
            LOAD_NAME            (five)
            CALL_FUNCTION        0
            CALL_FUNCTION        1
            POP_TOP
            LOAD_CONST           (None)
            RETURN_VALUE

The above can be created automatically from Python source code using the pydisasm command from xdis:

pydisasm --format xasm /tmp/five.pyc

In the example above though, I have shortend and simplified the result.

Usage

To create a python bytecode file from an assemble file, run:

pyc-xasm [OPTIONS] ASM_PATH

For usage help, type pyc-xasm –help.

To convert a python bytecode from one bytecode to another, run:

pyc-convert [OPTIONS] INPUT_PYC [OUTPUT_PYC]

For usage help, type pyc-convert –help.

See Also

Project details


Download files

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

Source Distribution

xasm-1.2.0.tar.gz (39.9 kB view details)

Uploaded Source

Built Distributions

xasm-1.2.0-py310-none-any.whl (20.1 kB view details)

Uploaded Python 3.10

xasm-1.2.0-py36-none-any.whl (20.1 kB view details)

Uploaded Python 3.6

xasm-1.2.0-py3.10.egg (25.9 kB view details)

Uploaded Source

xasm-1.2.0-py3.9.egg (25.7 kB view details)

Uploaded Source

xasm-1.2.0-py3.8.egg (25.9 kB view details)

Uploaded Source

xasm-1.2.0-py3.7.egg (25.8 kB view details)

Uploaded Source

xasm-1.2.0-py3.6.egg (25.8 kB view details)

Uploaded Source

File details

Details for the file xasm-1.2.0.tar.gz.

File metadata

  • Download URL: xasm-1.2.0.tar.gz
  • Upload date:
  • Size: 39.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for xasm-1.2.0.tar.gz
Algorithm Hash digest
SHA256 800ed4d0e2b582fa85c39362ea2958020b8fe48e96d13c2f0895c7f7b1f5f81f
MD5 1933d75b4581f2a87a48f22a585030a4
BLAKE2b-256 ce0e71b42ebe7420df8237f43576c5034740f12b62a86a79e6a10df6bd71def6

See more details on using hashes here.

File details

Details for the file xasm-1.2.0-py310-none-any.whl.

File metadata

  • Download URL: xasm-1.2.0-py310-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3.10
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for xasm-1.2.0-py310-none-any.whl
Algorithm Hash digest
SHA256 4427492288440ce2fb1216745f394fe900b066d20002df2fe495a8d377ec58ba
MD5 ddbbc5f1631cee5be6e048b21d1fe7fc
BLAKE2b-256 d2d1b528292f3da76f7e8da7649dbc00b7d367da58303095163afc145e177430

See more details on using hashes here.

File details

Details for the file xasm-1.2.0-py36-none-any.whl.

File metadata

  • Download URL: xasm-1.2.0-py36-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3.6
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for xasm-1.2.0-py36-none-any.whl
Algorithm Hash digest
SHA256 cdd8d3419a331404dc8a242c116b4ec74234882c8dd33ff557e6537b5e980d54
MD5 922cbe6ed237c55788df70f16d14fe6f
BLAKE2b-256 03381aca68e18e62f2e6eb2204e923be94a136a666c6760b0fb322b1d906d344

See more details on using hashes here.

File details

Details for the file xasm-1.2.0-py3.10.egg.

File metadata

  • Download URL: xasm-1.2.0-py3.10.egg
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for xasm-1.2.0-py3.10.egg
Algorithm Hash digest
SHA256 c45a189a2558140982d374348f62926ea04c3cbcabd42389af1edf6616cd6c8c
MD5 248885edff1ed55fa13d48783abcb177
BLAKE2b-256 c6dfd7ecf3140c6fdee1bedf37c052fdb1597f8f297c6be74582c31be92b8c11

See more details on using hashes here.

File details

Details for the file xasm-1.2.0-py3.9.egg.

File metadata

  • Download URL: xasm-1.2.0-py3.9.egg
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for xasm-1.2.0-py3.9.egg
Algorithm Hash digest
SHA256 c8140310875a4be4f8ad18b7df5b97748413f95b9c11ef045f681ad8ff22aeed
MD5 692997a44f1092649072acc89c1664f7
BLAKE2b-256 e0fa0f82f1824452d7aa2ce3a28cadf9c402a87a27103e8f0013bfdc56da9fc2

See more details on using hashes here.

File details

Details for the file xasm-1.2.0-py3.8.egg.

File metadata

  • Download URL: xasm-1.2.0-py3.8.egg
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for xasm-1.2.0-py3.8.egg
Algorithm Hash digest
SHA256 b7ad30570c2e50d6902c4cdd20cfd369543a21284bf6482b99ac136d2b1f01cf
MD5 859cea76929fd4ad86b8cfe83da2a56f
BLAKE2b-256 b4c21871a479e55392b7d1a742ab24767759b517f038d795b09086e39e49f23b

See more details on using hashes here.

File details

Details for the file xasm-1.2.0-py3.7.egg.

File metadata

  • Download URL: xasm-1.2.0-py3.7.egg
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for xasm-1.2.0-py3.7.egg
Algorithm Hash digest
SHA256 509c74d02e883c235a323517beee300d888107651213d4d113f8ff7f0c016d31
MD5 033fc7a2dd0a6c03b8ca5d124628d21b
BLAKE2b-256 4147a09c5bbcf8b8094e00f0a9cf825b63ac3af47b851d111fe5704d98e73bc6

See more details on using hashes here.

File details

Details for the file xasm-1.2.0-py3.6.egg.

File metadata

  • Download URL: xasm-1.2.0-py3.6.egg
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for xasm-1.2.0-py3.6.egg
Algorithm Hash digest
SHA256 7b920a063b95c19264a3c021e7e4e906fa54bc68ba4fe9716ade4fed6f4640e7
MD5 a02b64fe585c22d28779b749999821ac
BLAKE2b-256 f3e33a463ce58e4e6fccbe63f78fb1ccff986ada80268c4711845688787f7142

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page