mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-15 07:22:29 +03:00
remove aapt version of common.is_apk_and_debuggable()
This commit is contained in:
parent
b5cd850abe
commit
27b90a13bf
2 changed files with 9 additions and 46 deletions
|
@ -2389,19 +2389,15 @@ def ensure_final_value(packageName, arsc, value):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def is_apk_and_debuggable_aapt(apkfile):
|
def is_apk_and_debuggable(apkfile):
|
||||||
p = SdkToolsPopen(['aapt', 'dump', 'xmltree', apkfile, 'AndroidManifest.xml'],
|
"""Returns True if the given file is an APK and is debuggable
|
||||||
output=False)
|
|
||||||
if p.returncode != 0:
|
Parse only <application android:debuggable=""> from the APK.
|
||||||
raise FDroidException(_("Failed to get APK manifest information"))
|
|
||||||
for line in p.output.splitlines():
|
:param apkfile: full path to the apk to check"""
|
||||||
if 'android:debuggable' in line and not line.endswith('0x0'):
|
|
||||||
return True
|
if get_file_extension(apkfile) != 'apk':
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_apk_and_debuggable_androguard(apkfile):
|
|
||||||
"""Parse only <application android:debuggable=""> from the APK"""
|
|
||||||
from androguard.core.bytecodes.axml import AXMLParser, format_value, START_TAG
|
from androguard.core.bytecodes.axml import AXMLParser, format_value, START_TAG
|
||||||
with ZipFile(apkfile) as apk:
|
with ZipFile(apkfile) as apk:
|
||||||
with apk.open('AndroidManifest.xml') as manifest:
|
with apk.open('AndroidManifest.xml') as manifest:
|
||||||
|
@ -2423,20 +2419,6 @@ def is_apk_and_debuggable_androguard(apkfile):
|
||||||
return False
|
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):
|
def get_apk_id(apkfile):
|
||||||
"""Extract identification information from APK.
|
"""Extract identification information from APK.
|
||||||
|
|
||||||
|
|
|
@ -148,11 +148,6 @@ class CommonTest(unittest.TestCase):
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = 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
|
# these are set debuggable
|
||||||
testfiles = []
|
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-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.is_apk_and_debuggable(apkfile)
|
self.assertTrue(fdroidserver.common.is_apk_and_debuggable(apkfile),
|
||||||
self.assertTrue(debuggable,
|
|
||||||
"debuggable APK state was not properly parsed!")
|
"debuggable APK state was not properly parsed!")
|
||||||
if 'aapt' in config:
|
|
||||||
self.assertTrue(fdroidserver.common.is_apk_and_debuggable_aapt(apkfile),
|
|
||||||
'aapt parsing missed <application android:debuggable="">!')
|
|
||||||
if fdroidserver.common.use_androguard():
|
|
||||||
self.assertTrue(fdroidserver.common.is_apk_and_debuggable_androguard(apkfile),
|
|
||||||
'androguard missed <application android:debuggable="">!')
|
|
||||||
|
|
||||||
# these are set NOT debuggable
|
# these are set NOT debuggable
|
||||||
testfiles = []
|
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, 'urzip-release-unsigned.apk'))
|
||||||
testfiles.append(os.path.join(self.basedir, 'v2.only.sig_2.apk'))
|
testfiles.append(os.path.join(self.basedir, 'v2.only.sig_2.apk'))
|
||||||
for apkfile in testfiles:
|
for apkfile in testfiles:
|
||||||
debuggable = fdroidserver.common.is_apk_and_debuggable(apkfile)
|
self.assertFalse(fdroidserver.common.is_apk_and_debuggable(apkfile),
|
||||||
self.assertFalse(debuggable,
|
|
||||||
"debuggable APK state was not properly parsed!")
|
"debuggable APK state was not properly parsed!")
|
||||||
if 'aapt' in config:
|
|
||||||
self.assertFalse(fdroidserver.common.is_apk_and_debuggable_aapt(apkfile),
|
|
||||||
'aapt parsing missed <application android:debuggable="">!')
|
|
||||||
if fdroidserver.common.use_androguard():
|
|
||||||
self.assertFalse(fdroidserver.common.is_apk_and_debuggable_androguard(apkfile),
|
|
||||||
'androguard missed <application android:debuggable="">!')
|
|
||||||
|
|
||||||
VALID_STRICT_PACKAGE_NAMES = [
|
VALID_STRICT_PACKAGE_NAMES = [
|
||||||
"An.stop",
|
"An.stop",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue