Giter VIP home page Giter VIP logo

zigescape's Introduction

zigescape

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"

Building / Installation

Precompiled binaries

  1. Go to the latest release
  2. Download the relevant asset for your OS
  3. Rename to zigescape or zigescape.exe and give it executable permission (if necessary on your OS)
  4. Move the executable somewhere in your PATH

From Source

Requires latest master of Zig.

  1. zig build
  2. The compiled binary will be in zig-out/bin
  3. mv or ln the binary somewhere in your PATH

Usage

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.

Examples

Converting to a 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"

Converting from string literal

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

Some silly examples

cating 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

zigescape's People

Contributors

squeek502 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.