mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-14 15:02:51 +03:00
Merge branch 'use-androguard-first' into 'master'
use androguard first Closes #236 See merge request fdroid/fdroidserver!465
This commit is contained in:
commit
c679b5b144
1 changed files with 22 additions and 19 deletions
|
@ -1049,10 +1049,12 @@ def scan_apk(apk_file):
|
||||||
'antiFeatures': set(),
|
'antiFeatures': set(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if SdkToolsPopen(['aapt', 'version'], output=False):
|
try:
|
||||||
scan_apk_aapt(apk, apk_file)
|
import androguard
|
||||||
else:
|
androguard # silence pyflakes
|
||||||
scan_apk_androguard(apk, apk_file)
|
scan_apk_androguard(apk, apk_file)
|
||||||
|
except ImportError:
|
||||||
|
scan_apk_aapt(apk, apk_file)
|
||||||
|
|
||||||
# Get the signature, or rather the signing key fingerprints
|
# Get the signature, or rather the signing key fingerprints
|
||||||
logging.debug('Getting signature of {0}'.format(os.path.basename(apk_file)))
|
logging.debug('Getting signature of {0}'.format(os.path.basename(apk_file)))
|
||||||
|
@ -1069,7 +1071,9 @@ def scan_apk(apk_file):
|
||||||
|
|
||||||
if 'minSdkVersion' not in apk:
|
if 'minSdkVersion' not in apk:
|
||||||
logging.warning("No SDK version information found in {0}".format(apk_file))
|
logging.warning("No SDK version information found in {0}".format(apk_file))
|
||||||
apk['minSdkVersion'] = 1
|
apk['minSdkVersion'] = 3 # aapt defaults to 3 as the min
|
||||||
|
if 'targetSdkVersion' not in apk:
|
||||||
|
apk['targetSdkVersion'] = apk['minSdkVersion']
|
||||||
|
|
||||||
# Check for known vulnerabilities
|
# Check for known vulnerabilities
|
||||||
if has_known_vulnerability(apk_file):
|
if has_known_vulnerability(apk_file):
|
||||||
|
@ -1125,9 +1129,6 @@ def scan_apk_aapt(apk, apkfile):
|
||||||
+ ' is not a valid minSdkVersion!')
|
+ ' is not a valid minSdkVersion!')
|
||||||
else:
|
else:
|
||||||
apk['minSdkVersion'] = m.group(1)
|
apk['minSdkVersion'] = m.group(1)
|
||||||
# if target not set, default to min
|
|
||||||
if 'targetSdkVersion' not in apk:
|
|
||||||
apk['targetSdkVersion'] = m.group(1)
|
|
||||||
elif line.startswith("targetSdkVersion:"):
|
elif line.startswith("targetSdkVersion:"):
|
||||||
m = re.match(APK_SDK_VERSION_PAT, line)
|
m = re.match(APK_SDK_VERSION_PAT, line)
|
||||||
if m is None:
|
if m is None:
|
||||||
|
@ -1209,7 +1210,9 @@ def scan_apk_androguard(apk, apkfile):
|
||||||
|
|
||||||
if apkobject.get_max_sdk_version() is not None:
|
if apkobject.get_max_sdk_version() is not None:
|
||||||
apk['maxSdkVersion'] = apkobject.get_max_sdk_version()
|
apk['maxSdkVersion'] = apkobject.get_max_sdk_version()
|
||||||
|
if apkobject.get_min_sdk_version() is not None:
|
||||||
apk['minSdkVersion'] = apkobject.get_min_sdk_version()
|
apk['minSdkVersion'] = apkobject.get_min_sdk_version()
|
||||||
|
if apkobject.get_target_sdk_version() is not None:
|
||||||
apk['targetSdkVersion'] = apkobject.get_target_sdk_version()
|
apk['targetSdkVersion'] = apkobject.get_target_sdk_version()
|
||||||
|
|
||||||
icon_id = int(apkobject.get_element("application", "icon").replace("@", "0x"), 16)
|
icon_id = int(apkobject.get_element("application", "icon").replace("@", "0x"), 16)
|
||||||
|
@ -1239,28 +1242,28 @@ def scan_apk_androguard(apk, apkfile):
|
||||||
|
|
||||||
xml = apkobject.get_android_manifest_xml()
|
xml = apkobject.get_android_manifest_xml()
|
||||||
|
|
||||||
for item in xml.getElementsByTagName('uses-permission'):
|
for item in xml.findall('uses-permission'):
|
||||||
name = str(item.getAttribute("android:name"))
|
name = str(item.attrib['{' + xml.nsmap['android'] + '}name'])
|
||||||
maxSdkVersion = item.getAttribute("android:maxSdkVersion")
|
maxSdkVersion = item.attrib.get('{' + xml.nsmap['android'] + '}maxSdkVersion')
|
||||||
maxSdkVersion = None if maxSdkVersion is '' else int(maxSdkVersion)
|
maxSdkVersion = int(maxSdkVersion) if maxSdkVersion else None
|
||||||
permission = UsesPermission(
|
permission = UsesPermission(
|
||||||
name,
|
name,
|
||||||
maxSdkVersion
|
maxSdkVersion
|
||||||
)
|
)
|
||||||
apk['uses-permission'].append(permission)
|
apk['uses-permission'].append(permission)
|
||||||
|
|
||||||
for item in xml.getElementsByTagName('uses-permission-sdk-23'):
|
for item in xml.findall('uses-permission-sdk-23'):
|
||||||
name = str(item.getAttribute("android:name"))
|
name = str(item.attrib['{' + xml.nsmap['android'] + '}name'])
|
||||||
maxSdkVersion = item.getAttribute("android:maxSdkVersion")
|
maxSdkVersion = item.attrib.get('{' + xml.nsmap['android'] + '}maxSdkVersion')
|
||||||
maxSdkVersion = None if maxSdkVersion is '' else int(maxSdkVersion)
|
maxSdkVersion = int(maxSdkVersion) if maxSdkVersion else None
|
||||||
permission_sdk_23 = UsesPermissionSdk23(
|
permission_sdk_23 = UsesPermissionSdk23(
|
||||||
name,
|
name,
|
||||||
maxSdkVersion
|
maxSdkVersion
|
||||||
)
|
)
|
||||||
apk['uses-permission-sdk-23'].append(permission_sdk_23)
|
apk['uses-permission-sdk-23'].append(permission_sdk_23)
|
||||||
|
|
||||||
for item in xml.getElementsByTagName('uses-feature'):
|
for item in xml.findall('uses-feature'):
|
||||||
feature = str(item.getAttribute("android:name"))
|
feature = str(item.attrib['{' + xml.nsmap['android'] + '}name'])
|
||||||
if feature != "android.hardware.screen.portrait" \
|
if feature != "android.hardware.screen.portrait" \
|
||||||
and feature != "android.hardware.screen.landscape":
|
and feature != "android.hardware.screen.landscape":
|
||||||
if feature.startswith("android.feature."):
|
if feature.startswith("android.feature."):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue