Commit 04246443 authored by skylot's avatar skylot

Merge pull request #100 from netmaxt3r/master

multidex support for apk & zip
parents 7be37ff7 cf68e472
...@@ -116,7 +116,12 @@ public final class JadxDecompiler { ...@@ -116,7 +116,12 @@ public final class JadxDecompiler {
inputFiles.clear(); inputFiles.clear();
for (File file : files) { for (File file : files) {
try { try {
inputFiles.add(new InputFile(file)); InputFile inputFile = new InputFile(file);
inputFiles.add(inputFile);
while (inputFile.nextDexIndex != -1) {
inputFile = new InputFile(file, inputFile.nextDexIndex);
inputFiles.add(inputFile);
}
} catch (IOException e) { } catch (IOException e) {
throw new JadxException("Error load file: " + file, e); throw new JadxException("Error load file: " + file, e);
} }
......
...@@ -36,7 +36,12 @@ public class ConvertToClsSet { ...@@ -36,7 +36,12 @@ public class ConvertToClsSet {
if (f.isDirectory()) { if (f.isDirectory()) {
addFilesFromDirectory(f, inputFiles); addFilesFromDirectory(f, inputFiles);
} else { } else {
inputFiles.add(new InputFile(f)); InputFile inputFile = new InputFile(f);
inputFiles.add(inputFile);
while (inputFile.nextDexIndex != -1) {
inputFile = new InputFile(f, inputFile.nextDexIndex);
inputFiles.add(inputFile);
}
} }
} }
for (InputFile inputFile : inputFiles) { for (InputFile inputFile : inputFiles) {
...@@ -67,7 +72,12 @@ public class ConvertToClsSet { ...@@ -67,7 +72,12 @@ public class ConvertToClsSet {
if (fileName.endsWith(".dex") if (fileName.endsWith(".dex")
|| fileName.endsWith(".jar") || fileName.endsWith(".jar")
|| fileName.endsWith(".apk")) { || fileName.endsWith(".apk")) {
inputFiles.add(new InputFile(file)); InputFile inputFile = new InputFile(file);
inputFiles.add(inputFile);
while (inputFile.nextDexIndex != -1) {
inputFile = new InputFile(file, inputFile.nextDexIndex);
inputFiles.add(inputFile);
}
} }
} }
} }
......
...@@ -23,11 +23,18 @@ public class InputFile { ...@@ -23,11 +23,18 @@ public class InputFile {
private final File file; private final File file;
private final Dex dexBuf; private final Dex dexBuf;
public int nextDexIndex = -1;
private final int dexIndex;
public InputFile(File file) throws IOException, DecodeException { public InputFile(File file) throws IOException, DecodeException {
this(file, 0);
}
public InputFile(File file, int dexIndex) throws IOException, DecodeException {
if (!file.exists()) { if (!file.exists()) {
throw new IOException("File not found: " + file.getAbsolutePath()); throw new IOException("File not found: " + file.getAbsolutePath());
} }
this.dexIndex = dexIndex;
this.file = file; this.file = file;
this.dexBuf = loadDexBuffer(); this.dexBuf = loadDexBuffer();
} }
...@@ -41,7 +48,7 @@ public class InputFile { ...@@ -41,7 +48,7 @@ public class InputFile {
return loadFromClassFile(file); return loadFromClassFile(file);
} }
if (fileName.endsWith(".apk") || fileName.endsWith(".zip")) { if (fileName.endsWith(".apk") || fileName.endsWith(".zip")) {
Dex dex = loadFromZip(file); Dex dex = loadFromZip(this,file);
if (dex == null) { if (dex == null) {
throw new IOException("File 'classes.dex' not found in file: " + file); throw new IOException("File 'classes.dex' not found in file: " + file);
} }
...@@ -49,7 +56,7 @@ public class InputFile { ...@@ -49,7 +56,7 @@ public class InputFile {
} }
if (fileName.endsWith(".jar")) { if (fileName.endsWith(".jar")) {
// check if jar contains 'classes.dex' // check if jar contains 'classes.dex'
Dex dex = loadFromZip(file); Dex dex = loadFromZip(this,file);
if (dex != null) { if (dex != null) {
return dex; return dex;
} }
...@@ -74,13 +81,26 @@ public class InputFile { ...@@ -74,13 +81,26 @@ public class InputFile {
} }
} }
private static Dex loadFromZip(File file) throws IOException { private static Dex loadFromZip(InputFile ipf, File file) throws IOException {
ZipFile zf = new ZipFile(file); ZipFile zf = new ZipFile(file);
ZipEntry dex = zf.getEntry("classes.dex"); String dexName = "classes.dex";
String futureDexName = "classes2.dex";
if (ipf.dexIndex != 0) {
dexName = "classes" + ipf.dexIndex + ".dex";
futureDexName = "classes" + (ipf.dexIndex + 1) + ".dex";
}
ZipEntry dex = zf.getEntry(dexName);
if (dex == null) { if (dex == null) {
zf.close(); zf.close();
return null; return null;
} }
try {
ZipEntry futureDex = zf.getEntry(futureDexName);
if (futureDex != null) {
ipf.nextDexIndex = ipf.dexIndex == 0 ? 2 : ipf.dexIndex + 1;
}
} catch (Exception ex) {
}
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
InputStream in = null; InputStream in = null;
try { try {
......
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