I am trying to decompile Minecraft, to see if I can analyze the code to make a few small changes, but I need a decompiler good enough so I can recompile it in a way that will work. I have tried multiple decompilers online like javadecompilers.com. However, they don't work well for a variety of reasons, like they either throw errors, or the code does not look like original code, like all the variable names are replaced with snowman emojis or \u+5 digit number, for example, \u26032
. As for the snowman emojis, the java compiler won't be able to do distinguish different variables and cause name clashes. and for the \u numbers, the compiler might complain about stray \ in the program or something. Are there any easy to use compilers that work on Linux that are as accurate as possible, so accurate that decompiled code could be directly recompiled without having to fix the thousands of decompilation flaws?
-
What are you trying to modify? Why not use something like Forge or FabricMC?– Col-EJul 19, 2019 at 1:52
-
@I think the block of iron should have a blast resistance of 18000000 instead of 30– user29049Jul 19, 2019 at 14:24
-
I'm not familiar with Minecraft, but there's a good chance that something like that is stored in a data file, not the program code.– AntimonyJul 19, 2019 at 16:02
-
@Antimony I looked through all of the assets, and there is no sign of blast resistance.– user29049Jul 19, 2019 at 16:39
1 Answer
Krakatau is probably the decompiler most likely to produce code equivalent in behavior to the original (unless the code is using Java 8 lambdas, which Krakaau doesn't support). However, it is not possible to roundtrip decompile in general because compilation and decompilation are both lossy processes. And if the code has been obfuscated as Minecraft is, you'll be lucky if the results of decompilation are even understandable, let alone compileable.
If you want to edit obfuscated code, you need to learn how Java bytecode works and edit it at the bytecode level. Fortunately, besides the decompiler, Krakatau provides a bytecode assembler and disassembler which makes it easy to edit Java bytecode, even if it has been obfuscated.
P.S. No tool can recover the original variable or method names, because those simply aren't present in the compiled code. If you are seeing weird identifiers, it means that the code was obfuscated with a tool that strips out the original names and replaces them with meaningless names, which doesn't affect execution but obviously slows down reverse engineering.