#!/bin/bash #Script that patches .vhd files to be correctly read vhditools by turning LE parent filenames into BE if [ $# -eq 0 ]; then echo "Usage: $0 <.vhd>" exit 1 fi str=$(strings -e l $1 | head -n 1) echo $str read -p "Do you want to patch the listed string? (y/N): " -n 1 -r echo # move to a new line if [[ $REPLY =~ ^[Yy]$ ]] then be=$(echo -n $str | iconv -f UTF-8 -t UTF-16BE | xxd -p -c1 | tr -d '\n ' | sed 's/../\\x&/g') le=$(echo -n $str | iconv -f UTF-8 -t UTF-16LE | xxd -p -c1 | tr -d '\n ' | sed 's/../\\x&/g') mv $1 $1.old bbe -e "s/$le/$be/" $1.old | pv -s $(stat --printf="%s" $1.old) > $1 fi rm $1.old