From c4e8f88499222036c3cbe0964e038fe189bdaa98 Mon Sep 17 00:00:00 2001 From: Kirlif Date: Mon, 7 Nov 2022 14:06:22 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Fix=20=C2=AB=20doNotCompress=20=C2=BB=20in?= =?UTF-8?q?=20case=20of=20obfuscated=20resources.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/brut/androlib/Androlib.java | 3 +++ .../main/java/brut/androlib/res/AndrolibResources.java | 4 +++- .../java/brut/androlib/res/decoder/ResFileDecoder.java | 9 ++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java index 4077ca6f..8c197131 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java @@ -184,6 +184,9 @@ public class Androlib { 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); diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java index a4492dc4..59b18213 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java @@ -247,7 +247,7 @@ final public class AndrolibResources { 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..."); @@ -1041,6 +1041,8 @@ final public class AndrolibResources { public BuildOptions buildOptions; + public Map ObfFiles = new HashMap(); + // TODO: dirty static hack. I have to refactor decoding mechanisms. public static boolean sKeepBroken = false; diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java index 7d32581d..351a6819 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java @@ -27,6 +27,7 @@ import brut.directory.Directory; import brut.directory.DirectoryException; import java.io.*; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -37,10 +38,11 @@ public class ResFileDecoder { this.mDecoders = decoders; } - public void decode(ResResource res, Directory inDir, Directory outDir) + public void decode(ResResource res, Directory inDir, Directory outDir, Map 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(); @@ -55,6 +57,11 @@ public class ResFileDecoder { 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"); From b32be8ca2a4e9b59654a481c1e017692943d4c00 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 8 Nov 2022 06:24:41 -0500 Subject: [PATCH 2/2] refactor: rename attributes for storing obfuscated filepath --- .../src/main/java/brut/androlib/Androlib.java | 16 ++++++++-------- .../brut/androlib/res/AndrolibResources.java | 4 ++-- .../androlib/res/decoder/ResFileDecoder.java | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java index 8c197131..a36468ae 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java @@ -177,19 +177,19 @@ public class Androlib { for (String file : files) { if (isAPKFileNames(file) && unk.getCompressionLevel(file) == 0) { - String ext = ""; + String extOrFile = ""; if (unk.getSize(file) != 0) { - ext = FilenameUtils.getExtension(file); + extOrFile = FilenameUtils.getExtension(file); } - if (ext.isEmpty() || !NO_COMPRESS_PATTERN.matcher(ext).find()) { - ext = file; - if (mAndRes.ObfFiles.containsKey(ext)) { - ext = mAndRes.ObfFiles.get(ext); + if (extOrFile.isEmpty() || !NO_COMPRESS_PATTERN.matcher(extOrFile).find()) { + extOrFile = file; + if (mAndRes.mResFileMapping.containsKey(extOrFile)) { + extOrFile = mAndRes.mResFileMapping.get(extOrFile); } } - if (!uncompressedFilesOrExts.contains(ext)) { - uncompressedFilesOrExts.add(ext); + if (!uncompressedFilesOrExts.contains(extOrFile)) { + uncompressedFilesOrExts.add(extOrFile); } } } diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java index 59b18213..e9415efe 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java @@ -247,7 +247,7 @@ final public class AndrolibResources { LOGGER.info("Decoding file-resources..."); for (ResResource res : pkg.listFiles()) { - fileDecoder.decode(res, in, out, ObfFiles); + fileDecoder.decode(res, in, out, mResFileMapping); } LOGGER.info("Decoding values */* XMLs..."); @@ -1041,7 +1041,7 @@ final public class AndrolibResources { public BuildOptions buildOptions; - public Map ObfFiles = new HashMap(); + public Map mResFileMapping = new HashMap(); // TODO: dirty static hack. I have to refactor decoding mechanisms. public static boolean sKeepBroken = false; diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java index 351a6819..75f67a8c 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java @@ -38,11 +38,11 @@ public class ResFileDecoder { this.mDecoders = decoders; } - public void decode(ResResource res, Directory inDir, Directory outDir, Map obfFiles) + public void decode(ResResource res, Directory inDir, Directory outDir, Map resFileMapping) throws AndrolibException { ResFileValue fileValue = (ResFileValue) res.getValue(); - String inFileFullName = fileValue.toString(); + String inFilePath = fileValue.toString(); String inFileName = fileValue.getStrippedPath(); String outResName = res.getFilePath(); String typeName = res.getResSpec().getType().getName(); @@ -57,9 +57,9 @@ public class ResFileDecoder { outFileName = outResName + ext; } - String outFileFullName = "res/"+outFileName; - if (!inFileFullName.equals(outFileFullName)) { - obfFiles.put(inFileFullName, outFileFullName); + String outFilePath = "res/" + outFileName; + if (!inFilePath.equals(outFilePath)) { + resFileMapping.put(inFilePath, outFilePath); } try {