Editing binary files

I am working in C and need a solution for below problem:

I have a binary file, which needs to be edited in such a way no data is loss.
For example i have to insert 3 bytes of data at some position without changing the contents of the file.

if file has data as:
64795F8144054D595343435F813605494E44544D

and i need to add data 630000 like

64796300005F8144054D595343435F813605494E44544D

I have an Hex editor which enables me to see binary files in Hexadecimal mode.

I have tried fseek to reach that position and then write but it overwrites the current data bytes e.g,
6479630000054D595343435F813605494E44544D
data 5F8144 is lost.

but i want it to get inserted at that position as in earlier case.

Please share your comments.
Thanks in advance.

There's no file operation for "insert bytes here", you'll have to do this the hard way: store everything after the modified bytes in memory or temp file so you can overwrite everything after the insertion with the data you want to be there.

try `bvi' - the binary vi ;

  • it's available at sourceforge ;

good luck, and success !

alexandre botao
<< botao {dot} org >>