Inside Java

Java obfuscators


 

Why?

Java .class files contains data and symbolic names. Jshrink removes unused data and symbolic names from compiled Java class files, resulting in smaller files that load faster and that yield less information when decompiled. Decompilers such as Mocha can convert your Java .class files to highly readable and even recompilable source code.

An example

This example shows that it's very hard to understand a program when an obfuscator was used on it.

Source file:

class Main
{
    private static int compute(int myarg) {
        myarg=myarg*2;
        return myarg;
    }
   
    public static void main(String [] argv)
    {
       
        int count=1;
        System.out.println("Hello");


        for (int myint=1;myint<10;myint++) {
            count+=myint*myint;
        }
       
        System.out.println(compute(count));
        switch (count) {
            case 1: System.out.println("Humm...");
            case 286: System.out.println("Right!");
        }
    }
}

Decompiled Source file from obfuscated .class file:

import java.io.PrintStream;

synchronized class Main
{
public static void main(String astring[])
{
    int i;
    i = 1;
    System.out.println("Hello");
    for (int j = 1; j < 10; j++)
        i += j * j;
    System.out.println(0(i));


    expression i
    switch
        case 1: goto 68
        case 286: goto 76
        default: goto 84
        System.out.println("Humm...");
        System.out.println("Right!");
}

Main()
{
}

private static int 0(int i)
{
i *= 2;
return i;
}
}

Output from Jshrink obfuscator:

Jshrink 1.11 Copyright 1997 Eastridge Technology (www.e-t.com)
Licensed for evaluation only; generated names will not verify
Renamed compute to 0
Main    817 -> 520 bytes    37% reduction
Processed 1 class files; 520/817 = 37% reduction


JShrink renamed compute() to 0(), count to i,..
Neil's Java obfuscator even renames items to alphanumeric sequences (in high obfuscation mode) that are invalid to the Java syntax. Therefore, it's not possible to recompile again.

Some links