Skip to content

Instantly share code, notes, and snippets.

@Hucent
Created December 2, 2017 12:57
Show Gist options
  • Save Hucent/e7f0472746393b3f37d4602281db2e59 to your computer and use it in GitHub Desktop.
Save Hucent/e7f0472746393b3f37d4602281db2e59 to your computer and use it in GitHub Desktop.
Archive ipa
#coding:utf-8
import zipfile, plistlib, sys, re, datetime, os, shutil
def analyze_ipa_with_plistlib(ipa_path):
print ('path: %s' % ipa_path)
ipa_file = zipfile.ZipFile(ipa_path)
plist_path = find_plist_path(ipa_file)
plist_data = ipa_file.read(plist_path)
plist_root = plistlib.loads(plist_data)
print_ipa_info (plist_root)
final_path = make_dir(plist_root)
file_full_name = ipa_path.split("/")[-1]
file_name = file_full_name.split(".")[0]
file_ext = file_full_name.split(".")[1]
new_file_fullname = file_name + '_' + plist_root['CFBundleShortVersionString'] + "(" + plist_root['CFBundleVersion'] +")." + file_ext
new_file_full_path = final_path + '/' + new_file_fullname
shutil.copyfile(ipa_path, new_file_full_path)
print ('name %s' % new_file_full_path)
def make_dir(plist_root):
dir_name = plist_root['CFBundleVersion'][0:8]
final_path = '/Users/Hucent/Downloads/' + dir_name
if os.path.exists(final_path):
print ('dir exists %s' % final_path)
else:
print ('dir not exists %s' % final_path)
os.makedirs(final_path)
return final_path
def find_plist_path(zip_file):
name_list = zip_file.namelist()
pattern = re.compile(r'Payload/[^/]*.app/Info.plist')
for path in name_list:
m = pattern.match(path)
if m is not None:
return m.group()
def print_ipa_info(plist_root):
print ('Display Name: %s' % plist_root['CFBundleDisplayName'])
print ('Bundle Identifier: %s' % plist_root['CFBundleIdentifier'])
print ('Version: %s' % plist_root['CFBundleShortVersionString'])
print ('Bundle Version: %s' % plist_root['CFBundleVersion'])
if __name__ == '__main__':
args = sys.argv[1:]
if len(args) > 1:
print ('Usage: python3 ipaanalyze.py /path/to/ipa')
ipa_path = args[0]
analyze_ipa_with_plistlib(ipa_path)
# find_plist_path(ipa_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment