fix: support properly mapping r/R/res resources during disassemble (#2936)

This commit is contained in:
Connor Tumbleson 2022-11-13 18:06:25 -05:00 committed by GitHub
parent d66db22564
commit 22f2e6fb23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 28 deletions

View File

@ -221,22 +221,12 @@ final public class AndrolibResources {
ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder(); ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder();
attrDecoder.setCurrentPackage(resTable.listMainPackages().iterator().next()); attrDecoder.setCurrentPackage(resTable.listMainPackages().iterator().next());
Directory inApk, in = null, out; Directory in, out;
try { try {
out = new FileDirectory(outDir); out = new FileDirectory(outDir);
in = apkFile.getDirectory();
inApk = apkFile.getDirectory();
out = out.createDir("res"); out = out.createDir("res");
if (inApk.containsDir("res")) {
in = inApk.getDir("res");
}
if (in == null && inApk.containsDir("r")) {
in = inApk.getDir("r");
}
if (in == null && inApk.containsDir("R")) {
in = inApk.getDir("R");
}
} catch (DirectoryException ex) { } catch (DirectoryException ex) {
throw new AndrolibException(ex); throw new AndrolibException(ex);
} }

View File

@ -64,11 +64,11 @@ public class ResFileDecoder {
try { try {
if (typeName.equals("raw")) { if (typeName.equals("raw")) {
decode(inDir, inFileName, outDir, outFileName, "raw"); decode(inDir, inFilePath, outDir, outFileName, "raw");
return; return;
} }
if (typeName.equals("font") && !".xml".equals(ext)) { if (typeName.equals("font") && !".xml".equals(ext)) {
decode(inDir, inFileName, outDir, outFileName, "raw"); decode(inDir, inFilePath, outDir, outFileName, "raw");
return; return;
} }
if (typeName.equals("drawable") || typeName.equals("mipmap")) { if (typeName.equals("drawable") || typeName.equals("mipmap")) {
@ -83,26 +83,24 @@ public class ResFileDecoder {
// check for raw 9patch images // check for raw 9patch images
for (String extension : RAW_9PATCH_IMAGE_EXTENSIONS) { for (String extension : RAW_9PATCH_IMAGE_EXTENSIONS) {
if (inFileName.toLowerCase().endsWith("." + extension)) { if (inFileName.toLowerCase().endsWith("." + extension)) {
copyRaw(inDir, outDir, inFileName, outFileName); copyRaw(inDir, outDir, inFilePath, outFileName);
return; return;
} }
} }
// check for xml 9 patches which are just xml files // check for xml 9 patches which are just xml files
if (inFileName.toLowerCase().endsWith(".xml")) { if (inFileName.toLowerCase().endsWith(".xml")) {
decode(inDir, inFileName, outDir, outFileName, "xml"); decode(inDir, inFilePath, outDir, outFileName, "xml");
return; return;
} }
try { try {
decode(inDir, inFileName, outDir, outFileName, "9patch"); decode(inDir, inFilePath, outDir, outFileName, "9patch");
return; return;
} catch (CantFind9PatchChunkException ex) { } catch (CantFind9PatchChunkException ex) {
LOGGER.log( LOGGER.log(Level.WARNING, String.format(
Level.WARNING, "Cant find 9patch chunk in file: \"%s\". Renaming it to *.png.", inFileName
String.format( ), ex);
"Cant find 9patch chunk in file: \"%s\". Renaming it to *.png.",
inFileName), ex);
outDir.removeFile(outFileName); outDir.removeFile(outFileName);
outFileName = outResName + ext; outFileName = outResName + ext;
} }
@ -111,23 +109,23 @@ public class ResFileDecoder {
// check for raw image // check for raw image
for (String extension : RAW_IMAGE_EXTENSIONS) { for (String extension : RAW_IMAGE_EXTENSIONS) {
if (inFileName.toLowerCase().endsWith("." + extension)) { if (inFileName.toLowerCase().endsWith("." + extension)) {
copyRaw(inDir, outDir, inFileName, outFileName); copyRaw(inDir, outDir, inFilePath, outFileName);
return; return;
} }
} }
if (!".xml".equals(ext)) { if (!".xml".equals(ext)) {
decode(inDir, inFileName, outDir, outFileName, "raw"); decode(inDir, inFilePath, outDir, outFileName, "raw");
return; return;
} }
} }
decode(inDir, inFileName, outDir, outFileName, "xml"); decode(inDir, inFilePath, outDir, outFileName, "xml");
} catch (RawXmlEncounteredException ex) { } catch (RawXmlEncounteredException ex) {
// If we got an error to decode XML, lets assume the file is in raw format. // If we got an error to decode XML, lets assume the file is in raw format.
// This is a large assumption, that might increase runtime, but will save us for situations where // This is a large assumption, that might increase runtime, but will save us for situations where
// XSD files are AXML`d on aapt1, but left in plaintext in aapt2. // XSD files are AXML`d on aapt1, but left in plaintext in aapt2.
decode(inDir, inFileName, outDir, outFileName, "raw"); decode(inDir, inFilePath, outDir, outFileName, "raw");
} catch (AndrolibException ex) { } catch (AndrolibException ex) {
LOGGER.log(Level.SEVERE, String.format( LOGGER.log(Level.SEVERE, String.format(
"Could not decode file, replacing by FALSE value: %s", "Could not decode file, replacing by FALSE value: %s",