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 c1581340..8fd124c4 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 @@ -197,6 +197,41 @@ public final class ResXmlPatcher { return null; } + /** + * Finds key in integers.xml file and returns text value + * + * @param directory Root directory of apk + * @param key Integer reference (ie @integer/foo) + * @return String|null + * @throws AndrolibException + */ + public static String pullValueFromIntegers(File directory, String key) throws AndrolibException { + if (key == null || ! key.contains("@")) { + return null; + } + + File file = new File(directory, "/res/values/integers.xml"); + key = key.replace("@integer/", ""); + + if (file.exists()) { + try { + Document doc = loadDocument(file); + XPath xPath = XPathFactory.newInstance().newXPath(); + XPathExpression expression = xPath.compile("/resources/integer[@name=" + '"' + key + "\"]/text()"); + + Object result = expression.evaluate(doc, XPathConstants.STRING); + + if (result != null) { + return (String) result; + } + + } catch (SAXException | ParserConfigurationException | IOException | XPathExpressionException ignored) { + } + } + + return null; + } + /** * Removes attributes like "versionCode" and "versionName" from file. *