Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java decompiler that works with Java 5 (handles enums among other new things)

I know this question was asked gzillions of times already, but I am specifically after a decompiler that would handle enums corrently (because the jar I am decompiling uses enums heavily). I tested that both JAD and JD-GUI don't.

Could someone recommend a decompiler (ideally that works under Linux and can easily handle the whole jar without requiring me to write shell scrips)?

EDIT: Specifically I have issues with constructs like:

switch(myEnum) {
case A: ...
case B: ...
}

they get decompiled (for both JAD and JD-GUI) as something like:

switch ($SWITCH_TABLE$com$MyType()[myEnum.ordinal()]) {
case 1:
case 2:
}

where $SWITCH_TABLE$com$MyType() is either not declared at all or doesn't compile.

like image 854
Grzenio Avatar asked Oct 24 '11 11:10

Grzenio


1 Answers

It is not possible to decompile a enum-switch properly. The java-classfile doesn't know about the enum-Typ after compilation, thus your decompiler cant decompile it as you like it.

Enums-Types are all a subtype of java.lang.Enum, every enum constant got an ordinal-number which is used in a switch statement. The compiler do a switch on that int-value, a switch over an enum type is simply said syntactic-sugar. If you try to switch on an null-enum you will get a NPE.

like image 95
Chriss Avatar answered Sep 24 '22 14:09

Chriss