From fb6cd883c03dbabc343fe0625217d84eebbc3e9a Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Sun, 13 Aug 2023 13:46:47 -0400 Subject: [PATCH] refactor: split out string block vs res table string (#3267) --- .../res/decoder/AXmlResourceParser.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/AXmlResourceParser.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/AXmlResourceParser.java index a22072b2..a2e01d40 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/AXmlResourceParser.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/AXmlResourceParser.java @@ -407,28 +407,13 @@ public class AXmlResourceParser implements XmlResourceParser { String stringBlockValue = valueRaw == -1 ? null : ResXmlEncoders.escapeXmlChars(mStringBlock.getString(valueRaw)); String resourceMapValue = null; - // Ensure we only track down obfuscated values for reference/attribute type values. Otherwise we might + // Ensure we only track down obfuscated values for reference/attribute type values. Otherwise, we might // spam lookups against resource table for invalid ids. if (valueType == TypedValue.TYPE_REFERENCE || valueType == TypedValue.TYPE_DYNAMIC_REFERENCE || valueType == TypedValue.TYPE_ATTRIBUTE || valueType == TypedValue.TYPE_DYNAMIC_ATTRIBUTE) { resourceMapValue = decodeFromResourceId(valueData); } - String value = stringBlockValue; - - if (stringBlockValue != null && resourceMapValue != null) { - int slashPos = stringBlockValue.lastIndexOf("/"); - int colonPos = stringBlockValue.lastIndexOf(":"); - - // Handle a value with a format of "@yyy/xxx", but avoid "@yyy/zzz:xxx" - if (slashPos != -1) { - if (colonPos == -1) { - String type = stringBlockValue.substring(0, slashPos); - value = type + "/" + resourceMapValue; - } - } else if (! stringBlockValue.equals(resourceMapValue)) { - value = resourceMapValue; - } - } + String value = getPreferredString(stringBlockValue, resourceMapValue); // try to decode from resource table int attrResId = getAttributeNameResource(index); @@ -662,6 +647,26 @@ public class AXmlResourceParser implements XmlResourceParser { return -1; } + private static String getPreferredString(String stringBlockValue, String resourceMapValue) { + String value = stringBlockValue; + + if (stringBlockValue != null && resourceMapValue != null) { + int slashPos = stringBlockValue.lastIndexOf("/"); + int colonPos = stringBlockValue.lastIndexOf(":"); + + // Handle a value with a format of "@yyy/xxx", but avoid "@yyy/zzz:xxx" + if (slashPos != -1) { + if (colonPos == -1) { + String type = stringBlockValue.substring(0, slashPos); + value = type + "/" + resourceMapValue; + } + } else if (! stringBlockValue.equals(resourceMapValue)) { + value = resourceMapValue; + } + } + return value; + } + private void resetEventInfo() { mEvent = -1; mLineNumber = -1;