public static String decodeManifest(File manifestFile){ FileInputStream in = null; try { AXMLResource axmlResource = new AXMLResource(); in = new FileInputStream(manifestFile); axmlResource.read(in); return axmlResource.toXmlString(); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(in); } return null; }
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; }
FileOutputStream fileOutputStream = null; try { AXMLResource axmlResource = new AXMLResource(); fileInputStream = new FileInputStream(arguments[0]); axmlResource.read(fileInputStream);
FileOutputStream fileOutputStream = null; try { AXMLResource axmlResource = new AXMLResource(); fileInputStream = new FileInputStream(arguments[0]); axmlResource.read(fileInputStream);
@Before public void setUp() { underTest = new AXMLResource(); }
@Before public void setUp() { underTest = new AXMLResource(); }
@Test public void testPrinting() throws IOException { InputStream testStream = this.getClass().getClassLoader().getResourceAsStream(largeFromMalware); underTest = new AXMLResource(testStream); underTest.print(); }
@Test public void testPrinting() throws IOException { InputStream testStream = this.getClass().getClassLoader().getResourceAsStream(issue8); underTest = new AXMLResource(testStream); underTest.print(); }
@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); } }
@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 testWriteInsertedApplicationAttribute() throws IOException { InputStream testStream = this.getClass().getClassLoader().getResourceAsStream(issue8); underTest.read(testStream); Attribute attribute = new Attribute("android", "name", "test", AttributeType.STRING, null, underTest.getStringSection()); underTest.injectApplicationAttribute(attribute); File file = File.createTempFile("axml-func-test", "xml-test"); file.deleteOnExit(); underTest.write(new FileOutputStream(file)); underTest = new AXMLResource(new FileInputStream(file)); StartTag startTag = underTest.getApplicationTag(); assertEquals(underTest.getStringSection().getString(startTag.getAttributes().get(3).getNameIndex()), "name"); assertEquals(underTest.getStringSection().getString(startTag.getAttributes().get(3).getStringDataIndex()), "test"); } }
@Test public void testWriteInsertedApplicationAttribute() throws IOException { InputStream testStream = this.getClass().getClassLoader().getResourceAsStream(largeFromMalware); underTest.read(testStream); Attribute attribute = new Attribute("android", "name", "test", AttributeType.STRING, null, underTest.getStringSection()); underTest.injectApplicationAttribute(attribute); File file = File.createTempFile("axml-func-test", "xml-test"); file.deleteOnExit(); underTest.write(new FileOutputStream(file)); underTest = new AXMLResource(new FileInputStream(file)); StartTag startTag = underTest.getApplicationTag(); assertEquals(underTest.getStringSection().getString(startTag.getAttributes().get(3).getNameIndex()), "name"); assertEquals(underTest.getStringSection().getString(startTag.getAttributes().get(3).getStringDataIndex()), "test"); } }