Unlike C, C++ & Pascal, Java uses a different approach to compilation. Java don't compile to machine code, compile into intermediate code(byte code). That's why your Java byte code (.class or .jar) file contains much more information of your Java Source file, leaving exposed to reading the code or decompilation. To conceal your code from others, you can use any Java Obfuscator. Obfuscated code is very hard to read and understand. Obfuscating code to prevent reverse engineering(decompilation) is typically done to manage risks that stem from unauthorized access to source code.These risks include loss of intellectual property, ease of probing for application vulnerabilities and loss of revenue that can result when applications are reverse engineered, modified to circumvent metering or usage control and then recompiled. Obfuscating code is, therefore, also a compensating control to manage these risks. Obfuscators also be used to compact object code or interpreted code without affecting its behaviour. A good one I found is RetoGuard.
RetoGuard is very easy to install & use and fully documented. RetroGuard comes up with three flavors of license.
- Commercial(annual license and support agreement ) : If you are going to use RetroGuard commercially.
- Academic/Not-For-Profit(non-commercial license) : If you are going to use RetroGuard for Academic or not for profit purpose.
- Open Source(GNU General Public License) : If you are going to use RetroGuard for your Open Sourced Projects.
Using RetroGuard
Download RetroGuard from the download section and add the retroguard.jar file to your classpath. Package your entire package directory into jar by using the jar command or you can use any editor to do the same.
The command for running RetroGuard is of form
java RetroGuard [INPUT-JAR [OUTPUT-JAR [SCRIPT [LOGFILE]]]]
For simply, you can use
java -jar retroguard.jar input.jar output.jar
input.jar : jar to be obfuscated.
output.jar : output jar
Note : You can specify the classes not to obfuscate by adding entries to the script file. Bydefault(if you don't specify your script file) RetroGuard will preserve applications, applets, serializable classes, and RMI remote classes from obfuscation.
If your Jar requires other libraries to access they are must be available in classpath while running RetroGuard. Let your source jar is "input.jar" and you want allow access the class "mainClass" which lives in input.jar and has the package structure "com.test" and your jar depends upon the external library "extLib.jar" and will be output to "output.jar", then a suitable command for running RetroGuard will be :
java -classpath retroguard.jar;extLib.jar RetroGuard input.jar output.jar script.rgs
script.rgs is a simple text file which should contain the entry ".class com.test.mainClass public method"(without quote).
For the detail information, please check the RetroGuard documentation.
1 comments:
Arup,
You may wish to check out my article discussing the common flaws of Java bytecode obfuscation techniques.
Post a Comment