-->

在Mac OS可执行文件的打印rpath的(Print rpath of an executable

2019-06-18 06:19发布

我想改变使用可执行的rpath的 install_name_tool ,但我想不通的rpath的就是现在。 install_name_tool既需要旧的和新的rpath的的对命令行给出。 什么命令我可以用它来打印在MacOS下的可执行文件的rpath的

Answer 1:

首先,明白,可执行不包含单rpath条目,但一个或多个条目的数组。

其次,你可以用otool列出图像的rpath的条目。 使用otool -l ,你会得到输出像下面,在最后这都是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)

认准LC_RPATH命令,并记下的路径path条目。



Answer 2:

我目前正在写几个猛砸-3脚本处理dyld的,这一次回答了这个问题,所以我将它张贴供参考:

#! /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

# ######################################################################### #

'希望能帮助到你 ;-)

注:有谁知道一些的Bash-3的技巧,可以为这个脚本有用吗?



Answer 3:

我发现我可以使用打印在MacOS共享库的安装名

otool -D mylib

此外,我可以不直接引用通过将设置安装名老安装名称-id标志install_name_tool

install_name_tool -id @rpath/my/path mylib


Answer 4:

您可以使用otool -l myexecutable ,但这打印了很多不必要的信息,如果你有兴趣只在rpath中 S的名单。

您可以滤波器的输出otool -l通过向相关rpath的条目

otool -l myexecutable | grep RPATH -A2


Answer 5:

我只是用otool命令

otool -l <my executable>

它打印出rpath的领域。 无需任何长的脚本。



文章来源: Print rpath of an executable on macOS