bin2src
bin2src is a simple command line that converts a binary file to an array of bytes, defined at a source of another language, so you can embed it into your program.
Currently supported output languages:
- C
- C (shellcode)
- Pascal
- Python
- Rust
Overview
bin2src reads a binary file (.jpg, .wav, .mp3, etc.) and generate a source file with the binary data embeded into it as a byte array.
Sometimes, maybe you don't want to distribute a binary file inside your program's package and users can access it directly.
With bin2src you can embed it inside the executable and read the bytes direct from memory.
Keep in mind that it's always possible for an "advanced" user extract the file, even inside the executable.
Give a Star! :star:
If you like this project and find it useful, please give it a star. I appreciate very much! Thanks!
Usage
Examples
Suppose you have an image myimage.jpg:
Example 1:
bin2src --out-language pascal --out-dir "X:\My Projects\project01" --out-file image01 myimage.jpg
Windows paths with spaces needs quotation marks
will create the file ...\image01.pas with bytes in decimal format: [210, 0, ...].
Example 2:
bin2src -l c -d "X:\My Projects\project02" -f image01 -h myimage.jpg
will create the files (with bytes in hexadecimal: [0x10, 0xfa, ...]):
...\image01.h...\image01.c
Example 3:
bin2src --out-language python myimage.jpg
will create the file "myimage.py" at the current directory. Check the examples directory for some practical uses of bin2src.
Atention
-
Beware with the file size that you'll embed in your code!!!
Verify if it's accepted by your O.S., compiler, language standards, memory at runtime, etc.
-
if the file has more dots, in addition to the dot that separates the extension name and you don't use the
--out-fileor-fcommand line option, the output file name will be the first name before the first dot. Example (generating a 'y' file):abc.def.ghi.x=>abc.y -
The behavior of the option
--hexor-hfor C shellcode is different than the other languages. Without this flag, it will generate an array ofunsigned charbytes, but with the hexadecimal flag, it will embed the bytes as a string (char *). -
If you'll generate C shellcode as string, make sure that the binary does not contais null bytes ("\x00") or don't use string functions like
strlen. This may break your code and could cause exceptions (access violations, etc.). -
All the tests was made (until now) with Windows 10 Pro (2004) and to execute the alpha release maybe you have to install the latest MSVC runtime.
-
There are a lot of things to organize and improve the project. Please, check the TODO list.
License
Developed by Alexandre Gomiero de Oliveira under the GPL-3.0 License.
Any code generated by bin2src are under MIT License.
Please contact me if you need a different license.
If you'll use the tool to develop commercial products, please, consider make a donation to help me with future projects. :smiley: :thumbsup: :pray: