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; ...@@ -11,6 +11,8 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -100,4 +102,22 @@ public class FileUtils { ...@@ -100,4 +102,22 @@ public class FileUtils {
makeDirsForFile(file); makeDirsForFile(file);
return 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,15 +52,12 @@ public class InputFile { ...@@ -52,15 +52,12 @@ public class InputFile {
addDexFile(loadFromClassFile(file)); addDexFile(loadFromClassFile(file));
return; return;
} }
if (fileName.endsWith(".apk") || fileName.endsWith(".zip")) { if (FileUtils.isZipFile(file)) {
loadFromZip(".dex"); // check if zip contains '.dex' files
return;
}
if (fileName.endsWith(".jar")) {
// check if jar contains '.dex' files
if (loadFromZip(".dex")) { if (loadFromZip(".dex")) {
return; return;
} }
if (fileName.endsWith(".jar")) {
addDexFile(loadFromJar(file)); addDexFile(loadFromJar(file));
return; return;
} }
...@@ -68,6 +65,8 @@ public class InputFile { ...@@ -68,6 +65,8 @@ public class InputFile {
loadFromZip(".jar"); loadFromZip(".jar");
return; return;
} }
return;
}
//throw new DecodeException("Unsupported input file format: " + file); //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