I am trying to find a Java decompiler just like swf-decompiler, that allows to edit and recompile the source, without having to export it anywhere, and do any external actions. What I want is to very quickly apply small changes to .jars and save them, without taking extra time on manually recompiling java code with other tools, Is there a decompiler like that? Is there anything similar (like .class variable editor) and is it even possible to make a Java decompiler like swf-decompiler?
-
1Did you do any research? https://duckduckgo.com/?q=java+decompiler+and+editor ... And questions asking to recommend a tool are offtopic for stackoverflow. – clcto Jul 11 '14 at 17:15
-
I am not asking for a recomended tool, I want to know if it is possible in Java – Victor2748 Jul 11 '14 at 17:16
-
1What is wrong with just hotdeploying changes to your original source in a debug-enabled JVM? – Thorbjørn Ravn Andersen Jul 11 '14 at 17:18
-
1Are you asking if it's possible for a tool to exist to extract source files from a jar, edit the sources, and rebuild the jar? That would seem very possible, as long you have all the build dependencies. – NESPowerGlove Jul 11 '14 at 17:21
-
I don't have the source, instead I have tons of .jars to review and edit, and I can't take time on exporting the source and manually recompiling it with external tools (unless it is necessary) – Victor2748 Jul 11 '14 at 17:21
-
1Of course it's *possible*--but originally you *were* asking for a tool; it's not just recommending that's OT, finding is as well. It's just byte manipulation. Having "a ton of .jars to review and edit" seems really, really odd, on the face of it. Perhaps you can be more specific about what you're trying to do. – Dave Newton Jul 11 '14 at 17:22
-
I don't see how using a decompiler would ever be faster than hotdeploying changes. – Mitch Connor Jul 11 '14 at 17:52
-
Why do you need to "review and edit" binary jars? – Thorbjørn Ravn Andersen Jul 11 '14 at 19:09
-
@ThorbjørnRavnAndersen Different reasons: 1. Crack java games, 2. Moderation tool, etc. – Victor2748 Jul 11 '14 at 20:59
-
1@Victor2748 if you are smart enough to crack Java games, you should be smart enough to whip up such a tool from existing components (which are all out there). – Thorbjørn Ravn Andersen Jul 11 '14 at 21:16
-
You wouldn't want this even if you could find it. You need an IDE. The computer industry has spent decades trying to make what you describe impossible, and has at least succeeded in making it rather difficult. Recommendation//search questions are off-topic here. – user207421 Jul 12 '14 at 03:14
1 Answers
Recommending a tool is offtopic, but as for the question of whether it is possible, the answer is yes and no.
Java is relatively decompiler friendly, so for simple cases, it should be possible to create such a tool. However, there are some features or patterns that tend to trip up current decompilers, and given the complexity of the language, there is unlikely to ever be a decompiler that can reliably roundtrip arbitrary Java.
Furthermore, while compiling Java loses a lot less information than C, it does lose information. Obviously, you'll lose stuff like comments and whitespace, but under default settings, you'll lose a lot more: local variable names, flags, and types, generic types, compile time annotations, etc. Most of this information is preserved to some extent for reflection purposes, and passing the -g
flag to the compiler can force it to save more information, but you can't get it all back.
So in short, you can do a reasonable job most of the time, but you can't ever do it perfectly all of the time.
Also note that this is for ordinary Java compiled yourself. If the classfiles were not originally written in Java or they are obfuscated at all, you can forget recompiling. Even when decompilers produce readable output, the output is unlikely to be recompileable.
If you want to modify arbitrary jars, what you need is a disassembler and assembler. The best one I know of is Krakatau (Disclosure: I wrote it). The advantage of this is that it will work for any classfiles, even if they are obfuscated. However, it is not user friendly at all. If you don't know your way around the classfile format and bytecode, you won't be able to make more than trivial changes (such as changing a constant string).

- 37,781
- 10
- 100
- 107
-
To my understanding it is possible to express functionality in Java byte code that cannot easily be expressed in Java the language. See http://www.sable.mcgill.ca/publications/papers/2002-2/sable-paper-2002-2-slides.pdf for some insight on this. – Thorbjørn Ravn Andersen Jul 12 '14 at 13:32
-
-
Also, if Krakatau can produce semi-readable sources with correct linenumbers (from debug info in the class) then you have a winner if you make a Eclipse plugin replacing the default class presentation. – Thorbjørn Ravn Andersen Jul 12 '14 at 14:07
-
@ThorbjørnRavnAndersen The Krakatau decompiler is designed for reverse engineering, so it ignores debug information completely (as it will usually not be present anyway). And source will often not be recompileable for the reasons I mentioned above. At any rate, I was talking about the assembler and disassembler here, not the decompiler. – Antimony Jul 12 '14 at 15:58