Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,12 @@ public void decode(ResTable resTable, ExtFile apkFile, File outDir)
ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder();

attrDecoder.setCurrentPackage(resTable.listMainPackages().iterator().next());
Directory inApk, in = null, out;
Directory in, out;

try {
out = new FileDirectory(outDir);

inApk = apkFile.getDirectory();
in = apkFile.getDirectory();
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) {
throw new AndrolibException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public void decode(ResResource res, Directory inDir, Directory outDir, Map<Strin

try {
if (typeName.equals("raw")) {
decode(inDir, inFileName, outDir, outFileName, "raw");
decode(inDir, inFilePath, outDir, outFileName, "raw");
return;
}
if (typeName.equals("font") && !".xml".equals(ext)) {
decode(inDir, inFileName, outDir, outFileName, "raw");
decode(inDir, inFilePath, outDir, outFileName, "raw");
return;
}
if (typeName.equals("drawable") || typeName.equals("mipmap")) {
Expand All @@ -83,26 +83,24 @@ public void decode(ResResource res, Directory inDir, Directory outDir, Map<Strin
// check for raw 9patch images
for (String extension : RAW_9PATCH_IMAGE_EXTENSIONS) {
if (inFileName.toLowerCase().endsWith("." + extension)) {
copyRaw(inDir, outDir, inFileName, outFileName);
copyRaw(inDir, outDir, inFilePath, outFileName);
return;
}
}

// check for xml 9 patches which are just xml files
if (inFileName.toLowerCase().endsWith(".xml")) {
decode(inDir, inFileName, outDir, outFileName, "xml");
decode(inDir, inFilePath, outDir, outFileName, "xml");
return;
}

try {
decode(inDir, inFileName, outDir, outFileName, "9patch");
decode(inDir, inFilePath, outDir, outFileName, "9patch");
return;
} catch (CantFind9PatchChunkException ex) {
LOGGER.log(
Level.WARNING,
String.format(
"Cant find 9patch chunk in file: \"%s\". Renaming it to *.png.",
inFileName), ex);
LOGGER.log(Level.WARNING, String.format(
"Cant find 9patch chunk in file: \"%s\". Renaming it to *.png.", inFileName
), ex);
outDir.removeFile(outFileName);
outFileName = outResName + ext;
}
Expand All @@ -111,27 +109,27 @@ public void decode(ResResource res, Directory inDir, Directory outDir, Map<Strin
// check for raw image
for (String extension : RAW_IMAGE_EXTENSIONS) {
if (inFileName.toLowerCase().endsWith("." + extension)) {
copyRaw(inDir, outDir, inFileName, outFileName);
copyRaw(inDir, outDir, inFilePath, outFileName);
return;
}
}

if (!".xml".equals(ext)) {
decode(inDir, inFileName, outDir, outFileName, "raw");
decode(inDir, inFilePath, outDir, outFileName, "raw");
return;
}
}

decode(inDir, inFileName, outDir, outFileName, "xml");
decode(inDir, inFilePath, outDir, outFileName, "xml");
} catch (RawXmlEncounteredException ex) {
// 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
// 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) {
LOGGER.log(Level.SEVERE, String.format(
"Could not decode file, replacing by FALSE value: %s",
inFileName), ex);
"Could not decode file, replacing by FALSE value: %s",
inFileName), ex);
res.replace(new ResBoolValue(false, 0, null));
}
}
Expand Down