Imprimir rpath del ejecutable en OSX
Quiero cambiar el rpath de un ejecutable usando install_name_tool
, pero no puedo averiguar cuál es el rpath en este momento. install_name_tool
requiere que tanto el rpath antiguo como el nuevo sean dados en la línea de órdenes. ¿Qué comando puedo usar para imprimir el rpath de un ejecutable bajo OSX?
4 answers
En primer lugar, entienda que un ejecutable no contiene una sola entrada rpath
, sino una matriz de una o más entradas.
En segundo lugar, puede usar otool
para listar las entradas rpath
de una imagen. Usando otool -l
, obtendrás una salida como la siguiente, al final de la cual están las entradas rpath
:
Load command 34
cmd LC_LOAD_DYLIB
cmdsize 88
name /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (offset 24)
time stamp 2 Wed Dec 31 19:00:02 1969
current version 1038.32.0
compatibility version 45.0.0
Load command 35
cmd LC_RPATH
cmdsize 40
path @loader_path/../Frameworks (offset 12)
Busque los comandos LC_RPATH
y anote la ruta bajo la entrada path
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-20 22:56:18
Actualmente estoy escribiendo varios scripts Bash-3 para procesar DYLD y este responde a la pregunta, así que lo publico como referencia:
#! /bin/bash
# ######################################################################### #
if [ ${#} -eq 0 ]
then
echo "
Usage: ${0##*/} FILE...
List rpaths in FILEs
"
exit 0
fi
# ######################################################################### #
shopt -s extglob
# ######################################################################### #
for file in "${@}"
do
if [ ! -r "${file}" ]
then
echo "${file}: no such file" 1>&2
continue
fi
if ! [[ "$(/usr/bin/file "${file}")" =~ ^${file}:\ *Mach-O\ .*$ ]]
then
echo "${file}: is not an object file" 1>&2
continue
fi
if [ ${#} -gt 1 ]
then
echo "${file}:"
fi
IFS_save="${IFS}"
IFS=$'\n'
_next_path_is_rpath=
while read line
do
case "${line}" in
*(\ )cmd\ LC_RPATH)
_next_path_is_rpath=yes
;;
*(\ )path\ *\ \(offset\ +([0-9])\))
if [ -z "${_next_path_is_rpath}" ]
then
continue
fi
line="${line#* path }"
line="${line% (offset *}"
if [ ${#} -gt 1 ]
then
line=$'\t'"${line}"
fi
echo "${line}"
_next_path_is_rpath=
;;
esac
done < <(/usr/bin/otool -l "${file}")
IFS="${IFS_save}"
done
# ######################################################################### #
' espero que ayude ; -)
NB: ¿Alguien conoce algunos trucos Bash-3 que pueden ser útiles para este script ?
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-20 14:50:12
Encontré que puedo imprimir el nombre de instalación de una biblioteca compartida en osx usando otool-D.
Además, puedo establecer el nombre de instalación directamente sin referencia al nombre de instalación anterior pasando la bandera -id a install_name_tool: install_name_tool-id " @ rpath/my / path mylib
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-28 07:46:55
Solo uso el comando otool
otool -L <my executable>
Imprime el campo rpath. No hay necesidad de guiones largos.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-26 17:41:28