A tool for converting between binary data and Zig string literals.
The original motivation for this was to be able to easily turn inputs found via fuzz testing into strings that can be used in Zig test cases (like in the tests added by this commit).
Basic example (more can be found below):
$ echo '00 01 02 03 04' | xxd -r -p | zigescape
"\x00\x01\x02\x03\x04"
or with the --hex
option, this can be done directly:
$ zigescape --hex "00 01 02 03 04"
"\x00\x01\x02\x03\x04"
- Go to the latest release
- Download the relevant asset for your OS
- Rename to
zigescape
orzigescape.exe
and give it executable permission (if necessary on your OS) - Move the executable somewhere in your
PATH
Requires latest master of Zig.
zig build
- The compiled binary will be in
zig-out/bin
mv
orln
the binary somewhere in yourPATH
Usage: zigescape [-hsx] [-o <PATH>] <INPUT>
<INPUT>: Either a path to a file, or a Zig string literal (if using --string),
or a series of hex bytes in string format (if using --hex).
If <INPUT> is not specified, then stdin is used.
Available options:
-h, --help Display this help and exit.
-o, --output <PATH> Output file path (stdout is used if not specified).
-s, --string Specifies that the input is a Zig string literal.
Output will be the parsed string.
-x, --hex Specifies that the input is a series of hex bytes
in string format (e.g. "0A B4 10").
Output will be a Zig string literal.
zigescape path/to/file
or
zigescape < path/to/file
or, if you want to output to a file:
zigescape path/to/file -o path/to/outfile
or, if you want to convert from a series of hex bytes in string format:
zigescape --hex "00 01 02 03 04"
Note: shell escaping of arguments can mess with the string literal before it gets parsed, so it's best to use single quotes to bypass shell escaping.
zigescape --string '"hello world\n"'
The double quotes are optional, zigescape
will add them if they are missing:
zigescape --string 'hello world\n'
To convert from a series of hex bytes to a string literal and then into a binary file:
zigescape --hex "00 01 02 03 04" | zigescape --string -o outfile.bin
cat
ing a file by converting it to a string literal and then parsing it to stdout:
zigescape path/to/file | zigescape --string
Copying a file by converting it to a string literal and then parsing it:
zigescape path/to/file.orig | zigescape --string -o path/to/file.copy