Preventing Others from Decompiling Your Java Files


But I don’t want people to be able to decompile my Java programs!


Obfuscate them.


It has been said that for any weapon there is a defense, and for any defense there is a weapon. If the weapon is a decompiler, then the defense is something called an obfuscator . An obfuscator takes your program and tries to make it obscure, so that decompilation either will not work or will not be useful.

Because Mr. van Vliet, the late inventor of Mocha, did not release its source code, nobody else can take it over and maintain it, as we don’t have the source. Or do we? Of course! That’s it! We’ll just run it through itself. Well, if you can download a copy, you can try it. But what you’ll find is that it doesn’t work. The entire program has been obfuscated. Yes, Mr. van Vliet also wrote the first Java obfuscator, partly in reaction to all the people who flamed him on the Net for releasing Mocha. Due to his untimely death, his obfuscator is no longer available.

There are, of course, commercial obfuscation programs that will do some degree of obfuscation. Some of them actually encrypt the file and use a custom class loader to decrypt it at runtime. I suppose if you wanted to keep people from learning how your program worked, which you well might for commercial or other reasons, you’d want to use one of these tools. Again, a Java resource web site or a current Java developer’s magazine would be the place to go for the latest versions.

Get Java Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.