Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not support version for Android N framework jars #93

Open
mindbirth opened this issue Oct 6, 2016 · 13 comments
Open

Not support version for Android N framework jars #93

mindbirth opened this issue Oct 6, 2016 · 13 comments

Comments

@mindbirth
Copy link

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.(DexFileReader.java:151)
at com.googlecode.d2j.reader.DexFileReader.(DexFileReader.java:211)
at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:104)
at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:288)
at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:32)

@death2all110
Copy link

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.

@krblock
Copy link

krblock commented Dec 15, 2016

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.

@death2all110
Copy link

death2all110 commented Dec 15, 2016

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!

@krblock
Copy link

krblock commented Dec 15, 2016

Have you run into any cases where dex2jar failed when given a jar with version 037?

@death2all110
Copy link

Nope. Not at the moment.

@krblock
Copy link

krblock commented Dec 15, 2016

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?

@death2all110
Copy link

death2all110 commented Dec 15, 2016

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

@Lanchon
Copy link

Lanchon commented Jan 30, 2017

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>

@sdGitBugger
Copy link

death2all110,

Please can you share your d2j-dex-2-jar.sh files after the compilation.

@prajitdas
Copy link

prajitdas commented May 14, 2017

@sdGitBugger I did this:-

  1. Compiled the project as per instructions given here using Maven
  2. 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.
  3. Removed all old versions jar files
  4. 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

@Lanchon
Copy link

Lanchon commented Oct 1, 2017

dex2jar for Android 7 and Android 8 is available here

@LiXiongDEV
Copy link

yes, Lanchon, it works, thanks:)

@sg552
Copy link

sg552 commented Mar 17, 2021

thanks to @Lanchon , it also works for Android Q ( 10 , dex.039)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants