Skip to content

Commit 22f2e6f

Browse files
authored
fix: support properly mapping r/R/res resources during disassemble (#2936)
1 parent d66db22 commit 22f2e6f

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,22 +221,12 @@ public void decode(ResTable resTable, ExtFile apkFile, File outDir)
221221
ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder();
222222

223223
attrDecoder.setCurrentPackage(resTable.listMainPackages().iterator().next());
224-
Directory inApk, in = null, out;
224+
Directory in, out;
225225

226226
try {
227227
out = new FileDirectory(outDir);
228-
229-
inApk = apkFile.getDirectory();
228+
in = apkFile.getDirectory();
230229
out = out.createDir("res");
231-
if (inApk.containsDir("res")) {
232-
in = inApk.getDir("res");
233-
}
234-
if (in == null && inApk.containsDir("r")) {
235-
in = inApk.getDir("r");
236-
}
237-
if (in == null && inApk.containsDir("R")) {
238-
in = inApk.getDir("R");
239-
}
240230
} catch (DirectoryException ex) {
241231
throw new AndrolibException(ex);
242232
}

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ public void decode(ResResource res, Directory inDir, Directory outDir, Map<Strin
6464

6565
try {
6666
if (typeName.equals("raw")) {
67-
decode(inDir, inFileName, outDir, outFileName, "raw");
67+
decode(inDir, inFilePath, outDir, outFileName, "raw");
6868
return;
6969
}
7070
if (typeName.equals("font") && !".xml".equals(ext)) {
71-
decode(inDir, inFileName, outDir, outFileName, "raw");
71+
decode(inDir, inFilePath, outDir, outFileName, "raw");
7272
return;
7373
}
7474
if (typeName.equals("drawable") || typeName.equals("mipmap")) {
@@ -83,26 +83,24 @@ public void decode(ResResource res, Directory inDir, Directory outDir, Map<Strin
8383
// check for raw 9patch images
8484
for (String extension : RAW_9PATCH_IMAGE_EXTENSIONS) {
8585
if (inFileName.toLowerCase().endsWith("." + extension)) {
86-
copyRaw(inDir, outDir, inFileName, outFileName);
86+
copyRaw(inDir, outDir, inFilePath, outFileName);
8787
return;
8888
}
8989
}
9090

9191
// check for xml 9 patches which are just xml files
9292
if (inFileName.toLowerCase().endsWith(".xml")) {
93-
decode(inDir, inFileName, outDir, outFileName, "xml");
93+
decode(inDir, inFilePath, outDir, outFileName, "xml");
9494
return;
9595
}
9696

9797
try {
98-
decode(inDir, inFileName, outDir, outFileName, "9patch");
98+
decode(inDir, inFilePath, outDir, outFileName, "9patch");
9999
return;
100100
} catch (CantFind9PatchChunkException ex) {
101-
LOGGER.log(
102-
Level.WARNING,
103-
String.format(
104-
"Cant find 9patch chunk in file: \"%s\". Renaming it to *.png.",
105-
inFileName), ex);
101+
LOGGER.log(Level.WARNING, String.format(
102+
"Cant find 9patch chunk in file: \"%s\". Renaming it to *.png.", inFileName
103+
), ex);
106104
outDir.removeFile(outFileName);
107105
outFileName = outResName + ext;
108106
}
@@ -111,27 +109,27 @@ public void decode(ResResource res, Directory inDir, Directory outDir, Map<Strin
111109
// check for raw image
112110
for (String extension : RAW_IMAGE_EXTENSIONS) {
113111
if (inFileName.toLowerCase().endsWith("." + extension)) {
114-
copyRaw(inDir, outDir, inFileName, outFileName);
112+
copyRaw(inDir, outDir, inFilePath, outFileName);
115113
return;
116114
}
117115
}
118116

119117
if (!".xml".equals(ext)) {
120-
decode(inDir, inFileName, outDir, outFileName, "raw");
118+
decode(inDir, inFilePath, outDir, outFileName, "raw");
121119
return;
122120
}
123121
}
124122

125-
decode(inDir, inFileName, outDir, outFileName, "xml");
123+
decode(inDir, inFilePath, outDir, outFileName, "xml");
126124
} catch (RawXmlEncounteredException ex) {
127125
// If we got an error to decode XML, lets assume the file is in raw format.
128126
// This is a large assumption, that might increase runtime, but will save us for situations where
129127
// XSD files are AXML`d on aapt1, but left in plaintext in aapt2.
130-
decode(inDir, inFileName, outDir, outFileName, "raw");
128+
decode(inDir, inFilePath, outDir, outFileName, "raw");
131129
} catch (AndrolibException ex) {
132130
LOGGER.log(Level.SEVERE, String.format(
133-
"Could not decode file, replacing by FALSE value: %s",
134-
inFileName), ex);
131+
"Could not decode file, replacing by FALSE value: %s",
132+
inFileName), ex);
135133
res.replace(new ResBoolValue(false, 0, null));
136134
}
137135
}

0 commit comments

Comments
 (0)