
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
A versatile and extensible binary data parsing/serializing library for Python 3
Supyr Struct is an extensible and powerful binary data parsing, editing, and serializing library for Python 3.
Supyr's parsing and serializing is declarative, meaning that rather than write code to handle parsing and serializing data, you instead create a description of the structure using various FieldTypes. These descriptions are used by BlockDef objects to build Blocks, which represent/contain the parsed data. A BlockDef is simply a constructor object that scans its description for errors on initialization and uses it for creating Blocks.
Supyr provides a large collection of FieldTypes, ranging from atomic data types(floats and ints of various sizes) to hierarchical structures(structs, containers, and arrays) and logical structures and wrappers(switches and unions).
For a detailed overview of the more abstract concepts and features of Supyr, read the text files in the 'docs' folder.
Check out the changelog here.
This project is licensed under the MIT License, check out the details and author info here.
You'll need Python 3.5 or higher.
In your terminal execute:
python3 -m pip install supyr_struct
or, you can clone/download this repo and run the setup.py:
git clone git@github.com:Sigmmma/supyr_struct.git
cd supyr_struct
python3 -m pip install .
Heres a small example of defining a structure using a BlockDef and FieldTypes and using it to create a Block.
>>> from supyr_struct import *
>>>
>>>
>>> asdf = BlockDef('some_block',
... UInt32('some_int'),
... BytesRaw('some_bytes', SIZE=16),
... ENDIAN='>')
>>>
>>>
>>> test_block = asdf.build()
>>> test_block.some_int = 1337
>>> test_block['some_bytes'] = b'here\'s a cstring\x00'
>>>
>>> print('test_block:', test_block)
test_block: [ Container, entries:2, some_block
[ UInt32, size:4, some_int, 1337 ]
[ BytesRaw, size:16, some_bytes, <RAWDATA> ]
]
>>>
>>>
>>> test_block.serialize()
BytearrayBuffer(b"\x00\x00\x059here\'s a cstring\x00")
Supyr allows forcing endianness to be either big, little, or back to normal on a library scale and/or on individual FieldTypes.
>>> field_types.FieldType.force_little()
>>> test_block.serialize()
BytearrayBuffer(b"9\x05\x00\x00here\'s a cstring\x00")
>>>
>>> field_types.FieldType.force_normal()
>>> test_block.serialize()
BytearrayBuffer(b"\x00\x00\x059here\'s a cstring\x00")
>>>
>>> field_types.FieldType.force_big()
>>> test_block.serialize()
BytearrayBuffer(b"\x00\x00\x059here\'s a cstring\x00")
>>>
>>> field_types.FieldType.force_little()
>>> test_block.serialize()
BytearrayBuffer(b"9\x05\x00\x00here\'s a cstring\x00")
Take a look at the examples module for some ready-to-run example programs that utilize Supyr in different ways.
If you're having any issues with the library you can report them on our GitHub Issues page.
If the issue requires some more direct attention we'll drop a contact link.
FAQs
A versatile and extensible binary data parsing/serializing library for Python 3
We found that supyr-struct demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.