As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
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
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.
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.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
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
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.
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.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I want to create a very minimalistic virtual machine with limited set of instructions in java.
I know how to do it in c/c++ with combination of LLVM but I want to try it in java as well how can I do it in java since I don't have access to LLVM how can I simulate the situation?
If you want to compile down to Java bytecode then you probably want to use a library like ASM: it is designed for generating and manipulating bytecode:
http://asm.ow2.org/
A lot of JVM languages (e.g. Clojure, Groovy) use ASM or something similar as an underlying bytecode generator.
To use the JVM you have to work within the constraints of how the JVM works which is to run byte code. This means you either have to generate byte code or Java source which you compile. If you use the Java source option, you can generate "instructions" which are implemented using method calls as a very light weight (for the developer) way of implementing it.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I used to think Java can be decompiled because it compiles into byte code and not object code. This is wrong because of the implicit assumption byte code is some how "more human readable" than object code. Why can programs written in Java be so easily decompiled and even have the same identifiers (variable names)? I heard in C/C++ it can only disassemble to assembly but no decompile to source code, why so?
Java compilers keeps most of the original information and does very little optimisation when producing the byte code. The compilers task is to validate the code so it can be dynamically optimised. Note: Excelisor compiles to native code and imagine would be difficult to decompile (at least that what their marketing says ;)
C/C++ is compiled and optimised as much as possible, discarding a lot of the original information. (With the exception for debug information) This makes it much more difficult to untangle into sensible C or C++.
Note: these are features of the compilers common used for those languages. Not features of the languages themselves.
In terms of the difference in languages, all you can say is that Java is relatively feature poor compared with C++. Less features makes less compiled patterns to understand and reverse engineer.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
CoffeeScript is so cool. If there is any language use the coffee syntax but running on jvm, like groovy, scala?
Python's syntax is not cool. i can't use so many xx,self in my code, that's ugly.
Yes. CoffeeScript compiles into plain old JavaScript, which can be executed by modern JVMs (v6+).
Incidentally, it's funny that you contrast the syntax of Python, since both languages depend on whitespace as syntax (which is a controversial topic!). Anyhoo, happy hacking!
[Edit] Here is a more useful introduction to using JavaScript on the JVM.
While it is not specifically Coffeescript, Mirah is a JVM language that compiles directly to JVM bytecode or Java source and requires no runtime library to run. Which makes it analogous to the way most people use Coffeescript. That is, avoiding the ugly semantic and syntactic elements of Javascript. Mirah is statically typed, yet its syntax borrows heavily from Ruby (Mirah is Javanese for Ruby).
While the language itself is still in its infancy, it's very possible to use it today. I've done most of my University homework using it where writing Java directly would have otherwise been required. I'm also poking at using it to develop for Android.
It does not look like Coffeescript, but it has the same goals and you may find it a good fit. Not to mention that Coffeescript syntax is also inspired somewhat on Ruby so the two share a common ancestor.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
How to get java file i.e source code from class file i.e from compiled file?
Check out this Java Decompiler.
Also see this Wikipedia page to know more about decompilation.
It should be noted that the code you get on decompilation of bytecode isn't very readable.
You have to use a disassembler.
Java Decompiler is a good choice.
Also Java Decompiler has a plug-in for Eclipse.
You can use javap command to get the overall structure of the file.
On the side note: Best way to disable anyone from getting the source from your compiled code is to use obfuscation.
You can make use of javap for getting the source back from bytecode.
There are plenty of tools and plugin that help you to disassemble and you can find some discussed here.
Yes you cannot do anything like reverse conversion.
What you can do is modify the bytecode at runtime. That's allowed in Java...
Check for java.lang.instrumentation package. That will help you to achieve your goal to some extent...
I just published a stand-alone Java Decompiler GUI (based on Jad) which you can get from Util Java Decompiler (JAD based) v1.0
This is a Windows based .NET 4.0 application, which supports the drag n'drop of *.jar files.