WhiteMask
WhiteMask

Reputation: 646

Put Hex Into .bin File

How would you stick a string of hexcode into a .bin file? Like this, \x45\x67\x89 for example. I've seen the long examples where you use bash to strip it then add it to the .bin, but there must be a quicker and simpler way?

Also, I am not too familiar with .bin's, are they a program in themselves?

Upvotes: 1

Views: 252

Answers (1)

Asain Kujovic
Asain Kujovic

Reputation: 1829

printf is function wide supported function. C, cpp, php, python, bash...

so classic implementation in C would be:

FILE *fp =fopen('binfilename.bin', 'w');
fprintf(fp, "\x45\x67\x89"); fclose(fp);

all other languages have similar usage. you mention bash, and i think there is no simpler way than bash itself:

printf "\x45\x67\x89" > binfilename.bin

Every file is binary file. If it contains just printable bytes, we call it textual file. If it is generated by compiler and have bytes meaningfull to cpu, not to human, than we say it is 'binary', program. But both textual and binary contains bytes and are binaries. Difference is after, when we/some app interprets it's contents.

Upvotes: 1

Related Questions