Last active
March 26, 2017 13:42
-
-
Save cielavenir/089ae47301458db8e2e04a67f72132b3 to your computer and use it in GitHub Desktop.
applink.py for iOS8+ (beta)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#applink.py for iOS8+ (beta) | |
#Erica Utilities package (plutil) is required. | |
#Note: linkname is app-identifier rather than app-name. | |
#Python: https://onedrive.live.com/?authkey=!APbsHsgWQMnaVVM&cid=AB142AFF051B6CD3&id=AB142AFF051B6CD3!16995&parId=AB142AFF051B6CD3!102&action=locate | |
import sys,os | |
linkdir='/var/mobile/applink' | |
tmpdir='/var/mobile/applink_tmp' | |
try: | |
os.makedirs(linkdir) | |
except OSError: | |
pass | |
try: | |
os.makedirs(tmpdir) | |
except OSError: | |
pass | |
for lnk in os.listdir(linkdir): | |
os.unlink(linkdir+'/'+lnk) | |
appdirs=[ | |
#This Application/iTunesMetadata.plist looks unusable on iOS10. | |
#['/var/containers/Bundle/Application','iTunesMetadata.plist','bundleDisplayName'], | |
['/var/mobile/Containers/Data/Application','.com.apple.mobile_container_manager.metadata.plist','MCMMetadataIdentifier'], | |
['/var/mobile/Containers/Shared/AppGroup','.com.apple.mobile_container_manager.metadata.plist','MCMMetadataIdentifier'], | |
] | |
for appdir in appdirs: | |
for ident in os.listdir(appdir[0]): | |
print(ident) | |
try: | |
with open(appdir[0]+'/'+ident+'/'+appdir[1],'rb') as fin: | |
with open(tmpdir+'/'+ident+'.plist','wb') as fout: | |
while 1: | |
buf = fin.read(65536) | |
if not buf: break | |
fout.write(buf) | |
except IOError: | |
print('metadata not found; possibly impactor stuff.') | |
continue | |
os.system('plutil -convert xml1 '+tmpdir+'/'+ident+'.plist >/dev/null') | |
with open(tmpdir+'/'+ident+'.plist') as fin: | |
a=list(map(lambda e:e.strip(),fin)) | |
try: | |
idx=a.index('<key>'+appdir[2]+'</key>') | |
appname=a[idx+1][8:-9].replace('/','_') | |
print(appname) | |
os.symlink(appdir[0]+'/'+ident,linkdir+'/'+appname) | |
except ValueError: | |
print('cannot parse metadata.') | |
except OSError: | |
print('[developer fault] '+appname) | |
os.unlink(tmpdir+'/'+ident+'.plist') | |
#sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment