All Projects → marhop → literate-binary

marhop / literate-binary

Licence: MIT license
Integrate handcrafted binary and documentation

Programming Languages

haskell
3896 projects

Projects that are alternatives of or similar to literate-binary

buffertools-php
Toolbox for working with binary and hex data. Similar to NodeJS Buffer.
Stars: ✭ 60 (+62.16%)
Mutual labels:  hex, binary
SwiftRadix
Easily convert integers to binary/hex/octal strings and back again with clean functional syntax.
Stars: ✭ 34 (-8.11%)
Mutual labels:  hex, binary
hext
Markup language and tool for generating binary files
Stars: ✭ 23 (-37.84%)
Mutual labels:  hex, binary
Heksa
CLI hex dumper with colors
Stars: ✭ 133 (+259.46%)
Mutual labels:  hex, binary
Image-Processing-CLI-in-Rust
CLI for image processing with histograms, binary treshold and other functions
Stars: ✭ 25 (-32.43%)
Mutual labels:  binary
extrude
🕵️ Analyse binaries for missing security features, information disclosure and more...
Stars: ✭ 51 (+37.84%)
Mutual labels:  binary
Alfred-Colors-workflow
hex <=> rgb <=> hsl
Stars: ✭ 28 (-24.32%)
Mutual labels:  hex
Xprof
A visual tracer and profiler for Erlang and Elixir.
Stars: ✭ 246 (+564.86%)
Mutual labels:  hex
gucci
Templating on the command line with sprig.
Stars: ✭ 74 (+100%)
Mutual labels:  binary
exe2hex
Inline file transfer using in-built Windows tools (DEBUG.exe or PowerShell).
Stars: ✭ 284 (+667.57%)
Mutual labels:  hex
go-delta
go-delta - A Go package and utility to generate and apply binary delta updates.
Stars: ✭ 25 (-32.43%)
Mutual labels:  binary
khroma
A collection of functions for manipulating CSS colors, inspired by SASS.
Stars: ✭ 28 (-24.32%)
Mutual labels:  hex
dehex
🎨👀 R package: learn to assess a colour hex code by eye
Stars: ✭ 29 (-21.62%)
Mutual labels:  hex
jomini
Low level, performance oriented parser for save and game files from EU4, CK3, HOI4, Vic3, Imperator, and other PDS titles.
Stars: ✭ 40 (+8.11%)
Mutual labels:  binary
contentful.ex
Elixir SDK for the Contentful Delivery API
Stars: ✭ 32 (-13.51%)
Mutual labels:  hex
fpbinary
Fixed point package for Python.
Stars: ✭ 30 (-18.92%)
Mutual labels:  binary
binstruct
Golang binary decoder for mapping data into the structure
Stars: ✭ 67 (+81.08%)
Mutual labels:  binary
hxd
Speedy colored hexdump
Stars: ✭ 33 (-10.81%)
Mutual labels:  hex
monobit
Tools for working with monochrome bitmap fonts
Stars: ✭ 124 (+235.14%)
Mutual labels:  hex
bmod
bmod parses binaries for modification/patching and disassembles machine code sections.
Stars: ✭ 12 (-67.57%)
Mutual labels:  binary

literate-binary

There are times when a binary file has to be crafted by hand, be it for testing purposes, for research, or just for some weird kind of fun. Usually, a hex editor is the tool of choice for straightforward binary editing. But what about documentation? There is no way to enter inline comments or other explanatory prose in a hex editor, leading to separation of hex code and documentation. (Or worse, to no documentation at all.)

Wouldn't it be great if there was a way to combine binary (expressed as hex code) and textual content in the same file? If both a binary file and accompanying documentation in formats like HTML or PDF could be generated from the same source file? There is!

Just write a Markdown file like this example. Run it through your favourite Markdown converter (mine is Pandoc) to create a pretty HTML or PDF document; run it through lb to create a binary file from its hex content.

                pandoc -> documentation.{html,pdf,docx,...}
              /
source.bmp.md
              \
                lb     -> binary.bmp

Obviously, this is inspired by Donald Knuth's ideas on literate programming.

Syntax

The lb (literate binary) tool produces a binary file from a Markdown input file. The binary is made up by all code blocks in the input file tied together. All other content including inline code in backticks `like this` is ignored. The code blocks must contain nothing but hex strings, whitespace and comments. The set of valid hex strings is defined as follows:

Each sequence of hex characters (0-9, A-F, upper or lower case) with even length like 00ff is a valid hex string; each pair of characters in this sequence translates to one byte in the usual fashion. Given hex strings x and y and a positive integer n, the following macros are valid hex strings as well:

  • A repetition of the form (x){n}. This translates to the byte sequence corresponding to x, repeated n times. The integer n may be followed by a multiplicative suffix K (factor 2¹⁰, KiB), M (factor 2²⁰, MiB), or G (factor 2³⁰, GiB). Examples: (00ff){3}00ff00ff00ff, (00){2M} → 2 MiB of NULL bytes
  • An alternative of the form (x|...|y). This translates to the byte sequence corresponding to either x or ... or y, selected randomly. Example: (00|ff|3333) → one of 00, ff or 3333
  • A range of the form (x-y). This translates to one random byte sequence from the range defined by x and y. Example: (0c-0f) → one of 0c, 0d, 0e or 0f
  • The special range . (a single dot). This translates to one random byte, so it is equivalent to the range (00-ff).
  • A string of the form "..." or '...' with arbitrary text content inside the quotes. The quote sign itself may appear inside the string escaped by a backslash like \", a literal backslash has to be escaped by another backslash like \\. This translates to the UTF-8 encoded byte sequence corresponding to the quoted string content. (Note that ASCII is a subset of UTF-8.) Example: "foo bar"666f6f20626172

When combining an alternative, a range or a string with a repetition, redundant parentheses are not required: (x|y){n} is equivalent to ((x|y)){n}, (x-y){n} is equivalent to ((x-y)){n}, .{n} is equivalent to (.){n}, and "foo"{3} is equivalent to ("foo"){3}.

Comments start with a # sign and end at the end of the line.

It is possible to exclude single code blocks from processing; fenced code blocks with the .nobin class are ignored by lb. This can be used to add code other than binary, or to "comment out" a whole code block.

Here is a complete example describing a simple Bitmap image file; there are several others in the examples/ directory.

Usage

Get a binary here and put it in your PATH (and, if necessary, make it executable -- hint: chmod u+x lb). Then:

$ lb --help
$ lb source.bmp.md --output binary.bmp
$ echo '(00ff){42} 0a' | lb --plain

Note that no Markdown is involved in the last command, just plain hex code. Strictly speaking, this defeats the purpose of literate binary, reducing lb to a beefed-up reverse hex dump tool. Anyway, it's useful for quick tests, so never mind.

Contributing

Pull requests, particularly well-documented example files (minimal file format examples, misuse of format specifications, ...) are greatly appreciated!

Building from source

This tool is written in Haskell, so you need GHC (compiler) and Cabal (build tool), best installed with ghcup if you use a Unix-like OS. Clone the Git repository, change to its top level directory and run the following commands to build and optionally install the lb binary:

$ cabal build
$ cabal install
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].