Skip to content

Commit d4ec44d

Browse files
authored
Prevent loading from resource pool if type is not a resolveable resource (#3187)
* perf: prefer the shifted resId vs expensive package calls * fix: only lookup values if reference/value
1 parent 2610033 commit d4ec44d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/AXmlResourceParser.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,14 @@ public String getAttributeValue(int index) {
387387
if (mAttrDecoder != null) {
388388
try {
389389
String stringBlockValue = valueRaw == -1 ? null : ResXmlEncoders.escapeXmlChars(mStringBlock.getString(valueRaw));
390-
String resourceMapValue = mAttrDecoder.decodeFromResourceId(valueData);
390+
String resourceMapValue = null;
391+
392+
// Ensure we only track down obfuscated values for reference/attribute type values. Otherwise we might
393+
// spam lookups against resource table for invalid ids.
394+
if (valueType == TypedValue.TYPE_REFERENCE || valueType == TypedValue.TYPE_DYNAMIC_REFERENCE ||
395+
valueType == TypedValue.TYPE_ATTRIBUTE || valueType == TypedValue.TYPE_DYNAMIC_ATTRIBUTE) {
396+
resourceMapValue = mAttrDecoder.decodeFromResourceId(valueData);
397+
}
391398
String value = stringBlockValue;
392399

393400
if (stringBlockValue != null && resourceMapValue != null) {

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResAttrDecoder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ public String decodeFromResourceId(int attrResId)
4646
throws AndrolibException {
4747

4848
if (attrResId != 0) {
49-
ResID resId = new ResID(attrResId);
50-
5149
try {
52-
ResResSpec resResSpec = mResTable.getResSpec(resId);
50+
ResResSpec resResSpec = mResTable.getResSpec(attrResId);
5351
if (resResSpec != null) {
5452
return resResSpec.getName();
5553
}

0 commit comments

Comments
 (0)