Skip to content

Instantly share code, notes, and snippets.

@jpiccari
jpiccari / bwrite.sh
Last active January 3, 2016 02:29
I found myself updating a few bytes within files often. This script quickly allows the update of 1 or more bytes so I don't have to open a hex editor for such a simple task.
#!/bin/sh
if [ "$#" -ne 3 ] || ! [ -f "$1" ]; then
# usage
echo "$(basename $0) [file] [offset] [bytes]"
exit 1
fi
bytes=$(printf "$3" | xxd -p)
printf $bytes | xxd -r -p | dd of="$1" seek=$(( $2 )) count=$(( ${#bytes} / 2 )) bs=1 conv=notrunc &> /dev/null