rofl0r / haxdiff

a simple and human readable binary diff format and implementation
MIT License
16 stars 1 forks source link

haxdiff

a simple format and implementation for human-readable binary diffs.

format description

the haxdiff/1.0 format looks pretty much like a standard unified text patch (as produced with diff -u), and can therefore make use of existing syntax highlighting facilities in an editor (e.g. nano).

a patch consists of one or more hunks, with the following layout:

full example:

@@ 17b0,-4,+4
- 04020004
+ 00000000
@@ 3dc14,-4,+4
- 04020004
+ 00000000
@@ b666c,-8,+8
- 0e48396801600e48
+ 0048004701bb3e08
@@ 3ebcb0,-8,+0
- ffffffffffffffff

advantages and disadvantages of the format

compared with other binary patch solutions, this format/impl has the following advantages:

disadvantages:

reference implementation

the haxdiff reference implementation allows both to create and apply patches. patches are always created including the optional - lines, so a patch's consistency can be controlled. it currently does not allow for hunks that have differing + and - - except for truncation and expansion cases.

license

the haxdiff reference implementation is (C) 2021 rofl0r and licensed as MIT. the format itself is licensed as public domain.

compilation

run make. if you want to use specific CFLAGS, you can use either of make CFLAGS="-O2 -g2" or echo "CFLAGS = -O0 -g3" > config.mak.

usage

haxdiff MODE FILE1 FILE2

creates or applies a binary diff.

MODE: d - diff, p - patch, P - force patch

in mode d, create a diff between files FILE1 and FILE2,
and write a patch to stdout.
the generated patch describes how to generate FILE2 from FILE1.
in patch mode, FILE1 denotes the file to be patched, and FILE2
the patched file that will be written (e.g. output file).
the patch itself is read from stdin.
if mode is p, the replaced bytes must match those described in
the patch. if mode is P, the replaced bytes will be ignored.
if mode is d, the patch will be written to stdout.