Storyyeller / Krakatau

Java decompiler, assembler, and disassembler
GNU General Public License v3.0
1.95k stars 219 forks source link

useless cast object to object & double casts #144

Closed GraxCode closed 6 years ago

GraxCode commented 6 years ago

Krakatau casts objects to objects http://prntscr.com/jecabk Bytecode: http://prntscr.com/jecalq

Or sometimes uses two casts http://prntscr.com/jecdz3 Bytecode: http://prntscr.com/jece3d

Janmm14 commented 6 years ago

The one cast is there to select the right overload. Removes need to check stuff.

GraxCode commented 6 years ago

Casts to Object.class don't make any sense because every object you can cast is an object, the first one even triggers an compiler error, because it's not a typeless list. I would check if the cast is to Object.class and ignore it.

Janmm14 commented 6 years ago

Bytecode has no binding generics rules. Krakatau is meant to decompile flow obf and all teh stuff correctly. User friendlyness is not first priority. ofc still valid to create sich requests.

GraxCode commented 6 years ago

A decompiler should decompile code correctly and not have invalid casts.

Janmm14 commented 6 years ago

As Krakatau doesn't add generics to declarations its valid.

Storyyeller commented 6 years ago

As Janmm mentioned, this is WAI.

As far as generics go, they are extremely complex to implement, and not all that useful for decompiling obfuscated apps, as the obfuscator will strip the generics information anyway. Therefore, it is highly unlikely to be implemented.

If you want a decompiler that outputs pretty code at the expense of not handling obfuscation, there are plenty of other decompilers to choose from.

GraxCode commented 6 years ago

I do not think it is working as intended, it could produce invalid code by casting to java.lang.Object that is mostly not wanted by classes with types. By ignoring all casts to (java.lang.Object) this issue would easily be resolved. It wouldn't change the behaviour.

Storyyeller commented 6 years ago

You can easily remove the casts if you want. Just go to the top of java/ast.py and change ALWAYS_CAST_PARAMS = 1 to ALWAYS_CAST_PARAMS = 0.