From 27b90a13bff71651e47d95cb35b772842a849889 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 14 Oct 2020 16:49:00 +0200 Subject: [PATCH] remove aapt version of common.is_apk_and_debuggable() --- fdroidserver/common.py | 32 +++++++------------------------- tests/common.TestCase | 23 ++--------------------- 2 files changed, 9 insertions(+), 46 deletions(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index aefe50b0..32ca62bc 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -2389,19 +2389,15 @@ def ensure_final_value(packageName, arsc, value): return '' -def is_apk_and_debuggable_aapt(apkfile): - p = SdkToolsPopen(['aapt', 'dump', 'xmltree', apkfile, 'AndroidManifest.xml'], - output=False) - if p.returncode != 0: - raise FDroidException(_("Failed to get APK manifest information")) - for line in p.output.splitlines(): - if 'android:debuggable' in line and not line.endswith('0x0'): - return True - return False +def is_apk_and_debuggable(apkfile): + """Returns True if the given file is an APK and is debuggable + Parse only from the APK. -def is_apk_and_debuggable_androguard(apkfile): - """Parse only from the APK""" + :param apkfile: full path to the apk to check""" + + if get_file_extension(apkfile) != 'apk': + return False from androguard.core.bytecodes.axml import AXMLParser, format_value, START_TAG with ZipFile(apkfile) as apk: with apk.open('AndroidManifest.xml') as manifest: @@ -2423,20 +2419,6 @@ def is_apk_and_debuggable_androguard(apkfile): return False -def is_apk_and_debuggable(apkfile): - """Returns True if the given file is an APK and is debuggable - - :param apkfile: full path to the apk to check""" - - if get_file_extension(apkfile) != 'apk': - return False - - if use_androguard(): - return is_apk_and_debuggable_androguard(apkfile) - else: - return is_apk_and_debuggable_aapt(apkfile) - - def get_apk_id(apkfile): """Extract identification information from APK. diff --git a/tests/common.TestCase b/tests/common.TestCase index ca06de8b..99e10e08 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -148,11 +148,6 @@ class CommonTest(unittest.TestCase): config = dict() fdroidserver.common.fill_config_defaults(config) fdroidserver.common.config = config - self._set_build_tools() - try: - config['aapt'] = fdroidserver.common.find_sdk_tools_cmd('aapt') - except fdroidserver.exception.FDroidException: - pass # aapt is not required if androguard is present # these are set debuggable testfiles = [] @@ -160,15 +155,8 @@ class CommonTest(unittest.TestCase): testfiles.append(os.path.join(self.basedir, 'urzip-badsig.apk')) testfiles.append(os.path.join(self.basedir, 'urzip-badcert.apk')) for apkfile in testfiles: - debuggable = fdroidserver.common.is_apk_and_debuggable(apkfile) - self.assertTrue(debuggable, + self.assertTrue(fdroidserver.common.is_apk_and_debuggable(apkfile), "debuggable APK state was not properly parsed!") - if 'aapt' in config: - self.assertTrue(fdroidserver.common.is_apk_and_debuggable_aapt(apkfile), - 'aapt parsing missed !') - if fdroidserver.common.use_androguard(): - self.assertTrue(fdroidserver.common.is_apk_and_debuggable_androguard(apkfile), - 'androguard missed !') # these are set NOT debuggable testfiles = [] @@ -176,15 +164,8 @@ class CommonTest(unittest.TestCase): testfiles.append(os.path.join(self.basedir, 'urzip-release-unsigned.apk')) testfiles.append(os.path.join(self.basedir, 'v2.only.sig_2.apk')) for apkfile in testfiles: - debuggable = fdroidserver.common.is_apk_and_debuggable(apkfile) - self.assertFalse(debuggable, + self.assertFalse(fdroidserver.common.is_apk_and_debuggable(apkfile), "debuggable APK state was not properly parsed!") - if 'aapt' in config: - self.assertFalse(fdroidserver.common.is_apk_and_debuggable_aapt(apkfile), - 'aapt parsing missed !') - if fdroidserver.common.use_androguard(): - self.assertFalse(fdroidserver.common.is_apk_and_debuggable_androguard(apkfile), - 'androguard missed !') VALID_STRICT_PACKAGE_NAMES = [ "An.stop",