Skip to main content

Better binary serialization for python

Project description

pybinary

A simple binary serializer/deserializer in pure python.

Limitations

Variable-sized fields are not supported. No size check on assignment for the most of the types.

Installation

Install from pypi:

pip install pybinary

Or download the repository and build from the sources:

python3 ./setup.py build
python3 ./setup.py install

Examples

ELF64 header

Spec taken from https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html

class Elf64_Ehdr(BinarySerializable):
    e_ident = ArrayTypes.bytearray(16)
    e_type = Types.u16
    e_machine = Types.u16
    e_version = Types.u32
    e_entry = Types.u64
    e_phoff = Types.u64
    e_shoff = Types.u64
    e_flags = Types.u32
    e_ehsize = Types.u16
    e_phentsize = Types.u16
    e_phnum = Types.u16
    e_shentsize = Types.u16
    e_shnum = Types.u16
    e_shstrndx  = Types.u16


header = Elf64_Ehdr.deserialize(input_stream_or_bytes) # deserialize header
header.e_phnum += 1 # update any field
header.serialize() # serialize and get updated bytes
...

CPIO Newc ACII Format Archive

Spec taken from https://manpages.ubuntu.com/manpages/bionic/man5/cpio.5.html

Code here

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

pybinary-0.9.5.tar.gz (5.4 kB view hashes)

Uploaded Source

Built Distribution

pybinary-0.9.5-py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 3

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