Skip to content

Commit

Permalink
winetricks_get_file_arch: try workaround for wrapper scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jre-wine committed Feb 18, 2024
1 parent 95693b0 commit dbaca9e
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/winetricks
Original file line number Diff line number Diff line change
Expand Up @@ -1078,14 +1078,58 @@ winetricks_get_file_arch()
*) w_die "Unknown file arch: ${_W_lipo_output}" ;;
esac
else
# Assume ELF binaries for everything else
# Assume ELF binaries for everything else (or try workaround for some specific scripts)
_W_ob_output="$(od -An -t x1 -j 0x12 -N 1 "${_W_file}" | tr -d "[:space:]")"
case "${_W_ob_output}" in
"3e") _W_file_arch="x86_64" ;;
"03"|"06") _W_file_arch="i386" ;;
"b7") _W_file_arch="aarch64" ;;
"28") _W_file_arch="aarch32" ;;
*) w_die "Unknown file arch: ${_W_ob_output}";;
*) # wineserver and wine might be wrapper scripts, their binaries might be in Wine's bindir.
# Since wineboot often is a link next to wineserver (whose path we already know) pointing to
# wineapploader in Wine's bindir, we can use this to figure out Wine's bindir.
WINEBOOT_BIN="$(echo "${WINESERVER_BIN}"|sed 's,wineserver,wineboot,')"

if [ -n "${READLINK_F}" ]; then
true
elif [ "$(uname -s)" = "Darwin" ]; then
# readlink exists on MacOS, but does not support "-f" on MacOS < 12.3
# Use perl instead
READLINK_F="perl -MCwd=abs_path -le 'print abs_path readlink(shift);'"
else
READLINK_F="readlink -f"
fi

if [ "$1" = "${WINESERVER_BIN}" ]; then
# wineserver in PATH might be a script calling a binary in Wine's bindir.
if [ -x "${WINEBOOT_BIN}" ]; then
WINE_BINDIR="$(dirname "$(${READLINK_F} "${WINEBOOT_BIN}" 2>/dev/null)" 2>/dev/null)"
# wineserver in Wine's bindir might be a script calling wineserver64 preferably over wineserver32 (Debian).
# Try these before testing wineserver itself
if [ -x "${WINE_BINDIR}/wineserver64" ]; then
_W_ob_output="$(od -An -t x1 -j 0x12 -N 1 "${WINE_BINDIR}/wineserver64" | tr -d "[:space:]")"
elif [ -x "${WINE_BINDIR}/wineserver32" ]; then
_W_ob_output="$(od -An -t x1 -j 0x12 -N 1 "${WINE_BINDIR}/wineserver32" | tr -d "[:space:]")"
elif [ -x "${WINE_BINDIR}/wineserver" ]; then
_W_ob_output="$(od -An -t x1 -j 0x12 -N 1 "${WINE_BINDIR}/wineserver" | tr -d "[:space:]")"
fi
fi
elif [ "$1" = "${WINE_BIN}" ]; then
# wine in PATH might be a script calling a binary in Wine's bindir.
if [ -x "${WINEBOOT_BIN}" ]; then
WINE_BINDIR="$(dirname "$(${READLINK_F} "${WINEBOOT_BIN}" 2>/dev/null)" 2>/dev/null)"
if [ -x "${WINE_BINDIR}/wine" ]; then
_W_ob_output="$(od -An -t x1 -j 0x12 -N 1 "${WINE_BINDIR}/wine" | tr -d "[:space:]")"
fi
fi
fi
case "${_W_ob_output}" in
"3e") _W_file_arch="x86_64" ;;
"03"|"06") _W_file_arch="i386" ;;
"b7") _W_file_arch="aarch64" ;;
"28") _W_file_arch="aarch32" ;;
*) w_die "Unknown file arch: ${_W_ob_output}" ;;
esac
esac
fi

Expand Down

0 comments on commit dbaca9e

Please sign in to comment.