Follow by Email

Saturday, August 28, 2004

Java Decompiler Progress

[FYI, I'm working on a Java decompiler]

OK it's not great, but it's definitely good.

I started with this:

import java.io.Serializable;

public abstract class TestClass implements Runnable, Serializable
{
    public static int _field1 = 123;
    public String _field2 = "Hello";
    protected double _field3 = 123.456;
    char _field4 = 'M';
    long _val = 12345L;

    public static void main(String[] args)
    {
        int firstParameter = 2;
        int secondParameter = 3;
        int k = 4;
        int l = 5;
        int m = 6;
        m = firstParameter + secondParameter + k + l + m;
    }
    public void ifTest()
    {
        if (_field1 == 12345)
        {
            _field3 = 1.01;
        }
        else
        {
            _field3 = 1.02;
        }
    }
}

and got this:

public abstract class TestClass extends java.lang.Object implements java.lang.Runnable, java.io.Serializable
{
    public static int _field1;
    public java.lang.String _field2;
    protected double _field3;
    char _field4;
    long _val;
    static void ()
    {
_field1 = 123;
return;
    }
    public TestClass()
    {
        TestClass this; // (0-31 0)]
"Hello"_field2 = this;
123.456_field3 = this;
77_field4 = this;
12345_val = this;
return;
    }
    public static void main(java.lang.String[] args)
    {
        int firstParameter; // (2-27 1)]
        int secondParameter; // (4-27 2)]
        int k; // (6-27 3)]
        int l; // (9-27 4)]
        int m; // (13-27 5)]
firstParameter = 2;
secondParameter = 3;
k = 4;
l = 5;
m = 6;
m = ((((firstParameter + secondParameter) + k) + l) + m);
return;
    }
    public void ifTest()
    {
        TestClass this; // (0-27 0)]
if (_field1 != 12345)
{
1.02_field3 = this;
return;

}
else
{
1.01_field3 = this;

}

    }
}


Except for the formatting and the glaringly obvious errors assigning to class attributes (101_field3 = this?), that's pretty damn good! Heck, the formatting is a non-issue, what with auto-formatters. I may just flush everything left and chain with a source-code formatter. With some smart stuff (optimizations), this will come together nicely.

(I haven't even tried to handle about while, for, switch, new, null, synchronized blocks or even nesting the ifs above, but hey.)

No comments: