如何从 /S/L/E kext info.plist 文件中读取信息?

How to read infos from /S/L/E kext info.plist file?

我只是 Mac OS X 编程的新手所以请耐心等待。我正在尝试制作一个 cocoa 应用程序,其目标是从 Info.plist kext 文件中读取一些信息,完整路径是 /System/Library/Extensions/NVDAResman.kext/Contents/Info.plist

h.

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (weak) IBOutlet NSTextField *nvidiaNameTextField;

@end

m.

#import "AppDelegate.h"

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    [self setnvidiaNameTextField];
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}

// This will allow the application to quit instead of just closing the window
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
    return YES;
}

// Find NVIDIA Kernel Extension Name
-(void)setnvidiaNameTextField
{
    NSString *nvidiaNameTextField = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
    self.nvidiaNameTextField.stringValue = [NSString stringWithFormat:@"%@", nvidiaNameTextField];
}

@end

它可以工作,但是对于我的项目 Info.plist 文件,这不是我想要的。

所以我的问题是如何从 NVDAResman.kext 读取 Info.plist?

提前致谢

PS:我正在使用 Xcode 7.1 测试版 (7B60)

NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/Extensions/NVDAResman.kext/Contents/Info.plist"];

请注意,任何使用“[NSBundle mainBundle]”的搜索都会在您的应用程序包中(在 .app 文件夹结构下)产生结果。此外,如果您计划对您的应用程序进行沙盒处理,上述代码将无法正常工作,并且没有解决方案可以使其与沙盒处理(OS X 平台的安全性)一起工作。

这是我的做法(感谢 xhruso00)

米.

// Find NVIDIA Kernel Extension Name
-(void)setnvidiaVersionTextField
{
    NSDictionary *infoDict = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/Extensions/NVDAResman.kext/Contents/Info.plist"];
    NSString* nvidiaVersionTextField = [infoDict objectForKey:@"CFBundleName"];
    self.nvidiaVersionTextField.stringValue = [NSString stringWithFormat:@"%@", nvidiaVersionTextField];
}