Skip to content

Commit

Permalink
ensure a zip file by file content.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhong.cz committed Nov 8, 2016
1 parent c338652 commit fe03c85
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
20 changes: 20 additions & 0 deletions jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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;
Expand Down Expand Up @@ -100,4 +102,22 @@ public static File prepareFile(File file) {
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());
}
}
}
}
}
21 changes: 10 additions & 11 deletions jadx-core/src/main/java/jadx/core/utils/files/InputFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,19 @@ private void searchDexFiles() throws IOException, DecodeException {
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);
Expand Down

0 comments on commit fe03c85

Please sign in to comment.