FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 12-02-2008, 12:54 PM
Alfredo Finelli
 
Default How can I write a shell script to update one octet in binary file (like I do manually with hexedit program) ?

On Tuesday 02 December 2008 13:33, KLEIN Stéphane wrote:
> Hi,
>
> I need to update one octet in a binary file (it's disk image file
> raw).
>
> To do that, I use hexedit and I do update manualy.
>
> Now, I would like to script this task, I know address of octet to
> update and the new value.
>
> Do you know a tool to do that ?
> [...]

Hi,

this is an example. Suppose you have the original file "orig":

$ hexdump -v -x orig
0000000 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e
0000010 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e
0000020 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e
0000030 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e
0000040 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e
0000050 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e
0000060 0e0e 0e0e
0000064

and you want to apply some arbitrary length patch at some point in the
file. You have the following "patch" file, in this case 10 bytes:

$ hexdump -v -x patch
0000000 7a7a 7a7a 7a7a 7a7a 7a7a
000000a

Now, with this command we insert the content of "patch" in "orig" at
byte 20:

$ dd if=patch bs=1 conv=notrunc of=orig seek=20 count=10
10+0 records in
10+0 records out
10 bytes (10 B) copied, 7.8222e-05 seconds, 128 kB/s

And here is the result:
$ hexdump -v -x orig
0000000 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e
0000010 0e0e 0e0e 7a7a 7a7a 7a7a 7a7a 7a7a 0e0e
0000020 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e
0000030 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e
0000040 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e
0000050 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e 0e0e
0000060 0e0e 0e0e
0000064

Best regards,


alfredo


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 09:55 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org