Adds full filepath for STORED files in case of multiple extensions

- fixes #1244
 - prevents greedy extension check STORE`ing too many files
This commit is contained in:
Connor Tumbleson 2016-07-29 09:21:52 -04:00
parent 475178605c
commit 3a982948ea
No known key found for this signature in database
GPG Key ID: C3CC0A201EC7DA75
3 changed files with 81 additions and 2 deletions

View File

@ -40,6 +40,7 @@ import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
/**
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
@ -161,10 +162,16 @@ public class Androlib {
for (String file : files) {
if (isAPKFileNames(file) && !NO_COMPRESS_PATTERN.matcher(file).find()) {
if (unk.getCompressionLevel(file) == 0) {
ext = FilenameUtils.getExtension(file);
if (ext.isEmpty()) {
if (StringUtils.countMatches(file, ".") > 1) {
ext = file;
} else {
ext = FilenameUtils.getExtension(file);
if (ext.isEmpty()) {
ext = file;
}
}
if (! uncompressedFilesOrExts.contains(ext)) {
uncompressedFilesOrExts.add(ext);
}

View File

@ -0,0 +1,72 @@
/**
* Copyright 2014 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright 2016 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.meta.MetaInfo;
import brut.androlib.res.util.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
import org.apache.commons.lang3.StringUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
import static org.junit.Assert.assertTrue;
/**
* @author Connor Tumbleson <connor.tumbleson@gmail.com>
*/
public class DoubleExtensionUnknownFileTest {
@BeforeClass
public static void beforeClass() throws Exception, BrutException {
TestUtils.cleanFrameworkFile();
sTmpDir = new ExtFile(OS.createTempDirectory());
TestUtils.copyResourceDir(LargeIntsInManifestTest.class, "brut/apktool/issue1244/", sTmpDir);
}
@AfterClass
public static void afterClass() throws BrutException {
OS.rmdir(sTmpDir);
}
@Test
public void multipleExtensionUnknownFileTest() throws BrutException, IOException {
String apk = "issue1244.apk";
// decode issue1244.apk
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
ExtFile decodedApk = new ExtFile(sTmpDir + File.separator + apk + ".out");
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
apkDecoder.decode();
MetaInfo metaInfo = new Androlib().readMetaFile(decodedApk);
for (String string : metaInfo.doNotCompress) {
if (StringUtils.countMatches(string, ".") > 1) {
assertTrue(string.equalsIgnoreCase("assets/bin/Data/sharedassets1.assets.split0"));
}
}
}
private static ExtFile sTmpDir;
private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName());
}