SHOW:
|
|
- or go back to the newest paste.
| 1 | #!/usr/bin/python | |
| 2 | ||
| 3 | PATH="/var/mobile/applink" | |
| 4 | ||
| 5 | import sys,os,objc # PyObjC; this is a dependency of the AppBackup package | |
| 6 | from objc import YES, NO, NULL | |
| 7 | objc.loadBundle("Foundation", globals(), "/System/Library/Frameworks/Foundation.framework")
| |
| 8 | ||
| 9 | # a class to work with plists using Foundation (so we can read binary plists) | |
| 10 | class plist: | |
| 11 | @classmethod | |
| 12 | def read(cls, filename): | |
| 13 | return NSDictionary.alloc().initWithContentsOfFile_(filename) | |
| 14 | ||
| 15 | # Gets the info from the MobileInstallation cache. | |
| 16 | def find_apps(): | |
| 17 | if not os.path.exists("/var/mobile/Library/Caches/com.apple.mobile.installation.plist"):
| |
| 18 | - | sys.stdout.write("MobileInstallation cache not found; reverting to old method of finding apps...\n")
|
| 18 | + | sys.stderr.write("MobileInstallation cache not found; reverting to old method of finding apps...\n")
|
| 19 | find_apps_old() | |
| 20 | return | |
| 21 | try: | |
| 22 | mobileInstallationCache = plist.read("/var/mobile/Library/Caches/com.apple.mobile.installation.plist")
| |
| 23 | except: | |
| 24 | - | sys.stdout.write("Reading the MobileInstallation cache failed; reverting to old method of finding apps...\n")
|
| 24 | + | sys.stderr.write("Reading the MobileInstallation cache failed; reverting to old method of finding apps...\n")
|
| 25 | find_apps_old() | |
| 26 | return | |
| 27 | if "User" not in mobileInstallationCache: | |
| 28 | - | sys.stdout.write("MobileInstallation cache doesn't have a User key; reverting to old method of finding apps...\n")
|
| 28 | + | sys.stderr.write("MobileInstallation cache doesn't have a User key; reverting to old method of finding apps...\n")
|
| 29 | find_apps_old() | |
| 30 | return | |
| 31 | appStoreApps = mobileInstallationCache["User"] | |
| 32 | - | sys.stdout.write("Here are the app bundles I found:\n")
|
| 32 | + | sys.stderr.write("Here are the app bundles I found:\n")
|
| 33 | for key in appStoreApps: | |
| 34 | i = appStoreApps[key] | |
| 35 | path = "/".join(i["Path"].rstrip("/").split("/")[:-1])
| |
| 36 | if os.path.exists(path) and "CFBundleDisplayName" in i and i["CFBundleDisplayName"] != "": | |
| 37 | #dotApp = i["Path"].rstrip("/").split("/")[-1]
| |
| 38 | #dotAppFull = path + "/" + dotApp | |
| 39 | if path.startswith("/private"):
| |
| 40 | path = path.split("/private", 1)[1]
| |
| 41 | guid = path.split("/")[-1]
| |
| 42 | - | sys.stdout.write(guid+"\n") |
| 42 | + | sys.stderr.write(guid+"\n") |
| 43 | try: | |
| 44 | os.symlink(path,i["CFBundleDisplayName"]) | |
| 45 | except: | |
| 46 | - | sys.stdout.write("Duplicate name\n")
|
| 46 | + | sys.stderr.write("Duplicate name\n")
|
| 47 | os.symlink(path,i["CFBundleDisplayName"]+"_"+guid) | |
| 48 | ||
| 49 | def find_apps_old(): | |
| 50 | mobile = u"/var/mobile" | |
| 51 | root = mobile+"/Applications" | |
| 52 | applist = []; applist1 = []; appdict = {}; apps = []
| |
| 53 | apps1 = os.listdir(root) | |
| 54 | for i in apps1: | |
| 55 | if os.path.isdir(root+"/"+i) == True: | |
| 56 | apps.append(i) | |
| 57 | - | sys.stdout.write("Here are the app bundles and Info.plist's I found:\n")
|
| 57 | + | sys.stderr.write("Here are the app bundles and Info.plist's I found:\n")
|
| 58 | for k in apps: | |
| 59 | appdir = root+"/"+k | |
| 60 | for j in os.listdir(appdir): | |
| 61 | if j.endswith(u".app"): | |
| 62 | plistfile = u"%s/%s/Info.plist" % (appdir, j) | |
| 63 | if os.path.exists(plistfile) == True: | |
| 64 | pl = plist.read(plistfile) | |
| 65 | if "CFBundleDisplayName" in pl: | |
| 66 | guid = appdir.split("/")[-1]
| |
| 67 | - | sys.stdout.write(guid+"\n") |
| 67 | + | sys.stderr.write(guid+"\n") |
| 68 | try: | |
| 69 | os.symlink(appdir,pl["CFBundleDisplayName"]) | |
| 70 | except: | |
| 71 | - | sys.stdout.write("Duplicate name\n")
|
| 71 | + | sys.stderr.write("Duplicate name\n")
|
| 72 | os.symlink(appdir,pl["CFBundleDisplayName"]+"_"+guid) | |
| 73 | ||
| 74 | #main | |
| 75 | os.system("rm -rf \""+PATH+"\"")
| |
| 76 | os.mkdir(PATH) | |
| 77 | os.chdir(PATH) | |
| 78 | find_apps() |