Commit fe03c85b authored by chenzhong.cz's avatar chenzhong.cz

ensure a zip file by file content.

parent c3386520
......@@ -11,6 +11,8 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
......@@ -100,4 +102,22 @@ public class FileUtils {
makeDirsForFile(file);
return file;
}
public static boolean isZipFile(final File file) throws IOException {
ZipFile zipFile = null;
try {
zipFile = new ZipFile(file);
return zipFile.entries().hasMoreElements();
} catch (ZipException e) {
return false;
} finally {
if (zipFile != null) {
try {
zipFile.close();
} catch (IOException e) {
LOG.error(e.getMessage());
}
}
}
}
}
......@@ -52,20 +52,19 @@ public class InputFile {
addDexFile(loadFromClassFile(file));
return;
}
if (fileName.endsWith(".apk") || fileName.endsWith(".zip")) {
loadFromZip(".dex");
return;
}
if (fileName.endsWith(".jar")) {
// check if jar contains '.dex' files
if (FileUtils.isZipFile(file)) {
// check if zip contains '.dex' files
if (loadFromZip(".dex")) {
return;
}
addDexFile(loadFromJar(file));
return;
}
if (fileName.endsWith(".aar")) {
loadFromZip(".jar");
if (fileName.endsWith(".jar")) {
addDexFile(loadFromJar(file));
return;
}
if (fileName.endsWith(".aar")) {
loadFromZip(".jar");
return;
}
return;
}
//throw new DecodeException("Unsupported input file format: " + file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment