From e91790e67698597f9ebbb225da69593f6332bbf5 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Sat, 23 Nov 2013 08:34:33 -0600 Subject: [PATCH] correctly handle incorrect type labeled 's --- CHANGES | 1 + .../androlib/res/data/value/ResArrayValue.java | 14 +++++++++----- .../java/brut/androlib/BuildAndDecodeTest.java | 7 +++++++ .../apktool/testapp/res/values-mcc003/arrays.xml | 10 ++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 brut.apktool/apktool-lib/src/test/resources/brut/apktool/testapp/res/values-mcc003/arrays.xml diff --git a/CHANGES b/CHANGES index a1451cb6..b2f03335 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,7 @@ v2.0.0 (TBA) -Fixed (issue #524) - INSTALL_FAILED_DEXOPT fix (JesusFreke) -Fixed (issue #473) - multiple package frameworks are treated correctly. -Fixed (issue #531) - JAR disassembling borking is fixed +-Fixed (issue #550) - Corectly labels incorrect type handling of -Added output to list Apktool version to help debugging. -Updated known bytes for configurations to 38 (from addition of layout direction) -Fixed NPE when handling odex apks even with --no-src specified. (Thanks Rodrigo Chiossi) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResArrayValue.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResArrayValue.java index 39444189..f1aaf94b 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResArrayValue.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResArrayValue.java @@ -21,6 +21,8 @@ import brut.androlib.res.data.ResResource; import brut.androlib.res.xml.ResValuesXmlSerializable; import brut.util.Duo; import java.io.IOException; +import java.util.Arrays; + import org.xmlpull.v1.XmlSerializer; /** @@ -49,9 +51,6 @@ public class ResArrayValue extends ResBagValue implements ResResource res) throws IOException, AndrolibException { String type = getType(); type = (type == null ? "" : type + "-") + "array"; - if ("reference-array".equals(type)) { - type = "string-array"; - } serializer.startTag(null, type); serializer.attribute(null, "name", res.getResSpec().getName()); for (int i = 0; i < mItems.length; i++) { @@ -71,19 +70,24 @@ public class ResArrayValue extends ResBagValue implements if (mItems[i].encodeAsResXmlItemValue().startsWith("@string")) { return "string"; - } else if (mItems[i].encodeAsResXmlItemValue().startsWith( - "@drawable")) { + } else if (mItems[i].encodeAsResXmlItemValue().startsWith("@drawable")) { return null; + } else if (mItems[i].encodeAsResXmlItemValue().startsWith("@integer")) { + return "integer"; } else if (!"string".equals(type) && !"integer".equals(type)) { return null; } else if (!type.equals(mItems[i].getType())) { return null; } } + if (!Arrays.asList(AllowedArrayTypes).contains(type)) { + return "string"; + } return type; } private final ResScalarValue[] mItems; + private final String AllowedArrayTypes[] = {"string", "integer"}; public static final int BAG_KEY_ARRAY_START = 0x02000000; } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java index ccc78c7c..3e74379c 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java @@ -23,6 +23,8 @@ import java.io.*; import java.util.HashMap; import java.util.Set; import java.util.logging.Logger; + +import com.sun.corba.se.impl.orb.ParserTable; import org.custommonkey.xmlunit.*; import org.junit.*; import static org.junit.Assert.*; @@ -76,7 +78,12 @@ public class BuildAndDecodeTest { @Test public void valuesArraysTest() throws BrutException { compareValuesFiles("values-mcc001/arrays.xml"); + } + + @Test + public void valuesArraysCastingTest() throws BrutException { compareValuesFiles("values-mcc002/arrays.xml"); + compareValuesFiles("values-mcc003/arrays.xml"); } @Test diff --git a/brut.apktool/apktool-lib/src/test/resources/brut/apktool/testapp/res/values-mcc003/arrays.xml b/brut.apktool/apktool-lib/src/test/resources/brut/apktool/testapp/res/values-mcc003/arrays.xml new file mode 100644 index 00000000..3d81bdd5 --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/resources/brut/apktool/testapp/res/values-mcc003/arrays.xml @@ -0,0 +1,10 @@ + + + + 3.0in + + + 65.0% + 65% + + \ No newline at end of file