Is there any straightforward way to modify a binary from the commandline? Let\'s say I know that my binary contains 1234abcd and i want to change it to 12FFabcd or FFFFabcd
Here's a Bash function replaceByte
, which takes the following parameters:
#!/bin/bash
# param 1: file
# param 2: offset
# param 3: value
function replaceByte() {
printf "$(printf '\\x%02X' $3)" | dd of="$1" bs=1 seek=$2 count=1 conv=notrunc &> /dev/null
}
# Usage:
# replaceByte 'thefile' $offset 95
Regarding Josh answer: In case you want to do it for a specific address
hexdump -C {file location}
with some hex value you might have tried to add 0x but it would fail :
dd: warning: ‘0x’ is a zero multiplier; use ‘00x’ if that is intended
You can achieve this by encapsulating it with $(()) that the terminal will translate as an int value :
mybinary={file location}
printf '\x31\xc0\xc3' | dd of=$mybinary bs=1 seek=$((0x100)) count=3 conv=notrunc