/
ipapiescan.py
executable file
·95 lines (76 loc) · 2.69 KB
/
ipapiescan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import zipfile
import biplist
import glob
import os
import sys
import subprocess
import re
def doit(basedir):
ipas = glob.glob(basedir + "/*.ipa")
for fn in ipas:
x = zipfile.ZipFile(fn)
y = x.namelist()
infoplist = ""
execFile = ""
for n in y:
if n[-11:] == "/Info.plist":
infoplist = n
if infoplist == "":
return
plistData = x.read(infoplist)
plist = biplist.readPlistFromString(plistData)
if "CFBundleDisplayName" in plist:
appname = plist["CFBundleDisplayName"]
elif "CFBundleName" in plist:
appname = plist["CFBundleName"]
else:
appname = plist["CFBundleIdentifier"]
appname += (32-len(appname)) * " "
if "CFBundleExecutable" not in plist:
continue
l = len(plist["CFBundleExecutable"])
for n in y:
if n[-l:] == plist["CFBundleExecutable"]:
execFile = n
if execFile == "":
print "Cannot find execFile"
continue
data = x.read(execFile)
tname = "ipapiescan_XABCDEF"
f = open(tname, "w+b")
f.write(data)
f.close()
output = subprocess.check_output(["otool", "-vh", tname])
archstr = ""
if output.find("ARM V6") != -1:
archstr += "armv6"
bestarch = "armv6"
if output.find("ARM V7") != -1:
if archstr == "":
archstr = " armv7"
else:
archstr += "|armv7"
bestarch = "armv7"
if bestarch == "armv6":
archstr += " "
if archstr == "":
print "%s - illegal architecture" % (appname)
print output
else:
output = subprocess.check_output(["otool", "-arch", bestarch ,"-vh", tname])
if output.find("PIE") == -1:
pie = "NO_PIE"
#print output
else:
pie = "PIE "
output = subprocess.check_output(["otool", "-arch", bestarch ,"-lv", tname])
if output.find("LC_VERSION_MIN_IPHONEOS") == -1:
minversion = "N/A"
else:
#print output
p = re.compile('LC_VERSION_MIN_IPHONEOS[^v]*version[^0-9]+([0-9]+\.[0-9]+)', re.MULTILINE|re.DOTALL)
x = p.search(output)
minversion = x.groups(0)[0]
print "%s - %s - %s - %s" % (appname, archstr, pie, minversion)
os.unlink(tname)
doit(os.getenv("HOME") + "/Music/iTunes/iTunes Media/Mobile Applications/")