diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResAttr.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResAttr.java index 96944f9f..fb8dcc2f 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResAttr.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResAttr.java @@ -99,7 +99,7 @@ public class ResAttr extends ResBagValue implements ResValuesXmlSerializable { int resId = items[i].m1; pkg.addSynthesizedRes(resId); attrItems[j++] = new Duo( - factory.newReference(resId), (ResIntValue) items[i].m2); + factory.newReference(resId, null), (ResIntValue) items[i].m2); } switch (type & 0xff0000) { case TYPE_ENUM: diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResBoolValue.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResBoolValue.java index 5e45179e..13afe32e 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResBoolValue.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResBoolValue.java @@ -22,8 +22,8 @@ package brut.androlib.res.data.value; public class ResBoolValue extends ResScalarValue implements ResValuesXmlSerializable { private final boolean mValue; - public ResBoolValue(boolean value) { - super("bool"); + public ResBoolValue(boolean value, String rawValue) { + super("bool", rawValue); this.mValue = value; } diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResColorValue.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResColorValue.java index 574b2707..0cb89a44 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResColorValue.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResColorValue.java @@ -20,8 +20,8 @@ package brut.androlib.res.data.value; * @author Ryszard Wiśniewski */ public class ResColorValue extends ResIntValue { - public ResColorValue(int value) { - super(value, "color"); + public ResColorValue(int value, String rawValue) { + super(value, rawValue, "color"); } @Override diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResDimenValue.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResDimenValue.java index f2752700..ceaca75b 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResDimenValue.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResDimenValue.java @@ -26,8 +26,8 @@ import org.xmlpull.v1.XmlSerializer; * @author Ryszard Wiśniewski */ public class ResDimenValue extends ResIntValue { - public ResDimenValue(int value) { - super(value, "dimen"); + public ResDimenValue(int value, String rawValue) { + super(value, rawValue, "dimen"); } @Override diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFloatValue.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFloatValue.java index cec3ebfb..5a63e1ec 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFloatValue.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFloatValue.java @@ -22,8 +22,8 @@ package brut.androlib.res.data.value; public class ResFloatValue extends ResScalarValue { private final float mValue; - public ResFloatValue(float value) { - super("float"); + public ResFloatValue(float value, String rawValue) { + super("float", rawValue); this.mValue = value; } diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFractionValue.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFractionValue.java index 6f18e795..9b5b465e 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFractionValue.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFractionValue.java @@ -23,8 +23,8 @@ import brut.androlib.AndrolibException; * @author Ryszard Wiśniewski */ public class ResFractionValue extends ResIntValue { - public ResFractionValue(int value) { - super(value, "fraction"); + public ResFractionValue(int value, String rawValue) { + super(value, rawValue, "fraction"); } @Override diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntValue.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntValue.java index 5fc7c8ff..56ccbd45 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntValue.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntValue.java @@ -24,12 +24,12 @@ import brut.androlib.AndrolibException; public class ResIntValue extends ResScalarValue implements ResValuesXmlSerializable { protected final int mValue; - public ResIntValue(int value) { - this(value, "integer"); + public ResIntValue(int value, String rawValue) { + this(value, rawValue, "integer"); } - public ResIntValue(int value, String type) { - super(type); + public ResIntValue(int value, String rawValue, String type) { + super(type, rawValue); this.mValue = value; } diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResReferenceValue.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResReferenceValue.java index 7d8e979c..cae0cf7b 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResReferenceValue.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResReferenceValue.java @@ -27,12 +27,13 @@ public class ResReferenceValue extends ResIntValue { private final ResPackage mPackage; private final boolean mTheme; - public ResReferenceValue(ResPackage package_, int value) { - this(package_, value, false); + public ResReferenceValue(ResPackage package_, int value, String rawValue) { + this(package_, value, rawValue, false); } - public ResReferenceValue(ResPackage package_, int value, boolean theme) { - super(value, "reference"); + public ResReferenceValue(ResPackage package_, int value, String rawValue, + boolean theme) { + super(value, rawValue, "reference"); mPackage = package_; mTheme = theme; } diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResScalarValue.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResScalarValue.java index 5b141090..aec3fbde 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResScalarValue.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResScalarValue.java @@ -28,9 +28,11 @@ import org.xmlpull.v1.XmlSerializer; public abstract class ResScalarValue extends ResValue implements ResXmlEncodable, ResValuesXmlSerializable { protected final String mType; + protected final String mRawValue; - protected ResScalarValue(String type) { + protected ResScalarValue(String type, String rawValue) { mType = type; + mRawValue = rawValue; } public abstract String toResXmlFormat() throws AndrolibException; diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStringValue.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStringValue.java index abe9a17b..4364a9fc 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStringValue.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStringValue.java @@ -30,7 +30,7 @@ public class ResStringValue extends ResScalarValue } public ResStringValue(String value, String type) { - super(type); + super(type, value); this.mValue = value; } diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStyleValue.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStyleValue.java index 0cc880a7..c7e6b279 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStyleValue.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStyleValue.java @@ -34,7 +34,7 @@ public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializab mItems = new Duo[items.length]; for (int i = 0; i < items.length; i++) { mItems[i] = new Duo( - factory.newReference(items[i].m1), items[i].m2); + factory.newReference(items[i].m1, null), items[i].m2); } } diff --git a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java index a1454c19..b67484bf 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java +++ b/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java @@ -31,30 +31,30 @@ public class ResValueFactory { this.mPackage = pakage_; } - public ResScalarValue factory(int type, int value) + public ResScalarValue factory(int type, int value, String rawValue) throws AndrolibException { switch (type) { case TypedValue.TYPE_REFERENCE: - return newReference(value); + return newReference(value, rawValue); case TypedValue.TYPE_ATTRIBUTE: - return newReference(value, true); + return newReference(value, rawValue, true); case TypedValue.TYPE_FLOAT: - return new ResFloatValue(Float.intBitsToFloat(value)); + return new ResFloatValue(Float.intBitsToFloat(value), rawValue); case TypedValue.TYPE_DIMENSION: - return new ResDimenValue(value); + return new ResDimenValue(value, rawValue); case TypedValue.TYPE_FRACTION: - return new ResFractionValue(value); + return new ResFractionValue(value, rawValue); case TypedValue.TYPE_INT_BOOLEAN: - return new ResBoolValue(value != 0); + return new ResBoolValue(value != 0, rawValue); } if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) { - return new ResColorValue(value); + return new ResColorValue(value, rawValue); } if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) { - return new ResIntValue(value); + return new ResIntValue(value, rawValue); } throw new AndrolibException("Invalid value type: "+ type); @@ -69,7 +69,7 @@ public class ResValueFactory { public ResBagValue bagFactory(int parent, Duo[] items) throws AndrolibException { - ResReferenceValue parentVal = newReference(parent); + ResReferenceValue parentVal = newReference(parent, null); if (items.length == 0) { return new ResBagValue(parentVal); @@ -88,11 +88,12 @@ public class ResValueFactory { return new ResStyleValue(parentVal, items, this); } - public ResReferenceValue newReference(int resID) { - return newReference(resID, false); + public ResReferenceValue newReference(int resID, String rawValue) { + return newReference(resID, rawValue, false); } - public ResReferenceValue newReference(int resID, boolean theme) { - return new ResReferenceValue(mPackage, resID, theme); + public ResReferenceValue newReference(int resID, String rawValue, + boolean theme) { + return new ResReferenceValue(mPackage, resID, rawValue, theme); } } diff --git a/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java b/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java index 85cff8ca..239059d4 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java +++ b/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java @@ -221,7 +221,7 @@ public class ARSCDecoder { return type == TypedValue.TYPE_STRING ? mPkg.getValueFactory().factory(mTableStrings.getHTML(data)) : - mPkg.getValueFactory().factory(type, data); + mPkg.getValueFactory().factory(type, data, null); } private ResConfigFlags readConfigFlags() throws IOException, AndrolibException { @@ -300,7 +300,7 @@ public class ARSCDecoder { mPkg.addResSpec(spec); mType.addResSpec(spec); - ResValue value = new ResBoolValue(false); + ResValue value = new ResBoolValue(false, null); ResResource res = new ResResource( mPkg.getOrCreateConfig(new ResConfigFlags()), spec, value); mPkg.addResource(res); diff --git a/apktool-lib/src/main/java/brut/androlib/res/decoder/AXmlResourceParser.java b/apktool-lib/src/main/java/brut/androlib/res/decoder/AXmlResourceParser.java index d989cf29..fea7132e 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/decoder/AXmlResourceParser.java +++ b/apktool-lib/src/main/java/brut/androlib/res/decoder/AXmlResourceParser.java @@ -308,20 +308,13 @@ public class AXmlResourceParser implements XmlResourceParser { int offset = getAttributeOffset(index); int valueType = m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE]; int valueData = m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA]; - int valueString = m_attributes[offset + ATTRIBUTE_IX_VALUE_STRING]; + int valueRaw = m_attributes[offset + ATTRIBUTE_IX_VALUE_STRING]; - if (mAttrDecoder != null && ( - valueString == -1 - || valueType == TypedValue.TYPE_REFERENCE - || valueType == TypedValue.TYPE_ATTRIBUTE - || ( - valueType >= TypedValue.TYPE_FIRST_COLOR_INT - && valueType <= TypedValue.TYPE_LAST_COLOR_INT - ) - )) { + if (mAttrDecoder != null) { try { return mAttrDecoder.decode(valueType, valueData, - getAttributeNameResource(index)); + valueRaw == -1 ? null : m_strings.getString(valueRaw), + getAttributeNameResource(index)); } catch (AndrolibException ex) { setFirstError(ex); LOGGER.log(Level.WARNING, String.format( @@ -333,11 +326,6 @@ public class AXmlResourceParser implements XmlResourceParser { } } - if (valueString != -1) { - return AndrolibResources.escapeTextForResXml( - m_strings.getString(valueString)); - } - return TypedValue.coerceToString(valueType, valueData); } diff --git a/apktool-lib/src/main/java/brut/androlib/res/decoder/ResAttrDecoder.java b/apktool-lib/src/main/java/brut/androlib/res/decoder/ResAttrDecoder.java index b2a4cb2c..df0b5ea3 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/decoder/ResAttrDecoder.java +++ b/apktool-lib/src/main/java/brut/androlib/res/decoder/ResAttrDecoder.java @@ -25,10 +25,10 @@ import brut.androlib.res.data.value.ResScalarValue; * @author Ryszard Wiśniewski */ public class ResAttrDecoder { - public String decode(int type, int value, int attrResId) + public String decode(int type, int value, String rawValue, int attrResId) throws AndrolibException { ResScalarValue resValue = mCurrentPackage.getValueFactory() - .factory(type, value); + .factory(type, value, rawValue); if (attrResId == 0) { return resValue.toResXmlFormat(); } diff --git a/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java b/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java index dc1cab4c..57b2125f 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java +++ b/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java @@ -88,7 +88,7 @@ public class ResFileDecoder { LOGGER.log(Level.SEVERE, String.format( "Could not decode file, replacing by FALSE value: %s", inFileName, outFileName), ex); - res.replace(new ResBoolValue(false)); + res.replace(new ResBoolValue(false, null)); } }