Commit cf68e472 authored by Nizam Moidu's avatar Nizam Moidu

multidex support for apk & zip

parent 7be37ff7
......@@ -116,7 +116,12 @@ public final class JadxDecompiler {
inputFiles.clear();
for (File file : files) {
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) {
throw new JadxException("Error load file: " + file, e);
}
......
......@@ -36,7 +36,12 @@ public class ConvertToClsSet {
if (f.isDirectory()) {
addFilesFromDirectory(f, inputFiles);
} 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) {
......@@ -67,7 +72,12 @@ public class ConvertToClsSet {
if (fileName.endsWith(".dex")
|| fileName.endsWith(".jar")
|| 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 {
private final File file;
private final Dex dexBuf;
public int nextDexIndex = -1;
private final int dexIndex;
public InputFile(File file) throws IOException, DecodeException {
this(file, 0);
}
public InputFile(File file, int dexIndex) throws IOException, DecodeException {
if (!file.exists()) {
throw new IOException("File not found: " + file.getAbsolutePath());
}
this.dexIndex = dexIndex;
this.file = file;
this.dexBuf = loadDexBuffer();
}
......@@ -41,7 +48,7 @@ public class InputFile {
return loadFromClassFile(file);
}
if (fileName.endsWith(".apk") || fileName.endsWith(".zip")) {
Dex dex = loadFromZip(file);
Dex dex = loadFromZip(this,file);
if (dex == null) {
throw new IOException("File 'classes.dex' not found in file: " + file);
}
......@@ -49,7 +56,7 @@ public class InputFile {
}
if (fileName.endsWith(".jar")) {
// check if jar contains 'classes.dex'
Dex dex = loadFromZip(file);
Dex dex = loadFromZip(this,file);
if (dex != null) {
return dex;
}
......@@ -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);
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) {
zf.close();
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();
InputStream in = null;
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