Skip to content

Commit 6ac7712

Browse files
committed
fix: prefer res name instead of "guessing" based on ids
1 parent d28e408 commit 6ac7712

File tree

4 files changed

+19
-30
lines changed

4 files changed

+19
-30
lines changed

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/ResTypeSpec.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
public final class ResTypeSpec {
2424

2525
public static final String RES_TYPE_NAME_ARRAY = "array";
26+
public static final String RES_TYPE_NAME_ATTR = "attr";
27+
public static final String RES_TYPE_NAME_ATTR_PRIVATE = "^attr-private";
2628
public static final String RES_TYPE_NAME_PLURALS = "plurals";
29+
public static final String RES_TYPE_NAME_STRING = "string";
2730
public static final String RES_TYPE_NAME_STYLES = "style";
28-
public static final String RES_TYPE_NAME_ATTR = "attr";
2931

3032
private final String mName;
3133
private final Map<String, ResResSpec> mResSpecs = new LinkedHashMap<>();
@@ -46,7 +48,7 @@ public int getId() {
4648
}
4749

4850
public boolean isString() {
49-
return mName.equalsIgnoreCase("string");
51+
return mName.equalsIgnoreCase(RES_TYPE_NAME_STRING);
5052
}
5153

5254
public ResResSpec getResSpec(String name) throws AndrolibException {

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResArrayValue.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,4 @@ public String getType() throws AndrolibException {
9191

9292
private final ResScalarValue[] mItems;
9393
private final String[] AllowedArrayTypes = {"string", "integer"};
94-
95-
public static final int BAG_KEY_ARRAY_START = 0x02000000;
9694
}

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResPluralsValue.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,5 @@ public void serializeToResValuesXml(XmlSerializer serializer,
5959
private final ResScalarValue[] mItems;
6060

6161
public static final int BAG_KEY_PLURALS_START = 0x01000004;
62-
public static final int BAG_KEY_PLURALS_END = 0x01000009;
6362
private static final String[] QUANTITY_MAP = new String[] { "other", "zero", "one", "two", "few", "many" };
6463
}

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,39 +80,29 @@ public ResIntBasedValue factory(String value, int rawValue) {
8080
return new ResStringValue(value, rawValue);
8181
}
8282

83-
public ResBagValue bagFactory(int parent, Duo<Integer, ResScalarValue>[] items, ResTypeSpec resTypeSpec) throws AndrolibException {
83+
public ResBagValue bagFactory(int parent, Duo<Integer, ResScalarValue>[] items, ResTypeSpec resTypeSpec)
84+
throws AndrolibException {
8485
ResReferenceValue parentVal = newReference(parent, null);
8586

8687
if (items.length == 0) {
8788
return new ResBagValue(parentVal);
8889
}
89-
int key = items[0].m1;
90-
if (key == ResAttr.BAG_KEY_ATTR_TYPE) {
91-
return ResAttr.factory(parentVal, items, this, mPackage);
92-
}
93-
9490
String resTypeName = resTypeSpec.getName();
9591

96-
// Android O Preview added an unknown enum for c. This is hardcoded as 0 for now.
97-
if (ResTypeSpec.RES_TYPE_NAME_ARRAY.equals(resTypeName)
98-
|| key == ResArrayValue.BAG_KEY_ARRAY_START || key == 0) {
99-
return new ResArrayValue(parentVal, items);
100-
}
101-
102-
if (ResTypeSpec.RES_TYPE_NAME_PLURALS.equals(resTypeName) ||
103-
(key >= ResPluralsValue.BAG_KEY_PLURALS_START && key <= ResPluralsValue.BAG_KEY_PLURALS_END)) {
104-
return new ResPluralsValue(parentVal, items);
105-
}
106-
107-
if (ResTypeSpec.RES_TYPE_NAME_ATTR.equals(resTypeName)) {
108-
return new ResAttr(parentVal, 0, null, null, null);
109-
}
110-
111-
if (resTypeName.startsWith(ResTypeSpec.RES_TYPE_NAME_STYLES)) {
112-
return new ResStyleValue(parentVal, items, this);
92+
switch (resTypeName) {
93+
case ResTypeSpec.RES_TYPE_NAME_ATTR:
94+
case ResTypeSpec.RES_TYPE_NAME_ATTR_PRIVATE:
95+
return ResAttr.factory(parentVal, items, this, mPackage);
96+
case ResTypeSpec.RES_TYPE_NAME_ARRAY:
97+
return new ResArrayValue(parentVal, items);
98+
case ResTypeSpec.RES_TYPE_NAME_PLURALS:
99+
return new ResPluralsValue(parentVal, items);
100+
default:
101+
if (resTypeName.startsWith(ResTypeSpec.RES_TYPE_NAME_STYLES)) {
102+
return new ResStyleValue(parentVal, items, this);
103+
}
104+
throw new AndrolibException("unsupported res type name for bags. Found: " + resTypeName);
113105
}
114-
115-
throw new AndrolibException("unsupported res type name for bags. Found: " + resTypeName);
116106
}
117107

118108
public ResReferenceValue newReference(int resID, String rawValue) {

0 commit comments

Comments
 (0)