Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite some bytes of a binary file with dd?

Tags:

unix

binary

dd

I have a binary file and i want to replace the value A2 at address DEADBEEF with some other value, say A1.

How can I do this with dd? If there are other tools that can do this, please suggest. But I plan to do this on iPhone so I can only work with most basic Unix tools.

like image 701
Wei Shi Avatar asked Sep 03 '11 02:09

Wei Shi


People also ask

Does dd command overwrite existing files?

Short answer to the question in the subject: yes, if the of argument refers to a disk partition , the dd command will overwrite the existing data on the partition.

What is seek in dd command?

The dd seek option is similar to the UNIX lseek() system call1. It moves the read/write pointer within the file. From the man page: seek=n Skip n blocks (using the specified output block size) from the beginning of the output file before copying.


1 Answers

printf '\xa1' | dd conv=notrunc of=somefile bs=1 seek=$((0xdeadbeef))
like image 54
Chris Jester-Young Avatar answered Oct 16 '22 19:10

Chris Jester-Young