dots/scripts/Documents/Scripts/davinky.sh

15 lines
717 B
Bash
Raw Normal View History

2024-04-29 19:05:39 +02:00
pattern="\x55\x41\x56\x53\x48\x83\xEC\x20\x49\x89\xFE\x85\xF6\x0F\x84....\x81\xFE\x13\xFC\xFF\xFF\x0F\x85"
offset=14
file="/opt/resolve/bin/resolve"
# https://stackoverflow.com/a/17168777
matches=$(LANG=C grep -obUaP $pattern $file)
matchcount=$(echo "$matches" | wc -l)
if [[ -z $matches ]]; then echo "pattern not found";
elif [[ $matchcount -ne 1 ]]; then echo "pattern returned $matchcount matches instead of 1";
else
patternOffset=$(echo $matches | cut -d: -f1)
instructionOffset=$(($patternOffset + $offset))
echo "patching byte '0x$(hexdump -s $instructionOffset -n 1 -e '/1 "%02x"' $file)' at offset $instructionOffset"
echo -en "\x85" | dd conv=notrunc of=$file bs=1 seek=$instructionOffset count=1;
fi