Skip to content

Instantly share code, notes, and snippets.

@minlexx
Created January 25, 2019 11:47
Show Gist options
  • Save minlexx/7bd176cab1776b36aa77231fabfda0e8 to your computer and use it in GitHub Desktop.
Save minlexx/7bd176cab1776b36aa77231fabfda0e8 to your computer and use it in GitHub Desktop.
Binary patcher for linux Qt builds to relocate hard-coded paths to library install location
#!/bin/sh
if [ x"$VERBOSE" = x"1" ]; then
set -x
fi
SCRIPT=$(readlink -f $0)
SCRIPTPATH=$(dirname $SCRIPT)
cd $SCRIPTPATH/..
TMP_FILE=/tmp/qt_new_path
if [ x"$1" = "x" ]; then
QT_PREFIX=`pwd`
else
QT_PREFIX="$1"
fi
echo -n "$QT_PREFIX" > $TMP_FILE
dd if=/dev/zero of=$TMP_FILE bs=128 count=1 oflag=append conv=notrunc status=none
MARKERS="qt_prfxpath qt_epfxpath qt_hpfxpath"
FILES="bin/qmake lib/libQt5Core.so"
for BIN_FILE in $FILES; do
OFFSETS=""
for keyword in $MARKERS; do
OFFSET=$(strings -t d $BIN_FILE |grep $keyword|cut -d ' ' -f 1)
if [ x"$OFFSET" = "x" ]; then
continue
fi
OFFSET=$(($OFFSET+12))
#echo "New offset:" $OFFSET
OFFSETS="$OFFSETS $OFFSET"
done
for OFFSET in $OFFSETS; do
echo "Patch file $BIN_FILE at offset $OFFSET"
dd if=$TMP_FILE bs=1 of=$BIN_FILE seek=$OFFSET conv=notrunc status=none
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment