Skip to content

Instantly share code, notes, and snippets.

@easonoutlook
Created July 28, 2014 09:08
Show Gist options
  • Save easonoutlook/4374a3ade9aca409d437 to your computer and use it in GitHub Desktop.
Save easonoutlook/4374a3ade9aca409d437 to your computer and use it in GitHub Desktop.
iOS8 MobileInstallationLookup work for jailbreak device.
Code from Clutch, Thanks. https://github.com/KJCracks/Clutch
#define mobileinstallationcache @"/private/var/mobile/Library/Caches/com.apple.mobile.installation.plist"
typedef NSDictionary* (*MobileInstallationLookup)(NSDictionary *options);
NSArray * get_application_list(BOOL sort) {
NSMutableArray *returnArray = [[[NSMutableArray alloc] init] autorelease];
NSDictionary* options = @{@"ApplicationType":@"User",
@"ReturnAttributes":@[@"CFBundleShortVersionString",
@"CFBundleVersion",
@"Path",
@"CFBundleDisplayName",
@"CFBundleExecutable",
@"ApplicationSINF",
@"MinimumOSVersion"]};
NSDictionary *installedApps;
MobileInstallationLookup mobileInstallationLookup = dlsym(dlopen(0,RTLD_LAZY),"MobileInstallationLookup");
if (mobileInstallationLookup)
installedApps = mobileInstallationLookup(options); //convenient way
else
{
// iOS 8 workaround
NSMutableDictionary *iapps = [NSMutableDictionary new];
NSDictionary *userApps = [NSDictionary dictionaryWithContentsOfFile:mobileinstallationcache][@"User"];
for (NSString *bID in userApps.allKeys)
{
NSDictionary *app = userApps[bID];
NSMutableDictionary *tmp = [NSMutableDictionary new];
for (NSString *attribute in options[@"ReturnAttributes"])
{
if (app[attribute])
tmp[attribute] = app[attribute];
}
iapps[bID] = tmp;
}
installedApps = [iapps copy];
}
for (NSString *bundleID in [installedApps allKeys])
{
NSDictionary *appI=[installedApps objectForKey:bundleID];
NSString *appPath=[[appI objectForKey:@"Path"]stringByAppendingString:@"/"];
NSString *container=[[appPath stringByDeletingLastPathComponent]stringByAppendingString:@"/"];
NSString *displayName=[appI objectForKey:@"CFBundleDisplayName"];
NSString *executableName = [appI objectForKey:@"CFBundleExecutable"];
NSString *minimumOSVersion = [appI objectForKey:@"MinimumOSVersion"];
minimumOSVersion = minimumOSVersion!=nil ? minimumOSVersion : @"1.0";
if (displayName == nil)
{
displayName=[[appPath lastPathComponent]stringByReplacingOccurrencesOfString:@".app" withString:@""];
}
NSString *version=@"";
if ([[appI allKeys]containsObject:@"CFBundleShortVersionString"])
{
version=[appI objectForKey:@"CFBundleShortVersionString"];
}
else
{
version=[appI objectForKey:@"CFBundleVersion"];
}
NSData *SINF = appI[@"ApplicationSINF"];
if (SINF)
{
Application *app =[[Application alloc]initWithAppInfo:@{@"ApplicationContainer":container,
@"ApplicationDirectory":appPath,
@"ApplicationDisplayName":displayName,
@"ApplicationName":[[appPath lastPathComponent]stringByReplacingOccurrencesOfString:@".app" withString:@""],
@"RealUniqueID":[container lastPathComponent],
@"ApplicationBasename":[appPath lastPathComponent],
@"ApplicationVersion":version,
@"ApplicationBundleID":bundleID,
//@"ApplicationSINF":SINF,
@"ApplicationExecutableName":executableName,
@"MinimumOSVersion":minimumOSVersion}];
[returnArray addObject:app];
[app release];
}
}
if ([returnArray count] == 0)
{
return nil;
}
if (sort)
{
NSSortDescriptor *sorter = [[NSSortDescriptor alloc]
initWithKey:@"applicationName"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)];
NSArray *sortDescriptors = [NSArray arrayWithObject: sorter];
[returnArray sortUsingDescriptors:sortDescriptors];
}
//caching is good
NSMutableArray *cacheArray = [NSMutableArray new];
for (Application *app in returnArray)
{
[cacheArray addObject:[app dictionaryRepresentation]];
}
if (cacheArray.count > 0)
{
[cacheArray writeToFile:applistCachePath atomically:YES];
}
[cacheArray release];
return (NSArray *) returnArray;
}
@app111
Copy link

app111 commented Aug 25, 2014

is Jbreak!

@jiang-yi-siphty
Copy link

How to use this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment