FileOutputStream fileOutputStream = null; try { AXMLResource axmlResource = new AXMLResource(); fileInputStream = new FileInputStream(arguments[0]); axmlResource.read(fileInputStream); axmlResource.print(); axmlResource.write(fileOutputStream);
public void injectApplicationAttribute(Attribute attribute) { StartTag tag = getApplicationTag(); tag.insertOrReplaceAttribute(attribute); }
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; }
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; }
@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 testInsertApplicationAttribute() 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); StartTag startTag = underTest.getApplicationTag(); assertTrue(startTag.getAttributes().contains(attribute)); }
@Test public void testPrinting() throws IOException { InputStream testStream = this.getClass().getClassLoader().getResourceAsStream(largeFromMalware); underTest = new AXMLResource(testStream); underTest.print(); }
public AXMLResource(InputStream stream) throws IOException { chunks = new LinkedHashSet<Chunk>(); if (!read(stream)) { throw new IOException(); } }
@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); } }
@Before public void setUp() { underTest = new AXMLResource(); }
public void print() { log("%s", header.toXML(stringSection, resourceSection, 0)); Iterator<Chunk> iterator = chunks.iterator(); int indents = 0; List<String> namespaceXmlList = new ArrayList<String>(); while (iterator.hasNext()) { Chunk chunk = iterator.next(); if (chunk.getChunkType() == ChunkType.END_TAG) { indents--; } if (chunk.getChunkType() == ChunkType.START_NAMESPACE) { namespaceXmlList.add(chunk.toXML(stringSection, resourceSection, indents)); } else if (chunk.getChunkType() == ChunkType.END_NAMESPACE) { // ignore } else { if (namespaceXmlList.isEmpty()) { log("%s", chunk.toXML(stringSection, resourceSection, indents)); } else { log("%s", appendNameSpace(chunk.toXML(stringSection, resourceSection, indents), namespaceXmlList)); namespaceXmlList.clear(); } } if (chunk.getChunkType() == ChunkType.START_TAG) { indents++; } } }
public String toXML() { StringBuilder xmlStrbui = new StringBuilder(); xmlStrbui.append(header.toXML(stringSection, resourceSection, 0)).append('\n'); Iterator<Chunk> iterator = chunks.iterator(); int indents = 0; List<String> namespaceXmlList = new ArrayList<String>(); while (iterator.hasNext()) { Chunk chunk = iterator.next(); if (chunk.getChunkType() == ChunkType.END_TAG) { indents--; } if (chunk.getChunkType() == ChunkType.START_NAMESPACE) { namespaceXmlList.add(chunk.toXML(stringSection, resourceSection, indents)); } else if (chunk.getChunkType() == ChunkType.END_NAMESPACE) { // ignore } else { if (namespaceXmlList.isEmpty()) { xmlStrbui.append(chunk.toXML(stringSection, resourceSection, indents)).append('\n'); } else { xmlStrbui.append(appendNameSpace(chunk.toXML(stringSection, resourceSection, indents), namespaceXmlList)).append('\n'); namespaceXmlList.clear(); } } if (chunk.getChunkType() == ChunkType.START_TAG) { indents++; } } return xmlStrbui.toString(); }
@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"); } }
@Test public void testInsertApplicationAttribute() 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); StartTag startTag = underTest.getApplicationTag(); assertTrue(startTag.getAttributes().contains(attribute)); }
@Test public void testPrinting() throws IOException { InputStream testStream = this.getClass().getClassLoader().getResourceAsStream(issue8); underTest = new AXMLResource(testStream); underTest.print(); }
public AXMLResource(InputStream stream) throws IOException { chunks = new LinkedHashSet<Chunk>(); if (!read(stream)) { throw new IOException(); } }
@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); } }
@Before public void setUp() { underTest = new AXMLResource(); }
public void print() { log("%s", header.toXML(stringSection, resourceSection, 0)); Iterator<Chunk> iterator = chunks.iterator(); int indents = 0; List<String> namespaceXmlList = new ArrayList<String>(); while (iterator.hasNext()) { Chunk chunk = iterator.next(); if (chunk.getChunkType() == ChunkType.END_TAG) { indents--; } if (chunk.getChunkType() == ChunkType.START_NAMESPACE) { namespaceXmlList.add(chunk.toXML(stringSection, resourceSection, indents)); } else if (chunk.getChunkType() == ChunkType.END_NAMESPACE) { // ignore } else { if (namespaceXmlList.isEmpty()) { log("%s", chunk.toXML(stringSection, resourceSection, indents)); } else { log("%s", appendNameSpace(chunk.toXML(stringSection, resourceSection, indents), namespaceXmlList)); namespaceXmlList.clear(); } } if (chunk.getChunkType() == ChunkType.START_TAG) { indents++; } } }
public String toXML() { StringBuilder xmlStrbui = new StringBuilder(); xmlStrbui.append(header.toXML(stringSection, resourceSection, 0)).append('\n'); Iterator<Chunk> iterator = chunks.iterator(); int indents = 0; List<String> namespaceXmlList = new ArrayList<String>(); while (iterator.hasNext()) { Chunk chunk = iterator.next(); if (chunk.getChunkType() == ChunkType.END_TAG) { indents--; } if (chunk.getChunkType() == ChunkType.START_NAMESPACE) { namespaceXmlList.add(chunk.toXML(stringSection, resourceSection, indents)); } else if (chunk.getChunkType() == ChunkType.END_NAMESPACE) { // ignore } else { if (namespaceXmlList.isEmpty()) { xmlStrbui.append(chunk.toXML(stringSection, resourceSection, indents)).append('\n'); } else { xmlStrbui.append(appendNameSpace(chunk.toXML(stringSection, resourceSection, indents), namespaceXmlList)).append('\n'); namespaceXmlList.clear(); } } if (chunk.getChunkType() == ChunkType.START_TAG) { indents++; } } return xmlStrbui.toString(); }