Op hierdie bladsy kan jy vind hoe om 'n app te skep om arbitrêre opdragte van binne die standaard macOS sandbox te begin:
Compileer die aansoek:
main.m
#include <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
while (true) {
char input[512];
printf("Enter command to run (or 'exit' to quit): ");
if (fgets(input, sizeof(input), stdin) == NULL) {
break;
}
// Remove newline character
size_t len = strlen(input);
if (len > 0 && input[len - 1] == '\n') {
input[len - 1] = '\0';
}
if (strcmp(input, "exit") == 0) {
break;
}
system(input);
}
}
return 0;
}
Kompileer dit deur te loop: clang -framework Foundation -o SandboxedShellApp main.m
Bou die .app bundel
mkdir-pSandboxedShellApp.app/Contents/MacOSmvSandboxedShellAppSandboxedShellApp.app/Contents/MacOS/cat<<EOF>SandboxedShellApp.app/Contents/Info.plist<?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>CFBundleIdentifier</key><string>com.example.SandboxedShellApp</string><key>CFBundleName</key><string>SandboxedShellApp</string><key>CFBundleVersion</key><string>1.0</string><key>CFBundleExecutable</key><string>SandboxedShellApp</string></dict></plist>EOF
Definieer die regte
cat<<EOF>entitlements.plist<?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/></dict></plist>EOF
cat<<EOF>entitlements.plist<?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.downloads.read-write</key><true/></dict></plist>EOF
Teken die app (jy moet 'n sertifikaat in die sleutelkettie skep)
codesign--entitlementsentitlements.plist-s"YourIdentity"SandboxedShellApp.app./SandboxedShellApp.app/Contents/MacOS/SandboxedShellApp# An d in case you need this in the futurecodesign--remove-signatureSandboxedShellApp.app