From 7c0a5de45e987081b6ee36f25f698e700412f5ec Mon Sep 17 00:00:00 2001 From: "Clemens-O. Hoppe" Date: Mon, 5 Mar 2012 00:12:52 +0100 Subject: [PATCH] UNTESTED! simplified logic, some PEP8 fixes, removed unused import, made the execution on direct invocation only --- ipapiescan.py | 66 ++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/ipapiescan.py b/ipapiescan.py index d11eeda..590a847 100755 --- a/ipapiescan.py +++ b/ipapiescan.py @@ -1,29 +1,26 @@ -import zipfile import biplist import glob import os -import sys -import subprocess import re +import subprocess +import zipfile + +from os.path import expanduser + 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 + infoplist = filter(lambda _: _.endswith('/Info.plist'), y) - if infoplist == "": + if not infoplist: return + else: + infoplist = infoplist[0] plistData = x.read(infoplist) plist = biplist.readPlistFromString(plistData) @@ -34,26 +31,25 @@ def doit(basedir): appname = plist["CFBundleName"] else: appname = plist["CFBundleIdentifier"] - appname += (32-len(appname)) * " " + appname = appname.ljust(32, ' ') if "CFBundleExecutable" not in plist: - continue - l = len(plist["CFBundleExecutable"]) + continue - for n in y: - if n[-l:] == plist["CFBundleExecutable"]: - execFile = n + execFile = filter(lambda _: _.endswith(plist['CFBundleExecutable']), y) - if execFile == "": + if not execFile: print "Cannot find execFile" continue - + else: + execFile = execFile[0] + 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: @@ -67,29 +63,29 @@ def doit(basedir): 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]) + output = subprocess.check_output(["otool", "-arch", bestarch, + "-vh", tname]) + pie = "PIE " if "PIE" in output else "NO_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) + 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/") \ No newline at end of file + +if __name__ == '__main__': + doit(expanduser("~/Music/iTunes/iTunes Media/Mobile Applications/"))