我有一个二进制文件,我需要比较文件中的位 Blob (具有某种模式),并将它们替换为相同大小的新位 Blob 。
想知道最好的方法是什么?
#$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 相等并且 显然它不会对我造成影响。我在这里错过了什么吗? 请忍受我,因为我是脚本世界的初学者
最佳答案
您可以在 bash 中尝试此操作以与二进制文件进行比较
diff <(xxd b1) <(xxd b2)
或者这个:
vimdiff <(xxd b1) <(xxd b2)
如果您正在寻找更强大的工具,请尝试 DHEX、VBinDiff、JDIFF。
另请参阅 post 。
关于linux - 与脚本比较并插入位 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14716074/