update: find aapt when it is not in the PATH

This is some very messy logic built up since 2010.  This will all go away
once we have a python3 version of androguard available.

The removed imports and `dir(APK)` is to silence pyflakes

closes #303
This commit is contained in:
Hans-Christoph Steiner 2017-05-18 17:20:24 +02:00
parent c348186ad6
commit 0345d2c79f
4 changed files with 6 additions and 9 deletions

View file

@ -544,7 +544,7 @@ def get_apk_metadata_androguard(apkfile):
def get_metadata_from_apk(app, build, apkfile): def get_metadata_from_apk(app, build, apkfile):
"""get the required metadata from the built APK""" """get the required metadata from the built APK"""
if common.set_command_in_config('aapt'): if common.SdkToolsPopen(['aapt', 'version'], output=False):
vercode, version, foundid, nativecode = get_apk_metadata_aapt(apkfile) vercode, version, foundid, nativecode = get_apk_metadata_aapt(apkfile)
else: else:
vercode, version, foundid, nativecode = get_apk_metadata_androguard(apkfile) vercode, version, foundid, nativecode = get_apk_metadata_androguard(apkfile)

View file

@ -1727,7 +1727,7 @@ def isApkAndDebuggable(apkfile, config):
if get_file_extension(apkfile) != 'apk': if get_file_extension(apkfile) != 'apk':
return False return False
if set_command_in_config('aapt'): if SdkToolsPopen(['aapt', 'version'], output=False):
return get_apk_debuggable_aapt(apkfile) return get_apk_debuggable_aapt(apkfile)
else: else:
return get_apk_debuggable_androguard(apkfile) return get_apk_debuggable_androguard(apkfile)

View file

@ -1128,7 +1128,7 @@ def scan_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk):
apk['antiFeatures'].add('KnownVuln') apk['antiFeatures'].add('KnownVuln')
try: try:
if common.set_command_in_config('aapt'): if SdkToolsPopen(['aapt', 'version'], output=False):
scan_apk_aapt(apk, apkfile) scan_apk_aapt(apk, apkfile)
else: else:
scan_apk_androguard(apk, apkfile) scan_apk_androguard(apk, apkfile)

View file

@ -4,12 +4,8 @@ import inspect
import logging import logging
import optparse import optparse
import os import os
import shutil
import sys import sys
import tempfile
import unittest import unittest
import yaml
from binascii import unhexlify
localmodule = os.path.realpath( localmodule = os.path.realpath(
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')) os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
@ -53,9 +49,10 @@ class UpdateTest(unittest.TestCase):
fdroidserver.update.options.clean = True fdroidserver.update.options.clean = True
fdroidserver.update.options.delete_unknown = True fdroidserver.update.options.delete_unknown = True
self.assertTrue(fdroidserver.common.set_command_in_config('aapt')) self.assertTrue(fdroidserver.common.SdkToolsPopen('aapt'))
try: try:
from androguard.core.bytecodes.apk import APK from androguard.core.bytecodes.apk import APK
dir(APK)
except ImportError: except ImportError:
raise Exception("androguard not installed!") raise Exception("androguard not installed!")
@ -89,4 +86,4 @@ if __name__ == "__main__":
newSuite = unittest.TestSuite() newSuite = unittest.TestSuite()
newSuite.addTest(unittest.makeSuite(UpdateTest)) newSuite.addTest(unittest.makeSuite(UpdateTest))
unittest.main() unittest.main()