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 « doNotCompress » in case of obfuscated resources. #2925

Merged
merged 1 commit into from
Nov 8, 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 @@ -184,6 +184,9 @@ public void recordUncompressedFiles(ExtFile apkFile, Collection<String> uncompre

if (ext.isEmpty() || !NO_COMPRESS_PATTERN.matcher(ext).find()) {
ext = file;
if (mAndRes.ObfFiles.containsKey(ext)) {
ext = mAndRes.ObfFiles.get(ext);
}
}
if (!uncompressedFilesOrExts.contains(ext)) {
uncompressedFilesOrExts.add(ext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void decode(ResTable resTable, ExtFile apkFile, File outDir)

LOGGER.info("Decoding file-resources...");
for (ResResource res : pkg.listFiles()) {
fileDecoder.decode(res, in, out);
fileDecoder.decode(res, in, out, ObfFiles);
}

LOGGER.info("Decoding values */* XMLs...");
Expand Down Expand Up @@ -1041,6 +1041,8 @@ public void close() throws IOException {

public BuildOptions buildOptions;

public Map<String, String> ObfFiles = new HashMap();

// TODO: dirty static hack. I have to refactor decoding mechanisms.
public static boolean sKeepBroken = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import brut.directory.DirectoryException;

import java.io.*;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -37,10 +38,11 @@ public ResFileDecoder(ResStreamDecoderContainer decoders) {
this.mDecoders = decoders;
}

public void decode(ResResource res, Directory inDir, Directory outDir)
public void decode(ResResource res, Directory inDir, Directory outDir, Map<String, String> obfFiles)
throws AndrolibException {

ResFileValue fileValue = (ResFileValue) res.getValue();
String inFileFullName = fileValue.toString();
String inFileName = fileValue.getStrippedPath();
String outResName = res.getFilePath();
String typeName = res.getResSpec().getType().getName();
Expand All @@ -55,6 +57,11 @@ public void decode(ResResource res, Directory inDir, Directory outDir)
outFileName = outResName + ext;
}

String outFileFullName = "res/"+outFileName;
if (!inFileFullName.equals(outFileFullName)) {
obfFiles.put(inFileFullName, outFileFullName);
}

try {
if (typeName.equals("raw")) {
decode(inDir, inFileName, outDir, outFileName, "raw");
Expand Down