Skip to content
/ Recaf Public

Java.lang.ClassFormatError at start of the modified jar #135

@artemking4

Description

@artemking4

When i made a simple if statement (Still learning java bytecode) i exported the app and while trying to run i got this error:

Exception in thread "main" java.lang.ClassFormatError: Duplicated LocalVariableTable attribute entry for '1' in class file com/desertkun/brainout/AuX/aux/jh at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at Aux.aux.aux.aux.do(BrainOut:839) at Aux.aux.aux.aux.getType(BrainOut:364) at com.desertkun.brainout.NUl.d.do(BrainOut:172) at com.desertkun.brainout.NUl.d.if(BrainOut:17) at Aux.aux.aux.aux$1.for(BrainOut:319) at Aux.aux.aux.aux.if(BrainOut:684) at Aux.aux.aux.aux.do(BrainOut:660) at Aux.aux.aux.aux.do(BrainOut:542) at Aux.aux.aux.aux.do(BrainOut:508) at Aux.aux.aux.aux.do(BrainOut:323) at com.desertkun.brainout.NUl.d.init(BrainOut:46) at com.desertkun.brainout.aux.<init>(BrainOut:58) at com.desertkun.brainout.con.<init>(BrainOut:91) at com.desertkun.brainout.desktop.aux.<init>(BrainOut:18) at com.desertkun.brainout.desktop.con.for(BrainOut:20) at com.desertkun.brainout.desktop.SteamLauncher.main(BrainOut:68)

To Reproduce
Steps to reproduce the behavior:

  1. Open a jar in recaf (https://www.mediafire.com/file/2b2ont373j1wkz1/brainout-steam.jar/file)
  2. Navigate to 'com/desertkun/brainout/AuX/aux/jh'
  3. Make an if statement in Assembler (setVisible function)
ILOAD 1
ICONST_1
IF_ICMPEQ then
ALOAD this 
GETSTATIC com/badlogic/gdx/graphics/Color.RED Lcom/badlogic/gdx/graphics/Color;
PUTFIELD com/desertkun/brainout/AuX/aux/jh.color Lcom/badlogic/gdx/graphics/Color;
//GOTO A
LABEL then
ILOAD 1
ICONST_0
IF_ICMPEQ END
ALOAD this 
GETSTATIC com/badlogic/gdx/graphics/Color.WHITE Lcom/badlogic/gdx/graphics/Color;
PUTFIELD com/desertkun/brainout/AuX/aux/jh.color Lcom/badlogic/gdx/graphics/Color;
LABEL END
  1. Export
  2. Run app and get this error

Activity

andylizi

andylizi commented on Jun 17, 2019

@andylizi
Contributor

Well the simple and obvious solution will be striping all the LocalVariableTable and be done with it. They are of no use in runtime anyway. Just turn on the Skip Debug checkbox in Config -> ASM.

Still worth investigating though. I'm guessing it's probably an ASM issue.

Edit: Huh. Guessed wrong 😁

Col-E

Col-E commented on Jun 17, 2019

@Col-E
Owner

Your code can be optimized:

// The opcode "IFEQ" checks if the value on the stack == false -> jump
// With this in mind, if visible == false we want to make the color red.
// The instruction will jump to red when visible == false
// The instruction will continue to the next one when visible == true
// So we can place the white code right after the IFEQ instruction
//
// if (visible) set WHITE
// else         set RED
ILOAD p1visible
IFEQ RED
// Set white if visible == true
LABEL WHITE
ALOAD this
GETSTATIC com/badlogic/gdx/graphics/Color.WHITE Lcom/badlogic/gdx/graphics/Color;
PUTFIELD com/desertkun/brainout/AuX/aux/jh.color Lcom/badlogic/gdx/graphics/Color;
GOTO END
// Set red  if visible == false
LABEL RED
ALOAD this 
GETSTATIC com/badlogic/gdx/graphics/Color.RED Lcom/badlogic/gdx/graphics/Color;
PUTFIELD com/desertkun/brainout/AuX/aux/jh.color Lcom/badlogic/gdx/graphics/Color;
LABEL END
RETURN

While I look into this, deselect the checkbox Local vars. This will stop Recaf from attempting to regenerate local variable debug information from the code you've written.

artemking4

artemking4 commented on Jun 17, 2019

@artemking4
Author

While pasting the code with comments to the Assembler i get nullpointerexception errors every edit i make here. And i can not touch ui anymore

Col-E

Col-E commented on Jun 17, 2019

@Col-E
Owner

Can you please share that nullpointerexception?
If the UI is frozen you can screenshot it.

artemking4

artemking4 commented on Jun 17, 2019

@artemking4
Author

Ok, let me just reproduce it (Also it is hella big)
изображение
So this seems to error only if it is copied from an browser/notepad and so on, but not the assembler

artemking4

artemking4 commented on Jun 17, 2019

@artemking4
Author

so its start is there:
изображение

Col-E

Col-E commented on Jun 17, 2019

@Col-E
Owner

Unrelated to the error, but I meant for you to replace the entire assembler code with what I posted, not adding it to the end.


Regarding the NPE shown in the logging pane down below: It's failing to map a set of old labels to new labels.

added a commit that references this issue on Jun 17, 2019
added a commit that references this issue on Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugYup, thats broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @andylizi@artemking4@Col-E

        Issue actions