我制作了一个简单的Unix工具,可以从Shell启动主Cocoa应用程序。
我需要对其进行沙箱化,但运行时它崩溃并显示错误“Illegal instruction: 4”,在console.app上,我可以看到以下错误消息:
Sandbox创建失败:容器对象初始化失败:NIL 没有visdiff的错误描述的容器信息对象
该文件已经正确地使用codesign签名。
我阅读了这篇文章Mac OS app, sandbox with command line tool?,但没有帮助。
我制作了一个简单的Unix工具,可以从Shell启动主Cocoa应用程序。
我需要对其进行沙箱化,但运行时它崩溃并显示错误“Illegal instruction: 4”,在console.app上,我可以看到以下错误消息:
Sandbox创建失败:容器对象初始化失败:NIL 没有visdiff的错误描述的容器信息对象
该文件已经正确地使用codesign签名。
我阅读了这篇文章Mac OS app, sandbox with command line tool?,但没有帮助。
我曾经遇到过这个问题,当我添加了一个内嵌的 Info.plist 时,问题消失了。
尝试使用以下clang标志(假设你的构建目录中有 info.plist
文件):
-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker info.plist
这个控制台应用是直接从控制台启动的还是从主沙盒应用程序调用的?当我尝试对一些二进制文件进行沙盒化时,我遇到了类似的错误,但我只能通过使用以下权限来使其正常工作:
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
</dict>
虽然 @Nick Moore 的答案完全正确,但在今天的 Xcode 中有一个选项可用于此,在 Packaging - Create Info.plist Section in Binary (CREATE_INFOPLIST_SECTION_IN_BINARY) 下。只需将 thue 设置为 Yes。
看起来,如果你用 com.apple.security.inherit 签名一个可执行文件,只有已经被沙盒化的应用程序才能调用它。因此,在运行 codesign 后,你不能再从命令行调用它。
现在在developer.apple.com
上有一篇官方文章,标题为“将命令行工具嵌入沙盒应用程序中”。
https://developer.apple.com/documentation/xcode/embedding-a-helper-tool-in-a-sandboxed-app
在构建命令行工具之后,以下是相关步骤(摘自文章)。
% /usr/libexec/PlistBuddy -c "Add :com.apple.security.app-sandbox bool true" "ToolC.entitlements"
文件不存在,将创建:ToolC.entitlements
% /usr/libexec/PlistBuddy -c "Add :com.apple.security.inherit bool true" ToolC.entitlements
% cat ToolC.entitlements
…
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
</dict>
</plist>
% codesign -s - -i com.example.apple-samplecode.AppWithTool.ToolC -o runtime --entitlements ToolC.entitlements -f ToolC
...
在应用程序目标编辑器的“构建阶段”选项卡中,将 ToolC 添加到“嵌入式助手工具”构建阶段,确保勾选“复制时代码签名”。
developer.apple.com
文章:https://developer.apple.com/documentation/xcode/embedding-a-helper-tool-in-a-sandboxed-app - nishanthshanmugham