I need to modify a byte in a binary file at a certain offset.
Example:
- Input file:
A.bin
- Output file:
B.bin
I need to read a byte at the offset 0x40c
from A.bin
, clear to 0 least significant 2 bits of this byte, and then write file B.bin
equal to A.bin
, but with the calculated byte at offset 0x40c
.
- I can use Bash and standard commands like
printf
and dd. - I can easily write a byte into a binary file, but I don't know how to read it.
Modify a byte in a binary file using standard Linux command line tools.