Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it so easy to decompile Java Code? [closed]

So I've just realized how easy it is to decompile my Java code. I've been searching around the net and I can't seem to figure out WHY its so easy. Every time I google something like "Why can I decomilple .class files?" or "Why does Java decompile so easily", all I get is links to software that can easily deompile my code. So I turn to you StackOverflow: why is it that Java can be converted back to easlily readable source code while C++ and other languages aren't very friendly to decompiling?

Thanks

like image 283
user818502 Avatar asked Sep 16 '12 20:09

user818502


People also ask

How easy is it to decompile Java?

Java is relatively easy to decompile back into legal Java code and with the abundance of programs capable of doing so it should definitely be a deciding factor whether to make use of Java for desktop applications.

How accurate is Java decompiler?

Short answer: 99% of the time, decompiled code will not look like the original code, but it should behave the same way.

Is Java easy to reverse engineer?

Yes, Java class files are easy to reverse engineer. The format is very regular, and very constrained: the VM must be able to verify that the code complies to the strong typing rules of Java code. This is like the output of a C compiler with all optimizations deactivated: the program structure is plainly visible.


2 Answers

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...
All a Java (or .Net) decompiler needs to do is look at the instructions in each method body, and turn them into the appropriate syntactic constructs.

By contrast, native languages like C++ do not include any metadata at all, so the decompiler needs to reconstruct everything.

like image 108
SLaks Avatar answered Sep 20 '22 02:09

SLaks


Java is compiled into an intermediate form, JVM bytecode, that retains a large amount of the information contained in the original Java code. A language like C++ compiles into assembly code, with looks a lot different from the original code, and is, therefore, harder to reverse.

like image 25
dhg Avatar answered Sep 20 '22 02:09

dhg