简体   繁体   中英

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

I'm just a newbie in Mac OS X programming so please, be patient with me. I'm trying to make a cocoa app which the goal is to read some infos from Info.plist kext's file, which the full path is /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

it works but with my project Info.plist file, and it's not what I want.

So my question is how can I read Info.plist from NVDAResman.kext?

Thank you in advance

PS: I'm using Xcode 7.1 beta (7B60)

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

Please mind that any search using "[NSBundle mainBundle]" will results within your application package (under .app folder structure). Also if you plan to sandbox your application the above code will not work and there is no solution to make it work with Sandboxing (security of OS X platform).

here's how I did it (thanks to xhruso00)

m.

// 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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM