GitXplorerGitXplorer
w

bindef

public
37 stars
1 forks
1 issues

Commits

List of commits on branch master.
Verified
500aa74215e17af30698fa98fc89c4a7f2ce5f30

Upgrade to GitHub-native Dependabot (#6)

ddependabot-preview[bot] committed 4 years ago
Verified
52350f99e33eb58a4230272e065f960d3f9d420f

bin, lib: RuboCop fixes (#5)

wwoodruffw committed 4 years ago
Verified
d0ebc3f1ac1291b6491ae74122af68e27c14fa58

rubocop: Update rule name

wwoodruffw committed 4 years ago
Verified
054524f6cb4ccdb138b12bcb3cecc9ef11116765

rubocop: Add a bunch of new cops (#3)

wwoodruffw committed 5 years ago
Verified
032dd7546ea99cac57ba1bbdf468af23b2765edc

spec: Remove old codecov stuff

wwoodruffw committed 5 years ago
Verified
0396af4549cd8fd562c2ea73ca1f67632ae180d1

bindef/version: 0.0.6

wwoodruffw committed 5 years ago

README

The README file for this repository.

bindef

license Gem Version Build Status Coverage Status Maintainability

bindef is a DSL and command-line tool for building binary files.

It's inspired by t2b, but with a few crucial differences:

  • bindef scripts run within a Ruby process, making the DSL a strict superset of Ruby
  • Support for different (and multiple!) endians, string encodings, etc, is baked into the language
  • Reports common mistakes loudly as warnings (or errors, if severe enough)
  • Comes with a collection of user-selectable extensions for common binary formats (TLVs, control codes, etc.)

Syntax

bindef's syntax is stream-oriented, with two primary expressions: commands and pragmas.

Commands cause bindef to emit data, while pragmas influence how commands act.

Here's a simple bindef script that emits a unsigned 32-bit integer twice, in different endians:

# `bindef` starts in little-endian, so this is redundant
pragma endian: :little

u32 0xFF000000

# or `pragma :endian => :big`, if you prefer
pragma endian: :big

u32 0xFF000000

The example directory has more. Read the SYNTAX file for a complete listing of commands and pragmas.

Installation

bindef is available via RubyGems:

$ gem install bindef
$ bd -h

You can also run it directly from this repository:

$ ruby -Ilib ./bin/bd -h

Usage

In general, running a bindef script is as simple as:

$ bd < path/to/input.bd > path/to/output.bin

or:

$ bd -i path/to/input.bd -o /path/to/output.bin

You can also choose to enable one or more extra command sets via the -e, --extra flag:

# extra commands for building TLVs
$ bd -e tlv < input.bd > output.bin

# extra commands for ASCII control codes and string manipulation
$ bd -e ctrl,string < input.bd > output.bin

Design goals

bindef should...

  • ...have no runtime dependencies other than the current stable Ruby
  • ...be easy to read, even without knowledge of Ruby's syntax
  • ...be easy to write, even without knowledge of Ruby's syntax
  • ...be easy for other programs to emit without being (too) aware of Ruby's syntax
  • ...be easy to debug, with warnings and errors for common mistakes (overflows, negative unsigned integers, etc.)