From d0baa841ebd2ce52cf28130453fb763bfc89d045 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Sat, 6 Aug 2016 08:31:58 -0400 Subject: [PATCH] Add support for getting literal values for references in android:scheme - side affect of using public.xml to get constant resource ids - fixes #1097 --- .../brut/androlib/res/xml/ResXmlPatcher.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlPatcher.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlPatcher.java index 1b513f62..5d91e433 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlPatcher.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlPatcher.java @@ -82,6 +82,7 @@ public final class ResXmlPatcher { * @throws AndrolibException */ public static void fixingPublicAttrsInProviderAttributes(File file) throws AndrolibException { + boolean saved = false; if (file.exists()) { try { Document doc = loadDocument(file); @@ -104,12 +105,42 @@ public final class ResXmlPatcher { if (replacement != null) { provider.setNodeValue(replacement); - saveDocument(file, doc); + saved = true; } } } } + // android:scheme + xPath = XPathFactory.newInstance().newXPath(); + expression = xPath.compile("/manifest/application/activity/intent-filter/data"); + + result = expression.evaluate(doc, XPathConstants.NODESET); + nodes = (NodeList) result; + + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + NamedNodeMap attrs = node.getAttributes(); + + if (attrs != null) { + Node provider = attrs.getNamedItem("android:scheme"); + + if (provider != null) { + String reference = provider.getNodeValue(); + String replacement = pullValueFromStrings(file.getParentFile(), reference); + + if (replacement != null) { + provider.setNodeValue(replacement); + saved = true; + } + } + } + } + + if (saved) { + saveDocument(file, doc); + } + } catch (SAXException | ParserConfigurationException | IOException | XPathExpressionException | TransformerException ignored) { }