LoginSignup
0
2

More than 3 years have passed since last update.

コマンドラインツールのサンドボックス化

Posted at

はじめに

Xcodeで自作したコマンドラインツールをサンドボックス化する方法についてのメモ記事です。

すること

  1. Info.plistファイルを準備してプロジェクトに読み込む(他のプロジェクトで作成されたファイルを読み込んで編集すると楽)。
  2. TargetのGeneralタブのIdentityのchoose Info.plist File..で(1)のファイルを選ぶ。
  3. CapabilitiesでApp Sandboxを追加。適宜設定を変更。
  4. TargetのBuidSettingsのPackagingでCreate Info.plist Section in BinaryをYESに変更。 image.png

これでビルドする。

サンドボックスの設定を確認

codesign -d --entitlements :- 
/Users/yoho/Library/Developer/Xcode/DerivedData/commandLineToolTest-fiajznkvauagbcaqcvfqjyprqven/Build/Products/Release/commandLineToolTest

実行結果:


Executable=/Users/yoho/Library/Developer/Xcode/DerivedData/commandLineToolTest-fiajznkvauagbcaqcvfqjyprqven/Build/Products/Release/commandLineToolTest
<?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.app-sandbox</key>
    <true/>
    <key>com.apple.security.files.user-selected.read-write</key>
    <true/>
    <key>com.apple.security.get-task-allow</key>
    <true/>
</dict>
</plist>

関連するエラー

Info.plist Section in BinaryをYESにしないと、ビルド自体は成功するが、Xcodeで以下のエラーが出てデバッグなどができない。

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

この時作成されたバイナリをターミナルで実行すると、

Illegal instruction: 4

と出力される。

おわりに

App Storeで色々公開しようと思って準備しているが、Sandbox化で手こずっている。なかなか関連する情報が得られず、記事にしておくことにした。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2