Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A command line tool to parse .mobileprovision file
//
// © 2008 Eugene Solodovnykov
// http://idevblog.info/mobileprovision-files-structure-and-reading/
//
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
if (argc < 3) {
printf("Usage: mpParse -f <fileName> [-o <option>]\n");
return 1001;
}
//get arguments
NSUserDefaults *arguments = [NSUserDefaults standardUserDefaults];
NSString *fileName = [arguments stringForKey:@"f"];
NSString *propertyName = [arguments stringForKey:@"o"];
if (!fileName) {
fileName = [arguments stringForKey:@"-file"];
if (!fileName) {
return 1001;
}
}
if (!propertyName) {
propertyName = [arguments stringForKey:@"-option"];
if (!propertyName) {
propertyName = @"type";
}
}
//get plist XML
NSString *fileString = [[NSString alloc] initWithContentsOfFile:fileName];
NSScanner *scanner = [[NSScanner alloc] initWithString:fileString];
[fileString release];
if ([scanner scanUpToString:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" intoString:NULL]) {
NSString *plistString;
if ([scanner scanUpToString:@"</plist>" intoString:&plistString]) {
[scanner release];
NSDictionary *plist = [[plistString stringByAppendingString:@"</plist>"] propertyList];
// get profile type
// possible types:
// ad-hoc
// appstore
// debug
if ([propertyName isEqualToString:@"type"]) {
if ([plist valueForKeyPath:@"ProvisionedDevices"]) {
if ([[plist valueForKeyPath:@"Entitlements.get-task-allow"] boolValue]) {
printf("debug\n");
} else {
printf("ad-hoc\n");
}
} else {
printf("appstore\n");
}
} else
// get the UUID of the profile
if ([propertyName isEqualToString:@"uuid"]) {
printf("%s\n", [[plist valueForKeyPath:@"UUID"] cStringUsingEncoding:NSUTF8StringEncoding]);
} else
// get the supported devices list
if ([propertyName isEqualToString:@"devices"]) {
NSArray *devices = [plist valueForKeyPath:@"ProvisionedDevices"];
if (devices) {
for (NSString *deviceId in devices) {
printf("%s\n", [deviceId cStringUsingEncoding:NSUTF8StringEncoding]);
}
}
}
} else {
[scanner release];
return 1002;
}
} else {
[scanner release];
return 1002;
}
[pool drain];
return 0;
}
@dwelch2344

This comment has been minimized.

Copy link

dwelch2344 commented Oct 10, 2013

Looks like the blog related to this file is down, so I threw together a simple project and compiled it. You can download the binary at https://github.com/dwelch2344/mpParse/blob/master/build/mpParse (though GitHub adds .txt to the end of the file, so you'll probably want to strip that out)

@michaelhogg

This comment has been minimized.

Copy link

michaelhogg commented May 23, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.