Skip to content

Commit 65dd848

Browse files
authored
fix: validate type names (#4113)
1 parent 2b28180 commit 65dd848

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResDecoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ private void generateValuesXmls(ResPackage pkg, Directory outDir, ResXmlSerializ
141141
List<ResEntry> entries = mapEntry.getValue();
142142
entries.sort(Comparator.comparing(ResEntry::getResId));
143143

144-
String outFileName = "res/values" + qualifiers + "/"
145-
+ (typeName.endsWith("s") ? typeName : typeName + "s") + ".xml";
144+
String outFileName = "res/values" + qualifiers + "/" + (typeName.endsWith("s") ? typeName
145+
: typeName.equals("^attr-private") ? "attrs-private" : typeName + "s") + ".xml";
146146
try (OutputStream out = outDir.getFileOutput(outFileName)) {
147147
serial.setOutput(out, null);
148148
serial.startDocument(null, null);

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,40 @@ public ResTypeSpec(ResPackage pkg, int id, String name) {
4444
assert pkg != null && id > 0 && name != null;
4545
mPackage = pkg;
4646
mId = id;
47-
mName = name;
47+
// Some apps may have obfuscated or malicious type names.
48+
mName = isValidTypeName(name) ? name : String.format("invalid%02X", id);
49+
}
50+
51+
private static boolean isValidTypeName(String name) {
52+
switch (name) {
53+
case "anim":
54+
case "animator":
55+
case "array":
56+
case "attr":
57+
case "^attr-private":
58+
case "bool":
59+
case "color":
60+
case "dimen":
61+
case "drawable":
62+
case "font":
63+
case "fraction":
64+
case "id":
65+
case "integer":
66+
case "interpolator":
67+
case "layout":
68+
case "menu":
69+
case "mipmap":
70+
case "navigation":
71+
case "plurals":
72+
case "raw":
73+
case "string":
74+
case "style":
75+
case "transition":
76+
case "xml":
77+
return true;
78+
default:
79+
return false;
80+
}
4881
}
4982

5083
public ResPackage getPackage() {
@@ -61,9 +94,9 @@ public String getName() {
6194

6295
public boolean isBagType() {
6396
switch (mName) {
97+
case "array":
6498
case "attr":
6599
case "^attr-private":
66-
case "array":
67100
case "plurals":
68101
case "style":
69102
return true;

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/table/value/ResBag.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ protected ResBag(ResReference parent) {
3131

3232
public static ResBag parse(String typeName, ResReference parent, RawItem[] rawItems) {
3333
switch (typeName) {
34+
case "array":
35+
return ResArray.parse(parent, rawItems);
3436
case "attr":
3537
case "^attr-private":
3638
return ResAttribute.parse(parent, rawItems);
37-
case "array":
38-
return ResArray.parse(parent, rawItems);
3939
case "plurals":
4040
return ResPlural.parse(parent, rawItems);
4141
case "style":

0 commit comments

Comments
 (0)