mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-05 15:00:30 +03:00
make is_apk_and_debuggable() default to using androguard before aapt
This commit is contained in:
parent
847bbb6e43
commit
52b3436ff6
4 changed files with 28 additions and 10 deletions
|
|
@ -817,7 +817,7 @@ def build_local(app, build, vcs, build_dir, output_dir, log_dir, srclib_dir, ext
|
||||||
src = os.path.normpath(apks[0])
|
src = os.path.normpath(apks[0])
|
||||||
|
|
||||||
# Make sure it's not debuggable...
|
# Make sure it's not debuggable...
|
||||||
if common.isApkAndDebuggable(src):
|
if common.is_apk_and_debuggable(src):
|
||||||
raise BuildException("APK is debuggable")
|
raise BuildException("APK is debuggable")
|
||||||
|
|
||||||
# By way of a sanity check, make sure the version and version
|
# By way of a sanity check, make sure the version and version
|
||||||
|
|
|
||||||
|
|
@ -1927,7 +1927,25 @@ def get_file_extension(filename):
|
||||||
return os.path.splitext(filename)[1].lower()[1:]
|
return os.path.splitext(filename)[1].lower()[1:]
|
||||||
|
|
||||||
|
|
||||||
def get_apk_debuggable_aapt(apkfile):
|
def use_androguard():
|
||||||
|
"""Report if androguard is available, and config its debug logging"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
import androguard
|
||||||
|
if use_androguard.show_path:
|
||||||
|
logging.debug(_('Using androguard from "{path}"').format(path=androguard.__file__))
|
||||||
|
use_androguard.show_path = False
|
||||||
|
if options and options.verbose:
|
||||||
|
logging.getLogger("androguard.axml").setLevel(logging.INFO)
|
||||||
|
return True
|
||||||
|
except ImportError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
use_androguard.show_path = True
|
||||||
|
|
||||||
|
|
||||||
|
def is_apk_and_debuggable_aapt(apkfile):
|
||||||
p = SdkToolsPopen(['aapt', 'dump', 'xmltree', apkfile, 'AndroidManifest.xml'],
|
p = SdkToolsPopen(['aapt', 'dump', 'xmltree', apkfile, 'AndroidManifest.xml'],
|
||||||
output=False)
|
output=False)
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
|
|
@ -1938,7 +1956,7 @@ def get_apk_debuggable_aapt(apkfile):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_apk_debuggable_androguard(apkfile):
|
def is_apk_and_debuggable_androguard(apkfile):
|
||||||
try:
|
try:
|
||||||
from androguard.core.bytecodes.apk import APK
|
from androguard.core.bytecodes.apk import APK
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
@ -1952,7 +1970,7 @@ def get_apk_debuggable_androguard(apkfile):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def isApkAndDebuggable(apkfile):
|
def is_apk_and_debuggable(apkfile):
|
||||||
"""Returns True if the given file is an APK and is debuggable
|
"""Returns True if the given file is an APK and is debuggable
|
||||||
|
|
||||||
:param apkfile: full path to the apk to check"""
|
:param apkfile: full path to the apk to check"""
|
||||||
|
|
@ -1960,10 +1978,10 @@ def isApkAndDebuggable(apkfile):
|
||||||
if get_file_extension(apkfile) != 'apk':
|
if get_file_extension(apkfile) != 'apk':
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if SdkToolsPopen(['aapt', 'version'], output=False):
|
if use_androguard():
|
||||||
return get_apk_debuggable_aapt(apkfile)
|
return is_apk_and_debuggable_androguard(apkfile)
|
||||||
else:
|
else:
|
||||||
return get_apk_debuggable_androguard(apkfile)
|
return is_apk_and_debuggable_aapt(apkfile)
|
||||||
|
|
||||||
|
|
||||||
def get_apk_id_aapt(apkfile):
|
def get_apk_id_aapt(apkfile):
|
||||||
|
|
|
||||||
|
|
@ -1324,7 +1324,7 @@ def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=Fal
|
||||||
return True, None, False
|
return True, None, False
|
||||||
|
|
||||||
# Check for debuggable apks...
|
# Check for debuggable apks...
|
||||||
if common.isApkAndDebuggable(apkfile):
|
if common.is_apk_and_debuggable(apkfile):
|
||||||
logging.warning('{0} is set to android:debuggable="true"'.format(apkfile))
|
logging.warning('{0} is set to android:debuggable="true"'.format(apkfile))
|
||||||
|
|
||||||
if options.rename_apks:
|
if options.rename_apks:
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ class CommonTest(unittest.TestCase):
|
||||||
testfiles.append(os.path.join(self.basedir, 'urzip-badsig.apk'))
|
testfiles.append(os.path.join(self.basedir, 'urzip-badsig.apk'))
|
||||||
testfiles.append(os.path.join(self.basedir, 'urzip-badcert.apk'))
|
testfiles.append(os.path.join(self.basedir, 'urzip-badcert.apk'))
|
||||||
for apkfile in testfiles:
|
for apkfile in testfiles:
|
||||||
debuggable = fdroidserver.common.isApkAndDebuggable(apkfile)
|
debuggable = fdroidserver.common.is_apk_and_debuggable(apkfile)
|
||||||
self.assertTrue(debuggable,
|
self.assertTrue(debuggable,
|
||||||
"debuggable APK state was not properly parsed!")
|
"debuggable APK state was not properly parsed!")
|
||||||
# these are set NOT debuggable
|
# these are set NOT debuggable
|
||||||
|
|
@ -148,7 +148,7 @@ class CommonTest(unittest.TestCase):
|
||||||
testfiles.append(os.path.join(self.basedir, 'urzip-release.apk'))
|
testfiles.append(os.path.join(self.basedir, 'urzip-release.apk'))
|
||||||
testfiles.append(os.path.join(self.basedir, 'urzip-release-unsigned.apk'))
|
testfiles.append(os.path.join(self.basedir, 'urzip-release-unsigned.apk'))
|
||||||
for apkfile in testfiles:
|
for apkfile in testfiles:
|
||||||
debuggable = fdroidserver.common.isApkAndDebuggable(apkfile)
|
debuggable = fdroidserver.common.is_apk_and_debuggable(apkfile)
|
||||||
self.assertFalse(debuggable,
|
self.assertFalse(debuggable,
|
||||||
"debuggable APK state was not properly parsed!")
|
"debuggable APK state was not properly parsed!")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue