From fc4679cebba468a7491301959cfd71504ac20aea Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 7 Jan 2015 20:08:15 +0100 Subject: [PATCH] if `apktool` is available, use it to decompress APKs when verifying apktool decompiles the binary XML to regular XML, so it is much easier to read for differences. --- fdroidserver/common.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index c8ed3756..bfeb544d 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1897,6 +1897,19 @@ def compare_apks(apk1, apk2, tmp_dir): cwd=os.path.join(apk2dir, 'jar-xf')) != 0: return("Failed to unpack " + apk2) + # try to find apktool in the path, if it hasn't been manually configed + if not 'apktool' in config: + tmp = find_command('apktool') + if not tmp is None: + config['apktool'] = tmp + if 'apktool' in config: + if subprocess.call([config['apktool'], 'd', os.path.abspath(apk1), '--output', 'apktool'], + cwd=apk1dir) != 0: + return("Failed to unpack " + apk1) + if subprocess.call([config['apktool'], 'd', os.path.abspath(apk2), '--output', 'apktool'], + cwd=apk2dir) != 0: + return("Failed to unpack " + apk2) + p = FDroidPopen(['diff', '-r', apk1dir, apk2dir], output=False) lines = p.output.splitlines() if len(lines) != 1 or 'META-INF' not in lines[0]: @@ -1904,3 +1917,23 @@ def compare_apks(apk1, apk2, tmp_dir): # If we get here, it seems like they're the same! return None + + +def find_command(command): + '''find the full path of a command, or None if it can't be found in the PATH''' + + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + fpath, fname = os.path.split(command) + if fpath: + if is_exe(command): + return command + else: + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, command) + if is_exe(exe_file): + return exe_file + + return None