From bfe116d0fa0efcf2812df4d701ca061a0383bb1f Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Mon, 23 Aug 2021 17:50:59 +0200 Subject: [PATCH] Fix treating of Zip files --- .../java/com/googlecode/d2j/reader/DexFileReader.java | 2 +- .../com/googlecode/d2j/reader/MultiDexFileReader.java | 6 +++++- .../src/main/java/com/googlecode/d2j/dex/Dex2jar.java | 9 +++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java b/dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java index ecbdeeb25..a2e6a2772 100755 --- a/dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java +++ b/dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java @@ -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 diff --git a/dex-reader/src/main/java/com/googlecode/d2j/reader/MultiDexFileReader.java b/dex-reader/src/main/java/com/googlecode/d2j/reader/MultiDexFileReader.java index 3e693e14f..8b46919ac 100644 --- a/dex-reader/src/main/java/com/googlecode/d2j/reader/MultiDexFileReader.java +++ b/dex-reader/src/main/java/com/googlecode/d2j/reader/MultiDexFileReader.java @@ -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"); @@ -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() { diff --git a/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2jar.java b/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2jar.java index 67db2d7ee..7d9b1dfc0 100644 --- a/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2jar.java +++ b/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2jar.java @@ -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; @@ -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) { @@ -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 {