From 4249dde7cc5539e638927100f5ae6e1c4bdaa773 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Tue, 7 Jul 2015 14:42:43 -0600 Subject: [PATCH] Propagate the raw int values to callers --- .../androlib/res/data/value/ResBoolValue.java | 4 +-- .../androlib/res/data/value/ResFileValue.java | 5 +-- .../res/data/value/ResFloatValue.java | 4 +-- .../res/data/value/ResIntBasedValue.java | 32 +++++++++++++++++++ .../androlib/res/data/value/ResIntValue.java | 2 +- .../res/data/value/ResScalarValue.java | 5 +-- .../res/data/value/ResStringValue.java | 8 ++--- .../res/data/value/ResValueFactory.java | 12 +++---- .../androlib/res/decoder/ARSCDecoder.java | 16 +++++----- .../androlib/res/decoder/ResFileDecoder.java | 2 +- 10 files changed, 62 insertions(+), 28 deletions(-) create mode 100644 brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntBasedValue.java diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResBoolValue.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResBoolValue.java index 51b6bfb1..8b824286 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResBoolValue.java +++ b/brut.apktool/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 { private final boolean mValue; - public ResBoolValue(boolean value, String rawValue) { - super("bool", rawValue); + public ResBoolValue(boolean value, int rawIntValue, String rawValue) { + super("bool", rawIntValue, rawValue); this.mValue = value; } diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFileValue.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFileValue.java index 56f95643..c11c68f5 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFileValue.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFileValue.java @@ -21,10 +21,11 @@ import brut.androlib.AndrolibException; /** * @author Ryszard Wiśniewski */ -public class ResFileValue extends ResValue { +public class ResFileValue extends ResIntBasedValue { private final String mPath; - public ResFileValue(String path) { + public ResFileValue(String path, int rawIntValue) { + super(rawIntValue); this.mPath = path; } diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFloatValue.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFloatValue.java index 8e1c6283..142a0cb3 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFloatValue.java +++ b/brut.apktool/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, String rawValue) { - super("float", rawValue); + public ResFloatValue(float value, int rawIntValue, String rawValue) { + super("float", rawIntValue, rawValue); this.mValue = value; } diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntBasedValue.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntBasedValue.java new file mode 100644 index 00000000..55602b32 --- /dev/null +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntBasedValue.java @@ -0,0 +1,32 @@ +/** + * Copyright 2014 Ryszard Wiśniewski + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package brut.androlib.res.data.value; + +/** + * @author Matt Mastracci + */ +public class ResIntBasedValue extends ResValue { + private int mRawIntValue; + + protected ResIntBasedValue(int rawIntValue) { + mRawIntValue = rawIntValue; + } + + public int getRawIntValue() { + return mRawIntValue; + } +} diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntValue.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntValue.java index 4eb84286..d7cb0e8a 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntValue.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResIntValue.java @@ -32,7 +32,7 @@ public class ResIntValue extends ResScalarValue { } public ResIntValue(int value, String rawValue, String type) { - super(type, rawValue); + super(type, value, rawValue); this.mValue = value; } diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResScalarValue.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResScalarValue.java index e3d5fb3f..08f3b0ad 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResScalarValue.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResScalarValue.java @@ -27,12 +27,13 @@ import org.xmlpull.v1.XmlSerializer; /** * @author Ryszard Wiśniewski */ -public abstract class ResScalarValue extends ResValue implements +public abstract class ResScalarValue extends ResIntBasedValue implements ResXmlEncodable, ResValuesXmlSerializable { protected final String mType; protected final String mRawValue; - protected ResScalarValue(String type, String rawValue) { + protected ResScalarValue(String type, int rawIntValue, String rawValue) { + super(rawIntValue); mType = type; mRawValue = rawValue; } diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStringValue.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStringValue.java index 01652298..faf00dad 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStringValue.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStringValue.java @@ -27,12 +27,12 @@ import org.xmlpull.v1.XmlSerializer; */ public class ResStringValue extends ResScalarValue { - public ResStringValue(String value) { - this(value, "string"); + public ResStringValue(String value, int rawValue) { + this(value, rawValue, "string"); } - public ResStringValue(String value, String type) { - super(type, value); + public ResStringValue(String value, int rawValue, String type) { + super(type, rawValue, value); } @Override diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java index c0c5177e..43a3f2e5 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java @@ -41,15 +41,15 @@ public class ResValueFactory { case TypedValue.TYPE_ATTRIBUTE: return newReference(value, rawValue, true); case TypedValue.TYPE_STRING: - return new ResStringValue(rawValue); + return new ResStringValue(rawValue, value); case TypedValue.TYPE_FLOAT: - return new ResFloatValue(Float.intBitsToFloat(value), rawValue); + return new ResFloatValue(Float.intBitsToFloat(value), value, rawValue); case TypedValue.TYPE_DIMENSION: return new ResDimenValue(value, rawValue); case TypedValue.TYPE_FRACTION: return new ResFractionValue(value, rawValue); case TypedValue.TYPE_INT_BOOLEAN: - return new ResBoolValue(value != 0, rawValue); + return new ResBoolValue(value != 0, value, rawValue); case TypedValue.TYPE_DYNAMIC_REFERENCE: return newReference(value, rawValue); } @@ -66,11 +66,11 @@ public class ResValueFactory { throw new AndrolibException("Invalid value type: " + type); } - public ResValue factory(String value) { + public ResIntBasedValue factory(String value, int rawValue) { if (value.startsWith("res/")) { - return new ResFileValue(value); + return new ResFileValue(value, rawValue); } - return new ResStringValue(value); + return new ResStringValue(value, rawValue); } public ResBagValue bagFactory(int parent, diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java index 447875bb..a8046770 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java @@ -203,7 +203,7 @@ public class ARSCDecoder { ResValue value = (flags & ENTRY_FLAG_COMPLEX) == 0 ? readValue() : readComplexEntry(); if (mType.isString() && value instanceof ResFileValue) { - value = new ResStringValue(value.toString()); + value = new ResStringValue(value.toString(), ((ResFileValue) value).getRawIntValue()); } if (mConfig == null) { return; @@ -232,17 +232,17 @@ public class ARSCDecoder { ResValueFactory factory = mPkg.getValueFactory(); Duo[] items = new Duo[count]; - ResValue resValue; + ResIntBasedValue resValue; int resId; for (int i = 0; i < count; i++) { resId = mIn.readInt(); resValue = readValue(); - try { + if (resValue instanceof ResScalarValue) { items[i] = new Duo(resId, (ResScalarValue) resValue); - } catch (ClassCastException ex) { - resValue = new ResStringValue(resValue.toString()); + } else { + resValue = new ResStringValue(resValue.toString(), resValue.getRawIntValue()); items[i] = new Duo(resId, (ResScalarValue) resValue); } } @@ -250,14 +250,14 @@ public class ARSCDecoder { return factory.bagFactory(parent, items); } - private ResValue readValue() throws IOException, AndrolibException { + private ResIntBasedValue readValue() throws IOException, AndrolibException { /* size */mIn.skipCheckShort((short) 8); /* zero */mIn.skipCheckByte((byte) 0); byte type = mIn.readByte(); int data = mIn.readInt(); return type == TypedValue.TYPE_STRING - ? mPkg.getValueFactory().factory(mTableStrings.getHTML(data)) + ? mPkg.getValueFactory().factory(mTableStrings.getHTML(data), data) : mPkg.getValueFactory().factory(type, data, null); } @@ -395,7 +395,7 @@ public class ARSCDecoder { mConfig = mPkg.getOrCreateConfig(new ResConfigFlags()); } - ResValue value = new ResBoolValue(false, null); + ResValue value = new ResBoolValue(false, 0, null); ResResource res = new ResResource(mConfig, spec, value); mPkg.addResource(res); diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java index aa75b49b..05d2ab4d 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java @@ -101,7 +101,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, null)); + res.replace(new ResBoolValue(false, 0, null)); } }