diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java index 4ee8f2af..59abe334 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java @@ -136,12 +136,9 @@ public class ResourcesDecoder { private void decodeManifest(ResTable resTable, ExtFile apkFile, File outDir) throws AndrolibException { - AXmlResourceParser axmlParser = new AndroidManifestResourceParser(); - ResAttrDecoder attrDecoder = new ResAttrDecoder(); - attrDecoder.setResTable(resTable); - axmlParser.setAttrDecoder(attrDecoder); - + AXmlResourceParser axmlParser = new AndroidManifestResourceParser(resTable); XmlPullStreamDecoder fileDecoder = new XmlPullStreamDecoder(axmlParser, getResXmlSerializer()); + Directory inApk, out; try { inApk = apkFile.getDirectory(); @@ -216,10 +213,15 @@ public class ResourcesDecoder { private void decodeResources(ResTable resTable, ExtFile apkFile, File outDir) throws AndrolibException { - Duo duo = getResFileDecoder(); - ResFileDecoder fileDecoder = duo.m1; - ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder(); - attrDecoder.setResTable(resTable); + + ResStreamDecoderContainer decoders = new ResStreamDecoderContainer(); + decoders.setDecoder("raw", new ResRawStreamDecoder()); + decoders.setDecoder("9patch", new Res9patchStreamDecoder()); + + AXmlResourceParser axmlParser = new AXmlResourceParser(resTable); + decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser, getResXmlSerializer())); + + ResFileDecoder fileDecoder = new ResFileDecoder(decoders); Directory in, out; try { @@ -245,24 +247,12 @@ public class ResourcesDecoder { generatePublicXml(pkg, out, xmlSerializer); } - AndrolibException decodeError = duo.m2.getFirstError(); + AndrolibException decodeError = axmlParser.getFirstError(); if (decodeError != null) { throw decodeError; } } - private Duo getResFileDecoder() { - ResStreamDecoderContainer decoders = new ResStreamDecoderContainer(); - decoders.setDecoder("raw", new ResRawStreamDecoder()); - decoders.setDecoder("9patch", new Res9patchStreamDecoder()); - - AXmlResourceParser axmlParser = new AXmlResourceParser(); - axmlParser.setAttrDecoder(new ResAttrDecoder()); - decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser, getResXmlSerializer())); - - return new Duo<>(new ResFileDecoder(decoders), axmlParser); - } - private void generateValuesFile(ResValuesFile valuesFile, Directory out, ExtXmlSerializer serial) throws AndrolibException { try { 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 4058858c..6af01130 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 @@ -20,6 +20,7 @@ import android.content.res.XmlResourceParser; import android.util.TypedValue; import brut.androlib.exceptions.AndrolibException; import brut.androlib.res.data.ResID; +import brut.androlib.res.data.ResTable; import brut.androlib.res.data.arsc.ARSCHeader; import brut.androlib.res.data.axml.NamespaceStack; import brut.androlib.res.xml.ResXmlEncoders; @@ -44,8 +45,9 @@ import java.util.logging.Logger; */ public class AXmlResourceParser implements XmlResourceParser { - public AXmlResourceParser() { + public AXmlResourceParser(ResTable resTable) { resetEventInfo(); + setAttrDecoder(new ResAttrDecoder(resTable)); } public AndrolibException getFirstError() { diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/AndroidManifestResourceParser.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/AndroidManifestResourceParser.java index 4cceb565..64562b4c 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/AndroidManifestResourceParser.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/AndroidManifestResourceParser.java @@ -17,6 +17,7 @@ package brut.androlib.res.decoder; import android.util.TypedValue; +import brut.androlib.res.data.ResTable; import java.util.regex.Pattern; @@ -25,6 +26,10 @@ import java.util.regex.Pattern; */ public class AndroidManifestResourceParser extends AXmlResourceParser { + public AndroidManifestResourceParser(ResTable resTable) { + super(resTable); + } + /** * Pattern for matching numeric string meta-data values. aapt automatically infers the * type for a manifest meta-data value based on the string in the unencoded XML. However, diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResAttrDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResAttrDecoder.java index 8c450212..20d5066b 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResAttrDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResAttrDecoder.java @@ -26,6 +26,11 @@ import brut.androlib.res.data.value.ResAttr; import brut.androlib.res.data.value.ResScalarValue; public class ResAttrDecoder { + + public ResAttrDecoder(ResTable resTable) { + mResTable = resTable; + } + public String decode(int type, int value, String rawValue, int attrResId) throws AndrolibException { ResScalarValue resValue = mResTable.getCurrentResPackage().getValueFactory().factory(type, value, rawValue);