All Projects → malinoff → structures

malinoff / structures

Licence: Apache-2.0 License
Declarative binary data builder and parser: simple, fast, extensible

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to structures

Binjs Ref
Reference implementation for the JavaScript Binary AST format
Stars: ✭ 399 (+1275.86%)
Mutual labels:  parsing, binary
Corrode
A batteries-included library for reading binary data.
Stars: ✭ 116 (+300%)
Mutual labels:  parsing, binary
Formatfuzzer
FormatFuzzer is a framework for high-efficiency, high-quality generation and parsing of binary inputs.
Stars: ✭ 117 (+303.45%)
Mutual labels:  parsing, binary
siemstress
Very basic CLI SIEM (Security Information and Event Management system).
Stars: ✭ 24 (-17.24%)
Mutual labels:  parsing
tangle-rs
a collection of tools to do tangle in rust
Stars: ✭ 23 (-20.69%)
Mutual labels:  parsing
copper
An integrated context-aware scanner and parser generator
Stars: ✭ 14 (-51.72%)
Mutual labels:  parsing
YaccConstructor
Platform for parser generators and other grammarware research and development. GLL, RNGLR, graph parsing algorithms, and many others are included.
Stars: ✭ 36 (+24.14%)
Mutual labels:  parsing
hs-packer
Fast serialization in haskell
Stars: ✭ 13 (-55.17%)
Mutual labels:  binary
CYK-Parser
A CYK parser written in Python 3.
Stars: ✭ 24 (-17.24%)
Mutual labels:  parsing
loquat
Monadic parser combinators for JavaScript / TypeScript
Stars: ✭ 47 (+62.07%)
Mutual labels:  parsing
php-binary
A PHP library for parsing structured binary streams.
Stars: ✭ 30 (+3.45%)
Mutual labels:  parsing
mdict
node.js mdict (*.mdx, *.mdd) file reader
Stars: ✭ 39 (+34.48%)
Mutual labels:  binary
kolasu
Kotlin Language Support – AST Library
Stars: ✭ 45 (+55.17%)
Mutual labels:  parsing
macpack
Makes a macOS binary redistributable by searching the dependency tree and copying/patching non-system libraries.
Stars: ✭ 20 (-31.03%)
Mutual labels:  binary
Jsonify
♨️A delightful JSON parsing framework.
Stars: ✭ 42 (+44.83%)
Mutual labels:  parsing
octet
A library that makes working with bytebuffers painless.
Stars: ✭ 79 (+172.41%)
Mutual labels:  parsing
basgo
basgo compiles BASIC-lang to Golang. Then 'go build' can translate code to native executable binary.
Stars: ✭ 31 (+6.9%)
Mutual labels:  binary
racket-bitsyntax
Erlang-style binaries/bitstrings for Racket
Stars: ✭ 29 (+0%)
Mutual labels:  parsing
Ohm-S
A Squeak/Smalltalk implementation of the metaprogramming framework Ohm.
Stars: ✭ 18 (-37.93%)
Mutual labels:  parsing
xgadget
Fast, parallel, cross-variant ROP/JOP gadget search for x86/x64 binaries.
Stars: ✭ 33 (+13.79%)
Mutual labels:  binary

structures: declarative binary data processing

CI Status

structures is a Python package that allows you to declaratively describe binary data structures (like a network protocol or a file format), and to use that declaration to process binary data: to build bytes from python objects, to parse bytes to python objects and to calculate size of the described structure.

>>> from structures import Struct, Const, Integer, Contextual, RepeatExactly, Bytes
>>> class BMP(Struct):
...     signature = Const(b"BMP")  # 3 constant bytes
...     width = Integer(1)  # 1 byte
...     height = Integer(1)  # 1 byte
...     pixels = Contextual(Bytes, lambda ctx: ctx['width'] * ctx['height'])  #  width * height bytes
>>> bmp = BMP()
>>> bmp.build({'width': 3, 'height': 2, 'pixels': b'\x07\x08\t\x0b\x0c\r'})
b'BMP\x03\x02\x07\x08\t\x0b\x0c\r'
>>> bmp.parse(b'BMP\x03\x02\x07\x08\t\x0b\x0c\r') == {
...     'signature': b'BMP', 'width': 3, 'height': 2,
...     'pixels': b'\x07\x08\t\x0b\x0c\r',
... }
True
>>> bmp.sizeof(context={'width': 10, 'height': 10})
105

More sophisticated, real-world examples live in examples directory.

Available Constructs

  • Primitive: Pass, Flag, Bytes, Integer, Float, Padding, Const
  • Adapters: Repeat, RepeatExactly, Adapted, Prefixed, Padded, Aligned
  • Strings: String, PascalString, CString, Line
  • Structs: Struct, Contextual, Computed
  • Bit-wise: BitFields
  • Conditionals: If, Switch, Enum, Raise
  • Stream manipulation: Offset, Tell
  • Data transformers: Checksum
  • Debugging utilities: Debug

You can find usage examples in constructs docstrings.

All docstrings, examples, and even this readme are tested using doctest.

How To Contribute

This project uses Pull Requests for all kinds of contributions.

You have a question? Make a pull request with an example of structure that confuses you. This way we will improve the docs and examples so another person won't be confused. And they won't need to dig through issues to see if their question has already been answered.

You think you have found a bug? Make a pull request describing a buggy structure. If you are courage enough, feel free to also submit a bug fix :)

You have a feature request? Make a pull request briefly describing your feature. This can be a class with a (failing) example in its docstring. Even if it's not valid python code - your example will help to understand the intention. Having an initial implementation of your feature will greatly reduce the time needed to make your feature appear in the next release.

A detailed guide on how to contribute can be found in CONTRIBUTING.rst.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].