mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-15 15:32:30 +03:00
use androguard primitives to speed up finding debuggable flag
androguard parses the whole APK before handing the instance back, this uses the primitives to just find the <application android:debuggable=""> value, then stop parsing. #557
This commit is contained in:
parent
a3cecc16a3
commit
11d46072ab
2 changed files with 33 additions and 6 deletions
|
@ -2073,11 +2073,25 @@ def is_apk_and_debuggable_aapt(apkfile):
|
||||||
|
|
||||||
|
|
||||||
def is_apk_and_debuggable_androguard(apkfile):
|
def is_apk_and_debuggable_androguard(apkfile):
|
||||||
apkobject = _get_androguard_APK(apkfile)
|
"""Parse only <application android:debuggable=""> from the APK"""
|
||||||
if apkobject.is_valid_APK():
|
from androguard.core.bytecodes.axml import AXMLParser, format_value, START_TAG
|
||||||
debuggable = apkobject.get_element("application", "debuggable")
|
with ZipFile(apkfile) as apk:
|
||||||
if debuggable == 'true':
|
with apk.open('AndroidManifest.xml') as manifest:
|
||||||
return True
|
axml = AXMLParser(manifest.read())
|
||||||
|
while axml.is_valid():
|
||||||
|
_type = next(axml)
|
||||||
|
if _type == START_TAG and axml.getName() == 'application':
|
||||||
|
for i in range(0, axml.getAttributeCount()):
|
||||||
|
name = axml.getAttributeName(i)
|
||||||
|
if name == 'debuggable':
|
||||||
|
_type = axml.getAttributeValueType(i)
|
||||||
|
_data = axml.getAttributeValueData(i)
|
||||||
|
value = format_value(_type, _data, lambda _: axml.getAttributeValue(i))
|
||||||
|
if value == 'true':
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
break
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ class CommonTest(unittest.TestCase):
|
||||||
fdroidserver.common._add_java_paths_to_config(pathlist, config)
|
fdroidserver.common._add_java_paths_to_config(pathlist, config)
|
||||||
self.assertEqual(config['java_paths']['8'], choice[1:])
|
self.assertEqual(config['java_paths']['8'], choice[1:])
|
||||||
|
|
||||||
def testIsApkDebuggable(self):
|
def test_is_apk_and_debuggable(self):
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
|
@ -150,6 +150,13 @@ class CommonTest(unittest.TestCase):
|
||||||
debuggable = fdroidserver.common.is_apk_and_debuggable(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!")
|
||||||
|
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 = []
|
||||||
testfiles.append(os.path.join(self.basedir, 'urzip-release.apk'))
|
testfiles.append(os.path.join(self.basedir, 'urzip-release.apk'))
|
||||||
|
@ -158,6 +165,12 @@ class CommonTest(unittest.TestCase):
|
||||||
debuggable = fdroidserver.common.is_apk_and_debuggable(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!")
|
||||||
|
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="">!')
|
||||||
|
|
||||||
def test_is_valid_package_name(self):
|
def test_is_valid_package_name(self):
|
||||||
for name in ["cafebabe",
|
for name in ["cafebabe",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue