pxb1988 / dex2jar

Tools to work with android .dex and java .class files
Apache License 2.0
12.21k stars 2.1k forks source link

java.lang.RuntimeException: Method code too large! #22

Open CalvinEng opened 9 years ago

CalvinEng commented 9 years ago

The following is the error I encountered.

There are 1 methods fail to translate. 2015-07-29 03:53:53 UTC version: [dex-reader-2.0, dex-reader-api-2.0, dex-ir-2.0, d2j-smali-2.0, d2j-base-cmd-2.0, dex-tools-2.0, dex-translator-2.0] cmdline: [com.nxp.nfc.tagwriter.apk] env: java.runtime.name: Java(TM) SE Runtime Environment java.vm.version: 25.45-b02 java.vm.vendor: Oracle Corporation java.vendor.url: http://java.oracle.com/ java.vm.name: Java HotSpot(TM) Client VM java.vm.specification.name: Java Virtual Machine Specification java.runtime.version: 1.8.0_45-b15 java.awt.graphicsenv: sun.awt.Win32GraphicsEnvironment java.endorsed.dirs: C:\Program Files (x86)\Java\jre1.8.0_45\lib\endorsed java.io.tmpdir: C:\Users\Calvin\AppData\Local\Temp\ java.vm.specification.vendor: Oracle Corporation java.library.path: C:\ProgramData\Oracle\Java\javapath;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Softing\OPCToolbox\V43x\Windows\bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\TortoiseSVN\bin;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\nodejs\;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Brackets\command;C:\Users\Calvin\AppData\Roaming\npm;. java.specification.name: Java Platform API Specification java.class.version: 52.0 java.awt.printerjob: sun.awt.windows.WPrinterJob java.specification.version: 1.8 java.class.path: C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\antlr-runtime-3.5.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\asm-debug-all-4.1.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\d2j-base-cmd-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\d2j-jasmin-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\d2j-smali-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-ir-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-reader-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-reader-api-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-tools-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-translator-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-writer-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dx-1.7.jar; java.vm.specification.version: 1.8 java.home: C:\Program Files (x86)\Java\jre1.8.0_45 java.specification.vendor: Oracle Corporation java.vm.info: mixed mode java.version: 1.8.0_45 java.ext.dirs: C:\Program Files (x86)\Java\jre1.8.0_45\lib\ext;C:\Windows\Sun\Java\lib\ext java.vendor: Oracle Corporation java.vendor.url.bug: http://bugreport.sun.com/bugreport/

pxb1988 commented 9 years ago

please also attach the m0.txt in the zip file

CalvinEng commented 9 years ago

Github doesn't seems to have the option to upload files other than pictures, so I have uploaded the error zip file to google drive. Please look at the attached link.

https://drive.google.com/file/d/0B2U4p41RgtjKRFM2YWIwYW1SanM/view?usp=sharing

pxb1988 commented 9 years ago

the method Lcom/nxp/nfc/tagwriter/gc;.<clinit>()V contains an array, the array size is huge, so the generated instruction can't fit in a .class method.

devpilot commented 8 years ago

Encounted java.lang.RuntimeException: Method code too large! Uploaded Classes-error.zip on google drive https://drive.google.com/open?id=0B0uVD6vxUmjySEhJSmVSSVM2eTA

TamilanPeriyasamy commented 8 years ago

Hi pxb thanks for ur good Job .. I am in new for this circle.

I got same issue. How solve... I am use dex2jar 2.0.

GroverChouT commented 8 years ago

I have same problem. I'm using dex2jar Nightly build for dex2jar 20150601

smurfix commented 8 years ago

Same here. Any idea WRT a fix? or a workaround?

sigpwned commented 7 years ago

I was able to work around this issue with a little elbow grease.

I got the same error as above. I looked at the summary file to find the stack trace:

java.lang.RuntimeException: Method code too large!
        at org.objectweb.asm.MethodWriter.getSize(MethodWriter.java:1872)
        at org.objectweb.asm.AsmBridge.sizeOfMethodWriter(AsmBridge.java:28)
        at com.googlecode.d2j.dex.ExDex2Asm.convertCode(ExDex2Asm.java:55)
        at com.googlecode.d2j.dex.Dex2jar$2.convertCode(Dex2jar.java:128)
        at com.googlecode.d2j.dex.Dex2Asm.convertMethod(Dex2Asm.java:509)
        at com.googlecode.d2j.dex.Dex2Asm.convertClass(Dex2Asm.java:406)
        at com.googlecode.d2j.dex.Dex2Asm.convertDex(Dex2Asm.java:422)
        at com.googlecode.d2j.dex.Dex2jar.doTranslate(Dex2jar.java:172)
        at com.googlecode.d2j.dex.Dex2jar.to(Dex2jar.java:272)
        at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:108)
        at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:288)
        at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:32)

Next, I found the jar file which contains that class in the lib directory: asm-debug-all-4.1.jar. Searching for "asm-debug-all-4.1.jar source code" led me here. The relevant snippet of code that's failing is:

if (code.length > 0) {
    if (code.length > 65536) {
        throw new RuntimeException("Method code too large!"); // CULPRIT
    }
    cw.newUTF8("Code");
    size += 18 + code.length + 8 * handlerCount;

What an odd test! It turns out that the java spec states that java method bodies cannot be longer than 64K, so this library is (rightfully) refusing to compile the method dex2jar has generated under the covers. But we're just trying to look at source code, not compile a program, so we don't care about that limit. Let's work around it.

The Right Thing here would be to pull down the build here, update the code, recompile it, and replace the class file. However, I -- frankly -- couldn't be arsed to do all that, so I took the much more direct (irresponsible, and lazy) approach of editing the byte code by hand.

Here's what I did:

Really, whether to enforce this limit or not should be an option in the asm-debug-all library. In the meantime, I've attached the updated JAR file here. (I had to rename it to ZIP for GitHub to take the file; you'll need to rename it to JAR after you download it.) Back up the existing asm-debug-all-4.1.jar file, and replace the original with the attached (renamed) file. That should work.

ammaratef45 commented 6 years ago

@sigpwned Your solution is awesome but, I'm stuck with a new exception which is

java.lang.ArrayIndexOutOfBoundsException: 255 at org.objectweb.asm.MethodWriter.getSize(MethodWriter.java) at org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:775) at com.googlecode.d2j.dex.Dex2jar$1$1.visitEnd(Dex2jar.java:101) at com.googlecode.d2j.dex.Dex2Asm.convertClass(Dex2Asm.java:409) at com.googlecode.d2j.dex.Dex2Asm.convertDex(Dex2Asm.java:422) at com.googlecode.d2j.dex.Dex2jar.doTranslate(Dex2jar.java:172) at com.googlecode.d2j.dex.Dex2jar.to(Dex2jar.java:272) at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:108) at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:288) at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:32)

I tried to figure it out but I didn't get the point

ghost commented 5 years ago

@ammaratef45 Use another bytecode editor. https://github.com/GraxCode/JByteMod-Beta/releases worked for me.

ZXTube commented 2 years ago

The asm-debug-all-4.1.jar that @sigpwned attached is outdated by now

So you should use this amazing fork which says that it fixed a lot of things and it fixed this unnecessary exception