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

4

8

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.

Shown answered 1/4, 2013 at 1:42 Comment(2)
Most of the java code are written in native language... so you might 'c' the method declaration but not the body of it... Also, android for example will obfuscates the sources.. making it harder for you to read even if you decompile it.Impropriety
In theory, any nonobfuscated class can be decompiled reasonably well. In practice, all existing decompilers will fail for particularly bizarre and complicated classes. Many don't handle type casting of narrow primatives well either.Viglione
W
7

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.

Westmorland answered 1/4, 2013 at 1:55 Comment(0)
E
4

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.

Estovers answered 1/4, 2013 at 1:45 Comment(1)
ProGuard isn't much of an obfuscator, though it's better than nothing, and most importantly free. But AFAIK, ProGuard doesn't do any flow obfuscation. It only renames everything and strips attributes, which makes the decompiled source harder to understand, but doesn't actually stop decompilers.Viglione
A
0

Yes this is (in general) possible (there exists multiple tools for this). See: How do I "decompile" Java class files?

However you can try to secure your files from this, see: How to lock compiled Java classes to prevent decompilation?

Ahlers answered 1/4, 2013 at 1:46 Comment(0)
R
0

I had the opportunity to decompile java multiple codes, and always managed with the tools available, to think that the byte code is generated by a compiler this process only needs to be reversed to get the original code. I know of a way to avoid this.

I used this tool.

java.decompiler.free.fr

Repetend answered 1/4, 2013 at 1:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.