Bin2h - Win32/DOS binary to C header file converter
A dual-mode Win32/DOS command-line utility for converting a binary file into a C header file, representing the contents of that file as a block of data.
License
Free of charge for unmodified non-commercial use; please contact me for anything else including custom versions, redistribution permission or commercial use.
Usage
Download the tool from here.
You must specify the name of variable to define. Two switches control optional functionality, detailed below.
The input data is read from standard input, the resulting file is written to standard output. No seeking is performed, so either or both may be pipes or similar.
Syntax
bin2h [<flags>] <variable name>
-c flag | Count | Optionally defines a variable containing the data block length in bytes. |
-z flag | Zero-terminate | Appends a NULL character to the data, useful for textual content. |
Variable name | Required | The name of variable to be defined. |
Note that if both flags are present, they must be combined: '-cz' as opposed to '-c -z'.
Example
bin2h -cz eula < eula.txt
C code will be written to stdout defining two variables: a null-terminated character array named 'eula' containing the file eula.txt, followed by an integer eula_size equal to the number of bytes, including the terminating null.
Notes
The syntax has changed from the previous version of this tool, which remains available in case it is needed: old-bin2h.exe - both versions will display the syntax required if run without arguments.
Known bugs
None so far!