Add support for AndResGuard

- fixes #1170
This commit is contained in:
Connor Tumbleson 2016-03-10 09:29:49 -05:00
parent ee8e9cea3d
commit ea2c821fa5
6 changed files with 80 additions and 6 deletions

View File

@ -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|" +

View File

@ -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);
}

View File

@ -34,12 +34,14 @@ 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);
}
if (mPath.startsWith("r/")) {
return mPath.substring(2);
}
throw new AndrolibException("File path does not start with \"res/\" or \"r/\": " + mPath);
}
@Override
public String toString() {

View File

@ -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);
}

View File

@ -0,0 +1,66 @@
/**
* Copyright 2014 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright 2014 Connor Tumbleson <connor.tumbleson@gmail.com>
*
* 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());
}