update: switch to new androguard v3.1 API based on lxml

apkobject.get_android_manifest_xml() used to return a xml.dom.minidom
object, now it returns an lxml.etree.Element object.
This commit is contained in:
Hans-Christoph Steiner 2018-02-14 22:03:00 +01:00
parent 699b3e4c69
commit 5281228ea5

View file

@ -1240,28 +1240,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."):