def is_valid_APK(self):
"""
Return true if the APK is valid, false otherwise
:rtype: boolean
"""
return self.valid_apk
def _apk_analysis(self):
"""
Run analysis on the APK file.
This method is usually called by __init__ except if skip_analysis is False.
It will then parse the AndroidManifest.xml and set all fields in the APK class which can be
extracted from the Manifest.
"""
for i in self.zip.namelist():
# 先遍历zip文件名列表
if i == "AndroidManifest.xml":
# 若为"AndroidManifest.xml" 则使用AXMLPrinter工具解析
self.axml[i] = AXMLPrinter(self.zip.read(i))
self.xml[i] = None
raw_xml = self.axml[i].get_buff()
if len(raw_xml) == 0:
log.warning("AXML parsing failed, file is empty")
else:
try:
if self.axml[i].is_packed():
log.warning("XML Seems to be packed, parsing is very likely to fail.")
parser = etree.XMLParser(recover=True)
tree = etree.fromstring(raw_xml, parser=parser)
self.xml[i] = parse_lxml_dom(tree)
except Exception as e:
log.warning("reading AXML as XML failed: " + str(e))
if self.xml[i] is not None:
self.package = self.xml[i].documentElement.getAttribute(
"package")
self.androidversion[
"Code"
] = self.xml[i].documentElement.getAttributeNS(
NS_ANDROID_URI, "versionCode")
self.androidversion[
"Name"
] = self.xml[i].documentElement.getAttributeNS(
NS_ANDROID_URI, "versionName")
for item in self.xml[i].getElementsByTagName('uses-permission'):
self.permissions.append(str(item.getAttributeNS(
NS_ANDROID_URI, "name")))
# getting details of the declared permissions
for d_perm_item in self.xml[i].getElementsByTagName('permission'):
d_perm_name = self._get_res_string_value(str(
d_perm_item.getAttributeNS(NS_ANDROID_URI, "name")))
d_perm_label = self._get_res_string_value(str(
d_perm_item.getAttributeNS(NS_ANDROID_URI,
"label")))
d_perm_description = self._get_res_string_value(str(
d_perm_item.getAttributeNS(NS_ANDROID_URI,
"description")))
d_perm_permissionGroup = self._get_res_string_value(str(
d_perm_item.getAttributeNS(NS_ANDROID_URI,
"permissionGroup")))
d_perm_protectionLevel = self._get_res_string_value(str(
d_perm_item.getAttributeNS(NS_ANDROID_URI,
"protectionLevel")))
d_perm_details = {
"label": d_perm_label,
"description": d_perm_description,
"permissionGroup": d_perm_permissionGroup,
"protectionLevel": d_perm_protectionLevel,
}
self.declared_permissions[d_perm_name] = d_perm_details
self.valid_apk = True
不是应该再判断一下dex文件什么的吗?