Search code examples
iphoneiosobjective-cjailbreak

What entitlements/permissions does the device pin controller class require?


My iphone app is jailbroken and I don't care if my app is rejected by the app store.

I wish to use the private API DevicePINController in my program.

I recently found the private API called DevicePINController, however it doesn't work properly. The app runs and all but its methods do nothing. Its BOOL methods always return false. Set methods don't do anything.

Does anyone know what entitlements permissions the device pin controller requires?

EDIT:CODE

    id away = [[objc_getClass("DevicePINController") alloc]init];

    NSLog( [away simplePIN] ? @"YES":@"NO" );
    NSLog( [away _isBlocked] ? @"YES":@"NO" );
    NSLog( [away _attemptValidationWithPIN:@"1234"] ? @"YES":@"NO" );

    NSLog(@"%d",[away _unblockTime] );
    NSLog(@"%@",[away blockedStateKey] );
    NSLog(@"%@",[away blockTimeIntervalKey] );
    NSLog(@"%@",[away failedAttemptsKey] );
    NSLog(@"%d",[away pinLength] );
    NSLog(@"%@",[away stringsBundle] );

    NSLog(@"%@",[away stringsTable]);

Every method call returns the wrong answer. Some only return null. Bool always return NO.


Solution

  • So, the first problem is that you have a nil object. In Objective-C, sending a message to a nil object will just do nothing. If the method is supposed to return a BOOL, the default value of BOOL is NO, so you'll get back a bunch of NOs if away is nil.

    To answer your follow-up question (after you tested that you did actually have a nil value) ... you do need to make sure your app opens the library where the DevicePINController is defined. Otherwise, it won't know what that class is, and won't be able to instantiate it. So, objc_getClass will return you the nil object.

    For that class, it is defined in Preferences.framework, found at

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/PrivateFrameworks/Preferences.framework
    

    (obviously, adjust for your installation directory and/or SDK version)

    You can either add it to your project in Xcode, by going to the target settings -> Build Phases -> Link Binary With Libraries and adding it. You'll of course have to navigate to the directory above, since it's a Private Framework, and won't show up in the initial popup list.

    Or, you can use code to dynamically load the library:

    #import <objc/runtime.h>
    #include <dlfcn.h>
    

    and

    void* libHandle = dlopen("/System/Library/PrivateFrameworks/Preferences.framework/Preferences", RTLD_LAZY);
    
    id away = [[objc_getClass("DevicePINController") alloc] init];
    if (away == nil) {
        NSLog(@"object is nil");
    } else {
        if ([away respondsToSelector: @selector(simplePIN)]) {
            NSLog(@"object responds to selector!");
        }
    }
    
    close(libHandle);
    

    I tested this on iOS 6.1 (jailbroken) and it works.

    By the way, please change your PIN to something other than 1234. I have the same combination on my luggage ;)