[Snippet] Reloading SB Apps

Discussion in 'iOS Development' started by gojohnnyboi, Oct 2, 2008.

  1. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Ok, so today i made gPower, and i was thinking it would be nice in a future release to implement an app reloader. now, the simple notification doesn't cut it anymore in 2.1. you must write to the cache and what not. i also didn't want to have to use Erica Sadun's binary, because 1 i dont want to have to depend on another file, and 2 its more fun to write my own

    Please Register or Log in to view images



    so here's a little snippet of code that i used to load all the applications, the right way according to firmware.

    EDIT: here, uploaded binary. View attachment applicationload.zip

    Code:
    #include <Foundation/Foundation.h>
    #include <notify.h>
    #include <objc/runtime.h>
    
    BOOL __verboseEnabled;
    
    @protocol IDPATCH
    - (id)currentDevice;
    @end
    
    
    int main(int argc, char *argv[]) {
    	NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    	
    	__verboseEnabled = FALSE;
    	
    	NSString* currentFW = (NSString *)[[(id<IDPATCH>)objc_getClass("UIDevice") currentDevice] systemVersion];
    	printf([[NSString stringWithFormat:@"Current Firmware Is: %@\n",currentFW] UTF8String]);
    	printf("Loading Applications...\n");
    	if(currentFW != nil) {
    		if([currentFW doubleValue] >= 2.1) {
    			goto checkverbose;
    		} else {
    			goto notification;
    		}
    	}
    	[currentFW release];
    	
    	checkverbose: {
    		if(argc > 1 && argv[1] != NULL) {
    			if([[NSString stringWithCString:argv[1]] isEqualToString:@"-v"]) {
    				__verboseEnabled = TRUE;
    				goto firmware21;
    			} else {
    				printf("(-v for verbose application list)\n");
    			}
    		} else {
    			printf("(-v for verbose application list)\n");
    		}
    	}
    	
    	firmware21: {
    	
    		NSMutableDictionary* appCache;
    		if(appCache = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Caches/com.apple.mobile.installation.plist"]) {
    			[appCache autorelease];
    		
    			NSFileManager* fileManager = [NSFileManager defaultManager];
    		
    			id systemApps = [appCache objectForKey:@"System"];
    			id appstoreApps = [appCache objectForKey:@"User"];
    			if(system == nil || appstoreApps == nil) {
    				return 0;
    			}
    		
    			[systemApps removeAllObjects];
    			[appstoreApps removeAllObjects];
    		
    			NSArray* allAppsInSystemAppsDirectory;
    			NSArray* allAppsInUserDirectory;
    			if(allAppsInSystemAppsDirectory = [fileManager directoryContentsAtPath:@"/Applications"]) {
    				NSString* appName;
    				for(appName in allAppsInSystemAppsDirectory) {
    					if([appName hasSuffix:@".app"]) {
    						NSString* appPath = [@"/Applications" stringByAppendingPathComponent:appName];
    						NSString* appPropertyList = [appPath stringByAppendingPathComponent:@"Info.plist"];
    					
    						if(__verboseEnabled) {
    							NSString *noExt = [[appPath lastPathComponent] substringToIndex:[[appPath lastPathComponent] length] - 4];
    							printf([[[NSString stringWithFormat:@"Loading Application: %@",noExt] stringByAppendingString:@"\n"] UTF8String]);
    						}
    					
    						NSMutableDictionary* appInfoDictionary;
    						if(appInfoDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:appPropertyList]) {
    							[appInfoDictionary autorelease];
    							[appInfoDictionary setObject:appPath forKey:@"Path"];
    							[appInfoDictionary setObject:@"System" forKey:@"ApplicationType"];
    						
    							if([systemApps objectForKey:[appInfoDictionary objectForKey:@"CFBundleIdentifier"]] != nil) {
    								[systemApps removeObjectForKey:[appInfoDictionary objectForKey:@"CFBundleIdentifier"]];
    							}
    							[systemApps setObject:appInfoDictionary forKey:[appInfoDictionary objectForKey:@"CFBundleIdentifier"]];
    						}
    					}
    				}
    			}
    			if(allAppsInUserDirectory = [fileManager directoryContentsAtPath:@"/var/mobile/Applications"]) {
    				NSString* appNames;
    				for(appNames in allAppsInUserDirectory) {
    					NSString* appHolder = [@"/var/mobile/Applications" stringByAppendingPathComponent:appNames];
    					NSArray* appContentsInCurrentFolder;
    					if(appContentsInCurrentFolder = [fileManager directoryContentsAtPath:appHolder]) {
    						NSString* appName;
    						for(appName in appContentsInCurrentFolder) {
    							if([appName hasSuffix:@".app"]) {
    								NSString* appPath = [appHolder stringByAppendingPathComponent:appName];
    								NSString* appPropertyList = [appPath stringByAppendingPathComponent:@"Info.plist"];
    							
    								if(__verboseEnabled) {
    									NSString *noExt = [[appPath lastPathComponent] substringToIndex:[[appPath lastPathComponent] length] - 4];
    									printf([[[NSString stringWithFormat:@"Loading Application: %@",noExt] stringByAppendingString:@"\n"] UTF8String]);
    								}
    						
    								NSMutableDictionary* appInfoDictionary;
    								if(appInfoDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:appPropertyList]) {
    									[appInfoDictionary autorelease];
    									[appInfoDictionary setObject:appPath forKey:@"Path"];
    									[appInfoDictionary setObject:@"User" forKey:@"ApplicationType"];
    							
    									if([appstoreApps objectForKey:[appInfoDictionary objectForKey:@"CFBundleIdentifier"]] != nil) {
    										[appstoreApps removeObjectForKey:[appInfoDictionary objectForKey:@"CFBundleIdentifier"]];
    									}
    									[appstoreApps setObject:appInfoDictionary forKey:[appInfoDictionary objectForKey:@"CFBundleIdentifier"]];
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    	[appCache writeToFile:@"/User/Library/Caches/com.apple.mobile.installation.plist" atomically:TRUE];
    	}
    	
    	notification: {
    		notify_post("com.apple.mobile.application_installed");
    	}
    	
    	printf("Done!\n");
    	
    	[pool release];
    	return 0;
    }
    it is to be improved tomorrow, but ya know, whatever.

    Please Register or Log in to view images



    Thanks to saurik for giving me some tips on handling the arrays and what not. he's a beast

    -John
  2. iMario

    iMario Well-Known Member

    Joined:
    May 11, 2008
    Messages:
    1,642
    Likes Received:
    153
    Device:
    iPhone 5S
    What does this do?
  3. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    it's so when it respring it displays new springboard icons by doing something to cache I cant realy explain it
  4. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Ehem, how would I execute this from my SDK-based app? I really need this binary to work and i don't know how to get it going..thanks
  5. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    use my released tool, "quickload". it is on cydia.

    you can just execute "quickload --reload-all" to load all the apps onto springboard.
  6. cacman93

    cacman93 Banned

    Joined:
    Jul 13, 2008
    Messages:
    1,061
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    OMG!!!!!!!! Johny, answer my damn pm, YOU NEED TO STOP MAKING NEW APPS AFTER NEW APPS AND ACTUALLY FINISH ONE. YOU KEEP MAKING THESE APPS THAT COULD BE AWESOME AND THEN LEAVE IT IN A BETA STATE, JUST FINISH THE ONE YOUR DOING AND THEN MOVE TO THE NEXT ONE.
  7. murphmanny

    murphmanny Banned

    Joined:
    Sep 19, 2007
    Messages:
    5,250
    Likes Received:
    3
    calm down now
    just because your cubs team is out doesn't mean you have to be rude to people

    anyways, he can do what he wants
    he is a developer and if he wants to make 600 of the same apps, he can do that

    if you want to finish the app yourself, learn to code, then finish it
  8. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    i've told you, i'm DONE with jailbroken apps, quite likely permanently. I've moved on to appstore, where i will be making money.
  9. Nickll9009

    Nickll9009 New Member

    Joined:
    Sep 19, 2007
    Messages:
    1,367
    Likes Received:
    8
    Device:
    iPod touch
    If you stick to your word, you wont be making any money =P

    Straight from the About section of TapDial v2.0
  10. cacman93

    cacman93 Banned

    Joined:
    Jul 13, 2008
    Messages:
    1,061
    Likes Received:
    0
    Device:
    iPhone 3G (Black)

    oh, yeah, nice punish me with the cubs, to bad there about to lose out to the rays.
    ------------------double post merged------------------
    well, you never told me that, so, can you release what you have in the vault.

Share This Page