Загрузка данных


#!/bin/sh
# This script is used for patching elf binaries. It can change either
# rpath or loader.

print_usage()
{
	echo "Usage: $0 platform <loader|rpath> newvalue file1 [file2...]"
}

if test $# -lt 4; then
	print_usage
	exit 1
fi

PLATFORM="$1"; shift
ELF_FIELD="$1"; shift
NEW_VALUE="$1"; shift
IPLIR_ROOT=$(readlink -f ${0%/*}/..)
PATCHELF="patchelf"
FIXRPATH=change_rpath_chrpath

change_rpath_chrpath()
{
	file $1 | grep "dynamically linked" > /dev/null
	if [ "$?" -ne 0 ] ; then
	       echo "File $1 isn't dynamic linked - don't change rpath"
	       return 0
	fi

	if test "x${1%.so*}" = "x${1}"; then
		chrpath -r "$NEW_VALUE" "$1"
	else
		chrpath -k -r "$NEW_VALUE" "$1"
	fi
}

change_rpath_patchelf()
{
	echo "Running $PATCHELF" --force-rpath --set-rpath "$NEW_VALUE" "$1"
	"$PATCHELF" --set-rpath "$NEW_VALUE" --force-rpath "$1"
}

change_loader_patchelf()
{
	echo "Running $PATCHELF" --set-interpreter "$NEW_VALUE" "$1"
	"$PATCHELF" --set-interpreter "$NEW_VALUE" "$1"
}

if ! test -x "$PATCHELF"; then
  echo "$0: patchelf is not available (expected: $PATCHELF)"
  FIXRPATH=change_rpath_patchelf
elif ! type chrpath >/dev/null; then
  echo "$0: chrpath is not available"
  FIXRPATH=change_rpath_chrpath
else
  exit 1
fi

case $ELF_FIELD in
rpath)
	for file in "$@"; do
		$FIXRPATH "$file"
	done
	;;
loader)
	for file in "$@"; do
		change_loader_patchelf "$file"
	done
	;;
*)
	print_usage
	exit 1
	;;
esac