private String getDecodedXML() throws XmlPullParserException, IOException { //return new AXMLPrinter(inputFile.getContent()).getResult(); InputStream stream = inputFile.getStream(); if (stream != null) { AXMLResource axmlResource = new AXMLResource(); try { axmlResource.read(stream); String decoded = axmlResource.toXML(); stream.close(); return decoded; } catch (IOException e) { e.printStackTrace(); } } return null; }
@Test public void testToXml() throws IOException, ParserConfigurationException { InputStream testStream = this.getClass().getClassLoader().getResourceAsStream(largeFromMalware); underTest = new AXMLResource(testStream); String xml = underTest.toXML(); try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes())); Node manifestNode = document.getFirstChild(); NamedNodeMap manifestNodeAttributes = manifestNode.getAttributes(); assertEquals("http://schemas.android.com/apk/res/android", manifestNodeAttributes.getNamedItem("xmlns:android").getNodeValue()); assertEquals("3133", manifestNodeAttributes.getNamedItem("android:versionCode").getNodeValue()); assertEquals("1.9.3", manifestNodeAttributes.getNamedItem("android:versionName").getNodeValue()); assertEquals("com.faithcomesbyhearing.android.pt.bibleis", manifestNodeAttributes.getNamedItem("package").getNodeValue()); } catch (SAXException e) { // Is not xml assertTrue(false); } }
@Test public void testToXml() throws IOException, ParserConfigurationException { InputStream testStream = this.getClass().getClassLoader().getResourceAsStream(issue8); underTest = new AXMLResource(testStream); String xml = underTest.toXML(); try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes())); Node manifestNode = document.getFirstChild(); NamedNodeMap manifestNodeAttributes = manifestNode.getAttributes(); assertEquals("http://schemas.android.com/apk/res/android", manifestNodeAttributes.getNamedItem("xmlns:android").getNodeValue()); assertEquals("3133", manifestNodeAttributes.getNamedItem("android:versionCode").getNodeValue()); assertEquals("1.9.3", manifestNodeAttributes.getNamedItem("android:versionName").getNodeValue()); assertEquals("com.faithcomesbyhearing.android.pt.bibleis", manifestNodeAttributes.getNamedItem("package").getNodeValue()); } catch (SAXException e) { // Is not xml assertTrue(false); } }