将 dylib 插入到现有的bundle/可执行文件中



我有一个现有的捆绑包/可执行文件,我需要在其中添加新的dylib。

我已经尝试过的方法:

  • 将dylib复制到bundle中并在info.plist中设置dyld_insert_libraries以加载库。这适用于一个问题,即我将无法控制应用程序/捆绑包(或库,如果在捆绑包外部)的位置,并且相对路径(例如@executable_path)不能在 info.plist 中使用。

  • 使用install_name_tool(-add_rpath、-id 等)向库添加新路径。这似乎行不通,除非有一条可以改变的道路。(库的名称/安装位置正确,并经过多次检查)。

这个问题是否有任何进一步的解决方案,甚至对我已经尝试过的解决方案(上面)进行修改?

我做了一个可以做到这一点的工具,叫做insert_dylib:https://github.com/Tyilo/insert_dylib

以下是使用信息:

Usage: insert_dylib [--inplace] [--weak] dylib_path binary_path [new_path]

以及如何使用它:

 $ insert_dylib /usr/lib/libfoo.dylib test
 The provided dylib path doesn't exist. Continue anyway? [y/n] y
 Added LC_LOAD_DYLIB command to test_patched
 $ diff -u <(otool -hl test) <(otool -hl test_patched)
 ...
您还可以

设置环境变量DYLD_INSERT_LIBRARIES以指向执行二进制文件时要注入的库。有关详细信息,请参阅 https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man1/dyld.1.html。

相关内容