如何在用C语言编写的命令行程序中添加授权

3

我正在使用C语言编写一个命令行程序,通常的方式是在命令行上使用gcc进行编译等。我希望我的程序能够使用Hypervisor.framework。为了做到这一点,它需要com.apple.security.hypervisor特权。我该如何将此特权添加到已编译的二进制文件中,以使其能够运行?

2个回答

2

很抱歉要挖掘一个旧的帖子,另一种方法是将其链接到:

zpool_LDFLAGS  = -sectcreate __TEXT __info_plist yourcmd-Info.plist
zpool_LDFLAGS += -sectcreate __TEXT __entitlements yourcmd-entitlements.plist

2
您需要类似这样的内容(尽管您需要为您的授权使用不同的):https://glyph.twistedmatrix.com/2018/01/shipping-pygame-mac-app.html。请参考上述链接获取更多信息。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
</dict>
</plist>

将内容保存在entitleme.plist文件中,然后运行以下命令:

codesign --sign - \
    --entitlements entitleme.plist \
    --deep <your-binary> \
    --force

关于代码签名的Homebrew问题的其他参考:https://github.com/Homebrew/brew/issues/9082


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接