python 3.x
1 #!/usr/bin/python
2 # Filename: ipaInfo3.py
3 # author khan.lau
4
5 # python 3.x
6
7 import zipfile, plistlib, sys, re
8
9
10 def analyze_ipa_with_plistlib(ipa_path):
11 ipa_file = zipfile.ZipFile(ipa_path)
12 plist_path = find_plist_path(ipa_file)
13 plist_data = ipa_file.read(plist_path)
14 plist_root = plistlib.loads(plist_data)
15 print_ipa_info(plist_root)
16
17 def print_ipa_info(plist_root):
18 print ('Display Name: %s' % plist_root['CFBundleName'])
19 print ('Bundle Identifier: %s' % plist_root['CFBundleIdentifier'])
20 print ('Version: %s' % plist_root['CFBundleShortVersionString'])
21
22 def find_plist_path(zip_file):
23 name_list = zip_file.namelist()
24 # print name_list
25 pattern = re.compile(r'Payload/[^/]*.app/Info.plist')
26 for path in name_list:
27 m = pattern.match(path)
28 if m is not None:
29 return m.group()
30
31
32
33 if __name__ == '__main__':
34 args = sys.argv[1:]
35 if len(args) < 1:
36 print ('Usage: python ipaInfo3.py /path/to/ipa')
37 exit(0);
38
39 ipa_path = args[0]
40 analyze_ipa_with_plistlib(ipa_path)
41
python 2.7.x
1 #!/usr/bin/python
2 # Filename: ipaInfo2.py
3 # author khan.lau
4
5 # python 2.7.5
6 # project need third_party lib biplist, please run 'sudo pip install biplist'
7
8 import zipfile, biplist, sys, re
9
10
11 def analyze_ipa_with_plistlib(ipa_path):
12 ipa_file = zipfile.ZipFile(ipa_path)
13 plist_path = find_plist_path(ipa_file)
14 plist_data = ipa_file.read(plist_path)
15 plist_root = biplist.readPlistFromString(plist_data)
16 print_ipa_info(plist_root)
17
18 def print_ipa_info(plist_root):
19 print ('Display Name: %s' % plist_root['CFBundleName'])
20 print ('Bundle Identifier: %s' % plist_root['CFBundleIdentifier'])
21 print ('Version: %s' % plist_root['CFBundleShortVersionString'])
22
23 def find_plist_path(zip_file):
24 name_list = zip_file.namelist()
25 # print name_list
26 pattern = re.compile(r'Payload/[^/]*.app/Info.plist')
27 for path in name_list:
28 m = pattern.match(path)
29 if m is not None:
30 return m.group()
31
32
33
34 if __name__ == '__main__':
35 args = sys.argv[1:]
36 if len(args) < 1:
37 print ('Usage: python ipaInfo2.py /path/to/ipa')
38 exit(0);
39
40 ipa_path = args[0]
41 analyze_ipa_with_plistlib(ipa_path)
python2.7 不包含 plistlib, 所以需要引入第三方库 biplist, 使用 easy_install 或 pip 安装库即可, biplist 支持 data 解析, 相对于 plistlib 而已, 只需改动极少代码, 所以采用他