2

我正在尝试从在沙箱中运行的 ObjectiveC 应用程序运行 iTunes。Apple 文档提到“使用 NSTask 类创建的子进程继承了父应用程序的沙箱”。结果是运行iTunes时,弹出一些权限错误,关闭iTunes。使用 NSWorkspace 方法运行它时,它不会崩溃,并且似乎在任何沙箱之外运行。这是否意味着我有权在启动时使用 DYLD_INSERT_LIBRARIES 插入一些动态库?这是一些代码:

NSString* appPath = @"/Applications/iTunes.app";
// Get application URL
NSBundle *targetBundle = [NSBundle bundleWithPath:appPath];
NSURL *applicationURL = [targetBundle executableURL];

NSString* libPath = [NSHomeDirectory() stringByAppendingPathComponent:@"myLib.dylib"];
// Environment setup
NSDictionary *config = nil;
NSDictionary *env = [NSDictionary dictionaryWithObject:libPath forKey:@"DYLD_INSERT_LIBRARIES"];

NSNumber *arch = [NSNumber numberWithInt:(int)NSBundleExecutableArchitectureI386];
config = [[NSDictionary alloc] initWithObjectsAndKeys:env, NSWorkspaceLaunchConfigurationEnvironment, 
                                                      arch, NSWorkspaceLaunchConfigurationArchitecture, nil];

// Launch application
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:applicationURL
                          options:0 
                    configuration:config 
                            error:nil];

[config release];

当上面的代码在沙盒中运行时,iTunes 会在没有任何库的情况下启动。有什么建议吗?

谢谢,弗拉德。

4

0 回答 0