|
|
@@ -0,0 +1,81 @@ |
|
|
|
#include <stdio.h> |
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
#import <Foundation/Foundation.h> |
|
|
|
|
|
|
|
#define PROG_NAME "lockpick" |
|
|
|
|
|
|
|
@interface MCPasscodeManager : NSObject |
|
|
|
|
|
|
|
+ (MCPasscodeManager *)sharedManager; |
|
|
|
|
|
|
|
+ (BOOL)isDeviceUnlocked; |
|
|
|
+ (BOOL)isDeviceLocked; |
|
|
|
- (BOOL)isPasscodeSet; |
|
|
|
|
|
|
|
- (void)lockDevice; |
|
|
|
- (BOOL)unlockDeviceWithPasscode:(id)passcode outError:(out NSError * _Nullable *)error; |
|
|
|
|
|
|
|
@end |
|
|
|
|
|
|
|
@interface SBLockdownManager : NSObject |
|
|
|
|
|
|
|
+ (SBLockdownManager *)sharedInstance; |
|
|
|
|
|
|
|
@end |
|
|
|
|
|
|
|
void print_usage() { |
|
|
|
printf("Usage: %s lock\n", PROG_NAME); |
|
|
|
printf(" %s unlock [passcode]\n", PROG_NAME); |
|
|
|
} |
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
if(argc == 1) { |
|
|
|
print_usage(); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
if(strcmp(argv[1], "lock") == 0) { |
|
|
|
if([MCPasscodeManager isDeviceUnlocked]) { |
|
|
|
[[MCPasscodeManager sharedManager] lockDevice]; |
|
|
|
} else { |
|
|
|
fprintf(stderr, "Device is already locked.\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
else if(strcmp(argv[1], "unlock") == 0) { |
|
|
|
NSError *error = nil; |
|
|
|
|
|
|
|
if(![MCPasscodeManager isDeviceUnlocked]) { |
|
|
|
if(![MCPasscodeManager sharedManager].isPasscodeSet) { |
|
|
|
[[MCPasscodeManager sharedManager] unlockDeviceWithPasscode:nil outError:&error]; |
|
|
|
if(error) { |
|
|
|
fprintf(stderr, "Couldn't unlock device.\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
else if(argc < 3) { |
|
|
|
fprintf(stderr, "This device requires a passcode.\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
NSString *givenPasscode = @(argv[2]); |
|
|
|
|
|
|
|
[[MCPasscodeManager sharedManager] unlockDeviceWithPasscode:givenPasscode outError:&error]; |
|
|
|
if(error) { |
|
|
|
if(error.code == 5011) { |
|
|
|
fprintf(stderr, "Wrong passcode.\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
fprintf(stderr, "Unknown error code.\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} else { |
|
|
|
fprintf(stderr, "Device is already unlocked.\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |