Skip to content

Commit

Permalink
Fix treating of Zip files
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Aug 23, 2021
1 parent 9334471 commit bfe116d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public DexFileReader(InputStream is) throws IOException {
}

/**
* Reads a string index. String indicies are offset by 1, and a 0 value in the stream (-1 as returned by this
* Reads a string index. String indices are offset by 1, and a 0 value in the stream (-1 as returned by this
* method) means "null"
*
* @return index into file's string ids table, -1 means null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ private static byte[] toByteArray(InputStream is) throws IOException {
return out.getBuf();
}

public static BaseDexFileReader open(InputStream in) throws IOException {
return open(toByteArray(in));
}

public static BaseDexFileReader open(byte[] data) throws IOException {
if (data.length < 3) {
throw new IOException("File too small to be a dex/zip");
Expand All @@ -62,7 +66,7 @@ public static BaseDexFileReader open(byte[] data) throws IOException {
return new MultiDexFileReader(dexFileReaders.values());
}
}
throw new IOException("The src file is not a .dex or zip file");
throw new IOException("The source file is not a .dex or .zip file");
}

void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.googlecode.d2j.node.DexMethodNode;
import com.googlecode.d2j.reader.BaseDexFileReader;
import com.googlecode.d2j.reader.DexFileReader;
import com.googlecode.d2j.reader.MultiDexFileReader;
import com.googlecode.d2j.reader.zip.ZipUtil;
import com.googlecode.dex2jar.ir.IrMethod;
import com.googlecode.dex2jar.ir.stmt.LabelStmt;
Expand Down Expand Up @@ -268,11 +269,11 @@ public Dex2jar skipExceptions(boolean b) {
}

public static Dex2jar from(byte[] in) throws IOException {
return from(new DexFileReader(ZipUtil.readDex(in)));
return from(MultiDexFileReader.open(in));
}

public static Dex2jar from(ByteBuffer in) {
return from(new DexFileReader(in));
public static Dex2jar from(ByteBuffer in) throws IOException {
return from(MultiDexFileReader.open(in.array()));
}

public static Dex2jar from(BaseDexFileReader reader) {
Expand All @@ -284,7 +285,7 @@ public static Dex2jar from(File in) throws IOException {
}

public static Dex2jar from(InputStream in) throws IOException {
return from(new DexFileReader(in));
return from(MultiDexFileReader.open(in));
}

public static Dex2jar from(String in) throws IOException {
Expand Down

0 comments on commit bfe116d

Please sign in to comment.