Last active
July 30, 2016 18:40
-
-
Save or9/4e999108908ec5f227fb50d12d1ffc66 to your computer and use it in GitHub Desktop.
Search for a value in a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILE_TO_SEARCH_IN=$1 | |
STRING_TO_SEARCH_FOR=$2 | |
VALUE_TO_INSERT=$3 | |
#TODO: figure out how to get only the address PLUS OFFSET | |
ADDRESS_TO_INSERT=`hexdump -C $FILE_TO_SEARCH_IN | grep $STRING_TO_SEARCH_FOR` | |
function printAddress { | |
echo $ADDRESS_TO_INSERT | |
exit 0 | |
} | |
function replaceAtAddress { | |
# TODO: use value from above to determine address to replace | |
#ADDRESS_TO_INSERT_AT=0x0000 | |
echo -n $VALUE_TO_INSERT | dd conv=notrunc of=$FILE_TO_SEARCH_IN bs=1 seek=$(($ADDRESS_TO_INSERT)) | |
exit 0 | |
} | |
if [ !$ADDRESS_TO_INSERT ]; then | |
printAddress | |
else | |
echo "Sorry. Not ready yet. TODO though" | |
exit 1 | |
# replaceAtAddress | |
fi | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment