Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If all the bytecode which compiled from java sources can be decompiled to java sources?

I see some java decompilers can decompile bytecode to readable java sources, I wonder if all the bytecode which comes from java (not other JVM language) can be decompiled to java sources again?


Update

Sorry, let me make the question more clear.

Just talk about the normal Java code on JVM (no Android, no bytecode enhance, no AOP, no obfuscation), and I actually hope the bytecode can be decompiled. But I don't know if there are forms of java code which compiled into bytecode, will never be able to be decompiled to readable java sources.

like image 536
Freewind Avatar asked Apr 01 '13 01:04

Freewind


People also ask

Can Java bytecode be decompiled?

Abstract. Java virtual machines execute Java bytecode instructions. Since this bytecode is a higher level representation than traditional ob- ject code, it is possible to decompile it back to Java source.

Can all code be decompiled?

As code complexity increases, decompilation becomes even more difficult. It is also not possible to decompile all programs. Furthermore, it is not easy to separate data and code because both are represented similarly in most current computer systems.

Can we convert Java bytecode to source code?

It is possible. You need a Java Decompiler to do this. You'll find mostly it'll do a surprisingly good job.

Why Java can be decompiled?

Because Java byte-code is closer (more similar) to the source than assembly. In particular, . class files include metadata for classnames, method names, field & parameter types, etc...


2 Answers

I wonder if all the bytecode which comes from java (not other JVM language) can be decompiled to java sources again?

The answer is No.

Decompilers aren't guaranteed to work for all Java bytecodes:

  • A good obfuscator will deliberately rearrange the bytecodes in such a way that the common decompilers won't produce readable source code ... and probably won't produce valid source code.

  • Many decompilers out there have problems dealing with newer Java constructs.

  • Many decompilers have problems with bytecodes compiled from "complicated" source code.

  • Even if they generate compilable code, there is no guarantee that the code will be correct.

The bottom line is that a decompiler is only as good as the intelligence and diligence of its author can make it. I've never heard of a perfect one.

like image 116
Stephen C Avatar answered Oct 03 '22 06:10

Stephen C


Java byctecode can be decompiled back to java source code. The decompiled source will generally not look the exact same, but will have the same functionality. If you're concerned that someone might decompile your source, you can use obfuscators (like ProGuard) to help.

like image 33
Jeff Storey Avatar answered Oct 03 '22 06:10

Jeff Storey