From b896b4491abf2d72e62a08ec6efa0501ee55418b Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Fri, 27 Nov 2020 17:40:07 -0500 Subject: [PATCH] fix: prevent NPE during decode app with no matching resId for resource --- .../androlib/res/decoder/AXmlResourceParser.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 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 3d0c639a..9f70da76 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 @@ -21,6 +21,7 @@ import android.util.TypedValue; import brut.androlib.AndrolibException; import brut.androlib.res.data.ResID; import brut.androlib.res.xml.ResXmlEncoders; +import brut.common.BrutException; import brut.util.ExtDataInput; import com.google.common.io.LittleEndianDataInputStream; import java.io.DataInput; @@ -339,15 +340,15 @@ public class AXmlResourceParser implements XmlResourceParser { // some attributes will return "", we must rely on the resource_id and refer to the frameworks // to match the resource id to the name. ex: 0x101021C = versionName - if (value.length() != 0 && !android_ns.equals(getAttributeNamespace(index))) { - return value; - } else { + if (value.length() == 0 || android_ns.equals(getAttributeNamespace(index))) { try { - value = mAttrDecoder.decodeManifestAttr(getAttributeNameResource(index)); - } catch (AndrolibException e) { - } - return value; + int resourceId = getAttributeNameResource(index); + if (resourceId != 0) { + value = mAttrDecoder.decodeManifestAttr(getAttributeNameResource(index)); + } + } catch (AndrolibException | NullPointerException e) { } } + return value; } @Override