我有一个二进制文件,我需要比较文件中的位块(带有某种模式)并用相同大小的新位块替换它们。
想知道最好的方法是什么?
#$1 and $2 are two different binary files.
function compareByteByByte()
{
counter=0
while [ $counter -le $(( $PNG_FILE_SIZE-1 )) ]
do
S1=$($READFILE_EXE -t x1 --read-bytes=1 --skip-bytes=0 $1 | head -1 | awk '{print $2}')
S2=$($READFILE_EXE -t x1 --read-bytes=1 --skip-bytes=$counter $2 | head -1 | awk '{print $2}')
if [ $S1==$S2 ]; then
counter=$(( $counter + 1 ))
echo "Offset#$counter: $S2"
else
echo "S1('$S1') is equal to S2('$S2')"
break
fi
done
}
如果 S1 和 S2 相等,我想打破循环,显然它不会对我造成影响。我在这里错过什么了吗?忍受我,因为我是脚本世界的初学者