I'm trying to find two bytes inside binary file, then increase value of those two bytes and replace them inside file. Those two bytes are on positions 0x82-0x83. For now on I have successfully extracted those two bytes using this:
#!/usr/bin/env bash BYTES=$(tail -c +131 "$1" | head -c 2)
Those bytes have value:
1B 1F. I'm stuck with:
- How to convert bytes to integer? It should be
- How to append / echo binary data to file
- How to write increased bytes inside file on positions 0x82-0x83. I could use
head -c 130 original.bin >> new_file.bin && magic_command_writing_bytes_to_file >> new_file.bin && tail -c +133 original.bin, but there must be better way.
I could do that in PHP, it should be easier, but I'm interested how to do this in bash.