dex2jar
dex2jar copied to clipboard
Not support version for Android N framework jars
When trying to decompile the android N framework jars (after exporting them using oatdump), I get the following error:
com.googlecode.d2j.DexException: not support version.
at com.googlecode.d2j.reader.DexFileReader.
Having the same issue here on a odex that was converted to dex with oat2dex and then tried using the latest dex2jar. APK came from a Google Pixel. PC is running Java 8.
Based on the following line from the source, it would seem that oat2dex is using Dex version 037.
./dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/HeaderItem.java: // On android N and later we support dex version 037.
So this problem is not specific to oat2dex. It will be any dex file that uses the new format. According to this webpage, Android 7.0 introduced a new format version.
https://source.android.com/devices/tech/dalvik/dex-format.html
Note: Support for version 037 of the format was added in the Android 7.0 release. Prior to this release most versions of Android have used version 035 of the format. The only difference between versions 035 and 037 is the addition of default methods and the adjustment of the invoke instruction semantics to support this feature. Due to a Dalvik bug present in older versions of Android, Dex version 036 has been skipped. Dex version 036 is not valid for any version of Android and never will be.
I was able to correct this myself a few weeks ago by editing DexFileReader.java and compiling dex2jar myself.
I changed the MAGIC_036 line at Line 90
private static final int MAGIC_035 = 0x00353330;
private static final int MAGIC_037 = 0x00373330;
I then edited the following at Lines 147-149
if (version != MAGIC_035 && version != MAGIC_037) {
throw new DexException("not support version.");
}
Hope this helps!
Have you run into any cases where dex2jar failed when given a jar with version 037?
Nope. Not at the moment.
What version of dex2jar are you using? I'm using 0.0.9.15 because of issue 84 results in the loss of debug information. Wondering if I can just apply this patch to this version?
2.x. Not sure exact version offhand.
Code for 0.0.9.x is a bit different, but should be same principal.
Change Line 62:
private static final byte[] VERSION_037 = new byte[] { 0x30, 0x33, 0x37 };
And change Line 175:
if (!Arrays.equals(version, VERSION_035) && !Arrays.equals(version, VERSION_037)) {
The 0.0.9.x branch is only available on bitbucket: BitBucket - pxb1988/dex2jar - Branch: 0.0.9.x
the problem is of course that dex2jar doesn't support the new dex format in Android 7+...
https://source.android.com/devices/tech/dalvik/dex-format.html
Note: Support for version 037 of the format was added in the Android 7.0 release. Prior to this release most versions of Android have used version 035 of the format. The only difference between versions 035 and 037 is the addition of default methods and the adjustment of the invoke instruction semantics to support this feature. Due to a Dalvik bug present in older versions of Android, Dex version 036 has been skipped. Dex version 036 is not valid for any version of Android and never will be.
it seems dex2jar is abandonware now. removing the check for dex version will not make it magically support dex 037. 037 was needed to support the parts of the Java 8 subset that is supported in N. (independent APKs typically won't be built for 037 for a while because they will likely need to support M and earlier. but framework classes are free to use 037.)
and, of course, dex2jar does fail to properly convert generalized dex 037 to java 7 bytecode. in fact, such a tool cannot exist, given that java 7 bytecode cannot express dalvik 037; you need java 8 bytecode for that.
you can use enjarify to convert dex 037, but then annotations will be lost. enjarify's author doesn't want to support them. there is no solution to properly convert 037 for now.
if you want to have dex2jar process 037 (probably incorrectly) as if it were 035, you can simply rewrite your dex files instead of patching dex2jar:
dexpatcher [--multi-dex] --api-level 23 <input-dex/jar/apk> <output-dir>
death2all110,
Please can you share your d2j-dex-2-jar.sh files after the compilation.
@sdGitBugger I did this:-
- Compiled the project as per instructions given here using Maven
- Took all
<foldername>-2.1-SNAPSHOT.jar
files from individual target folders like dex-tools/target/ and dex-reader/target and put in a lib folder like the distribution's lib folder. - Removed all old versions jar files
- Executed d2j-dex2jar.sh in normal fashion.
This worked for me. Hope it helps you!
@death2all110 please correct me if any of these instructions look wrong to you
dex2jar for Android 7 and Android 8 is available here
yes, Lanchon, it works, thanks:)
thanks to @Lanchon , it also works for Android Q ( 10 , dex.039)