Skip to main content

wick

wick

Python 3.6 PyPI version Build Status

wick is a Python command line tool that automatically generates file I/O source code for working with binary data.

Why?

I was working on a project that involved reverse engineering file formats and I found that most data structures tend to be composed of several simpler data structures. I also noticed that the simpler structures were all very boilerplate. So I created this tool to write the simple structures for me, and I can do the more interesting work of composing them into the larger structure.

Supported Target Languages

  • C#
  • JavaScript
  • Python

Installation

$ pip install wick

Usage

$ wick example.h Python

What exactly does it do?

Let's walk through a concrete example.

Say we have binary data that is a sequence of records that are represented by a string name and an integer id. First we create a record.h file that contains a C struct representation of this data:

// record.h

// Simple Record
struct Record {
    // Record name
    char name[64];

    // Record id.
    unsigned char id;
};

Then we run wick on the file:

$ wick record.h Python

Which will then create a record.py file whose contents look like:

# record.py
import struct


class Record:
    """Simple Record object

    Attributes:
        name: Record name

        id: Record id.
    """

    format = '<64sB'
    size = struct.calcsize(format)

    __slots__ = (
        'name',
        'id'
    )

    def __init__(self,
                 name,
                 id):
        self.name = name.split(b'\x00')[0].decode('ascii') if type(name) is bytes else name
        self.id = id

    @classmethod
    def write(cls, file, record):
        record_data = struct.pack(cls.format,
                                  record.name.encode('ascii'),
                                  record.id)

        file.write(record_data)

    @classmethod
    def read(cls, file):
        record_data = file.read(cls.size)
        record_struct = struct.unpack(cls.format, record_data)

        return Record(*record_struct)

Then we can import this code into Python and do work.

Read Data

with open(path, 'rb') as file:
    rec = Record.read(file)

Write Data

with open(path, 'wb') as file:
    rec = Record(b'name', 0)
    Record.write(file, rec)

Unpack Lots of Data

import struct

# Assuming the file only contains Record data
with open(path, 'rb') as file:
    recs = [Record(*chunk) for chunk in struct.iter_unpack(Record.format, file.read())]

Contributing

Have a bug fix or a new feature you'd like to see in wick? Send it our way! Please make sure you create an issue that addresses your fix/feature so we can discuss the contribution.

  1. Fork this repo!
  2. Create your feature branch: git checkout -b features/add-javascript-code-generator
  3. Commit your changes: git commit -m 'Implemented Javascript code generator'
  4. Push the branch: git push origin add-javascript-code-generator
  5. Submit a pull request.
  6. Create an issue.

License

MIT

See the license document for the full text.

Metadata

Release files for wick 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wick 1.1.0
File Size Uploaded Provenance Actions
wick-1.1.0.tar.gz 19.6 kB Without provenance Details for wick-1.1.0.tar.gz

Release files / wick-1.1.0.tar.gz

Download URL wick-1.1.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
17e1616947a0b4c68311d85909ed2b62f24bd6ec6367a985df34fa9db94ce0f9
BLAKE2b-256 checksum
How to use checksums
ef9953bc63b4300e61f28115b4db7b53558436ec629c8aba8ee8d45966d7a4f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.6

Security for wick 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page