Java decompile-> recompile process, is it safe?

I know that if I take some source code, compile it and decompile it, the source and final source code will not be the same due to the possibility of saying the same thing in different ways (like a while

vs loop for

). In other words, this process is in some genus is polysemantic, which means that it is not reversible.

My question is in a different direction. If I take the bytecode, decompile it, and then recompile with the same compiler that was originally used, will the source and final bytecode be the same bytecode (ignoring the timestamps and default metadata)? If not byte is byte, is it at least logically equivalent, or could there be logical errors introduced by the process?

I don't have the tools, but I could answer my first question (byte equality), but not the second (logical equivalence), so I'm asking people to try it out here.

+3


source to share


1 answer


It seems to me that there is no decompiler to output 100% accurate recompiled code for the following reasons:



  • Compilation (like decompilation) is not meant to be bijective.
  • There is no way for the decompiler to be able to guess which compiler was used and with what parameters to create the .class file.
  • Decompilation should not respect a contract or specification as in the JSR and is not guaranteed to produce a valid, repeatable or certified result.
0


source







All Articles