Script command to manage a binary file (on Linux)

I am looking for a mechanism to manage my eeprom image with a unique device identifier. I would like to do this in the make file so that the device automatically gets a new identifier and then updates it to a data image and then launches it. In pseudo code:

wget http://my.centralized.uid.service/new >new.id binedit binary.image -write 0xE6 new.id flash binary.image into device 

So, first we enter the identifier in a separate file, then rewrite the image (from the specified offset) with the contents of this file ID. Then flare up. But how to make the second part? I looked at bvi, which seems to have some scripting capabilities, but I didn’t quite understand this, and honestly, vi always gave me creeps.

Thanks for the help in advance!

+4
source share
3 answers

(Full disclosure: I made an initial vote to close it as a duplicate. This answer is adapted from the question mentioned.)

Use dd with the notrunc option:

 offset=$(( 0xe6 )) length=$( wc -c < new.id ) dd bs=1 if=new.id of=binary.image count=$length seek=$offset conv=notrunc 

You can try this on a copy first to make sure that it works correctly.

+2
source

If you know the offset of the file you want to replace, you can use the split command to split the initial file before the offset. The cat can be used to combine the necessary fragments.

Another useful tool when working with binary files is od , which allows you to examine binary files in humanoid format.

+2
source

Perhaps I would use something like Perl . See here and, in particular, the section labeled “Updating a random access file” (example here )

0
source

Source: https://habr.com/ru/post/1432251/


All Articles