use of tinker.net.dongliu.apk.parser.exception.ParserException in project tinker by Tencent.
the class AndroidParser method parse.
private void parse() throws ParserException {
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
Document document;
try {
DocumentBuilder builder = builderFactory.newDocumentBuilder();
// Block any external content resolving actions since we don't need them and a report
// says these actions may cause security problems.
builder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
return new InputSource();
}
});
document = builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
Node manifestNode = document.getElementsByTagName("manifest").item(0);
NodeList nodes = manifestNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
String nodeName = node.getNodeName();
if (nodeName.equals("application")) {
NodeList children = node.getChildNodes();
for (int j = 0; j < children.getLength(); j++) {
Node child = children.item(j);
String childName = child.getNodeName();
switch(childName) {
case "service":
services.add(getAndroidComponent(child, TYPE_SERVICE));
break;
case "activity":
activities.add(getAndroidComponent(child, TYPE_ACTIVITY));
break;
case "receiver":
receivers.add(getAndroidComponent(child, TYPE_BROADCAST_RECEIVER));
break;
case "provider":
providers.add(getAndroidComponent(child, TYPE_CONTENT_PROVIDER));
break;
case "meta-data":
NamedNodeMap attributes = child.getAttributes();
metaDatas.put(getAttribute(attributes, "android:name"), getAttribute(attributes, "android:value"));
break;
default:
break;
}
}
}
}
} catch (Exception e) {
throw new ParserException("Error parsing AndroidManifest.xml", e);
}
}
Aggregations