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 56794ea3..f11ba5d5 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 @@ -708,7 +708,7 @@ public class Androlib { private final static String[] APK_MANIFEST_FILENAMES = new String[] { "AndroidManifest.xml" }; private final static String[] APK_STANDARD_ALL_FILENAMES = new String[] { - "classes.dex", "AndroidManifest.xml", "resources.arsc", "res", "lib", "libs", "assets", "META-INF" }; + "classes.dex", "AndroidManifest.xml", "resources.arsc", "res", "r", "lib", "libs", "assets", "META-INF" }; // Taken from AOSP's frameworks/base/tools/aapt/Package.cpp private final static Pattern NO_COMPRESS_PATTERN = Pattern.compile("\\.(" + "jpg|jpeg|png|gif|wav|mp2|mp3|ogg|aac|mpg|mpeg|mid|midi|smf|jet|rtttl|imy|xmf|mp4|" + 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 6abfd5d8..9f69936f 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 @@ -239,10 +239,13 @@ final public class AndrolibResources { out = new FileDirectory(outDir); inApk = apkFile.getDirectory(); + out = out.createDir("res"); if (inApk.containsDir("res")) { in = inApk.getDir("res"); } - out = out.createDir("res"); + if (in == null && inApk.containsDir("r")) { + in = inApk.getDir("r"); + } } catch (DirectoryException ex) { throw new AndrolibException(ex); } diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFileValue.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFileValue.java index c11c68f5..07edbbdc 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFileValue.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFileValue.java @@ -34,11 +34,13 @@ public class ResFileValue extends ResIntBasedValue { } public String getStrippedPath() throws AndrolibException { - if (!mPath.startsWith("res/")) { - throw new AndrolibException( - "File path does not start with \"res/\": " + mPath); + if (mPath.startsWith("res/")) { + return mPath.substring(4); } - return mPath.substring(4); + if (mPath.startsWith("r/")) { + return mPath.substring(2); + } + throw new AndrolibException("File path does not start with \"res/\" or \"r/\": " + mPath); } @Override diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java index 672ff832..572042c8 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResValueFactory.java @@ -70,6 +70,9 @@ public class ResValueFactory { if (value.startsWith("res/")) { return new ResFileValue(value, rawValue); } + if (value.startsWith("r/")) { //AndroResGuard + return new ResFileValue(value, rawValue); + } return new ResStringValue(value, rawValue); } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java new file mode 100644 index 00000000..2b1f1452 --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java @@ -0,0 +1,66 @@ +/** + * Copyright 2014 Ryszard Wiśniewski + * Copyright 2014 Connor Tumbleson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package brut.androlib; + +import brut.androlib.res.util.ExtFile; +import brut.common.BrutException; +import brut.util.OS; +import java.io.File; +import java.io.IOException; +import java.util.logging.Logger; + +import org.junit.*; +import static org.junit.Assert.*; + +public class AndResGuardTest { + + @BeforeClass + public static void beforeClass() throws Exception, BrutException { + sTmpDir = new ExtFile(OS.createTempDirectory()); + TestUtils.copyResourceDir(LargeIntsInManifestTest.class, "brut/apktool/issue1170/", sTmpDir); + } + + @AfterClass + public static void afterClass() throws BrutException { + OS.rmdir(sTmpDir); + } + + @Test + public void checkifAndResDecodeRemapsRFolder() throws BrutException, IOException { + String apk = "issue1170.apk"; + + // decode issue1170.apk + ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk)); + sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".out"); + + apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out")); + apkDecoder.decode(); + + checkFileExists("res/mipmap-hdpi-v4/a.png"); + } + + private void checkFileExists(String path) throws BrutException { + File f = new File(sTestOrigDir, path); + + assertTrue(f.isFile()); + } + + private static ExtFile sTmpDir; + private static ExtFile sTestOrigDir; + + private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeTest.class.getName()); +} diff --git a/brut.apktool/apktool-lib/src/test/resources/brut/apktool/issue1170/issue1170.apk b/brut.apktool/apktool-lib/src/test/resources/brut/apktool/issue1170/issue1170.apk new file mode 100644 index 00000000..ca2576a4 Binary files /dev/null and b/brut.apktool/apktool-lib/src/test/resources/brut/apktool/issue1170/issue1170.apk differ