Home

Awesome

bin2coff

bin2coff is a tool to create COFF object files containing binary data, which is useful e.g. to embed a binary file in a C/C++ project.

The code on which this project is based was originally created by Pete Batard as part of the libwdi project and modified by Artifex Software Inc. and included in the MuPDF source code.

I translated the original code to C# and added support for producing ARM64 compatible object files (which, in addition to a different flag in the file header, also require the data to be aligned to 4-byte boundaries).

Usage

bin2coff bin obj [label] [64bit|Win32|x64|arm64]

With your linker set properly, typical access from a C source is:

extern uint8_t  label[]     /* binary data         */
extern uint32_t label_size  /* size of binary data */

This program aims to be a drop-in replacement for other bin2coff versions (e.g. the one included with MuPDF): simply place the executable in the place where the toolchain expects it to be to make it possible to generate arm64-compatible obj files. For x86 and x64 targets, the binaries produced by this program should be identical to the original bin2coff.

Building from source

To build the program from the source code, you will need the .NET 6 SDK or higher. You should use a Windows machine.

  1. Download the source code: bin2coff-1.0.0.tar.gz (or clone the repository).
  2. Open a command prompt in the folder where you have downloaded the source code, type BuildBinaries and press enter. This will build the binaries for the x64, x86 and arm64 versions of the program (each version can produce object files for all platforms - use the one that corresponds to the host architecture). You can find them in the Release folder.
  3. (Optional) To sign the binaries, you will need to have the signtool utility installed and in your PATH. You can get this e.g. by opening a Visual Studio Developer command prompt in the folder with the source code. Use the command SignBinaries <path_to_certificate.p12> <certificate_password> to sign the binaries.