Issue 2943 - Support raw disassembly w/ AndResGuard (#2944)

* fix: allow copying r/R if in raw mode

* test: assert raw files disassembled from AndResGuard
This commit is contained in:
Connor Tumbleson 2022-11-20 08:08:45 -05:00 committed by GitHub
parent e32309c96f
commit 35ce8fc061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View File

@ -842,7 +842,7 @@ public class Androlib {
private final static String APK_DIRNAME = "build/apk";
private final static String UNK_DIRNAME = "unknown";
private final static String[] APK_RESOURCES_FILENAMES = new String[] {
"resources.arsc", "AndroidManifest.xml", "res" };
"resources.arsc", "AndroidManifest.xml", "res", "r", "R" };
private final static String[] APK_RESOURCES_WITHOUT_RES_FILENAMES = new String[] {
"resources.arsc", "AndroidManifest.xml" };
private final static String[] APP_RESOURCES_FILENAMES = new String[] {

View File

@ -56,4 +56,18 @@ public class AndResGuardTest extends BaseTest {
File aPng = new File(sTestOrigDir,"res/mipmap-hdpi-v4/a.png");
assertTrue(aPng.isFile());
}
@Test
public void checkifAndResDecodeRemapsRFolderInRawMode() throws BrutException, IOException {
String apk = "issue1170.apk";
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".raw.out");
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".raw.out"));
apkDecoder.setDecodeResources(ApkDecoder.DECODE_RESOURCES_NONE);
apkDecoder.decode();
File aPng = new File(sTestOrigDir,"r/a/a.png");
assertTrue(aPng.isFile());
}
}

View File

@ -23,6 +23,7 @@ import brut.common.TraversalUnknownFileException;
import brut.util.BrutIO;
import brut.util.OS;
import java.io.*;
import java.nio.file.Files;
import java.util.logging.Logger;
public class DirUtil {
@ -84,14 +85,13 @@ public class DirUtil {
if (in.containsDir(fileName)) {
OS.rmdir(new File(out, fileName));
in.getDir(fileName).copyToDir(new File(out, fileName));
} else if (!in.containsDir(fileName) && !in.containsFile(fileName)) {
// Skip copies of directories/files not found.
} else {
if (fileName.equals("res") && !in.containsFile(fileName)) {
return;
}
String cleanedFilename = BrutIO.sanitizeUnknownFile(out, fileName);
File outFile = new File(out, cleanedFilename);
outFile.getParentFile().mkdirs();
BrutIO.copyAndClose(in.getFileInput(fileName), new FileOutputStream(outFile));
BrutIO.copyAndClose(in.getFileInput(fileName), Files.newOutputStream(outFile.toPath()));
}
} catch (RootUnknownFileException | InvalidUnknownFileException | TraversalUnknownFileException exception) {
LOGGER.warning(String.format("Skipping file %s (%s)", fileName, exception.getMessage()));