javadecompilerjadjadclipse

What would be a more accurate decompiler than jad for Eclipse to get rid of <-MISALIGNED ->?


I have used jad for many years, most of these with the Jadclipse plugin to eclipse which makes it quite usable. Especially with the "Align code for debugging" which allows you to see the decompiled code for any line in a stack trace. Very nice.

Unfortunately I've seen more and more that the <- MISALIGNED -> comment sneaks in, which is most likely because jad expects the classfile to be in order which clearly is not the case for the Java 6 runtime library. Hence when writing the file, and an instruction says "this is line 100" then 99 empty lines are written, and if then the next instruction says "this is for line 10" then jad cannot rewind to put that output there, but just prints out a comment that this is in the wrong place.

Here is an example for HttpURLConnection:

          protected HttpURLConnection(URL url, Proxy proxy, Handler handler1)
            {
/* <-MISALIGNED-> */ /* 603*/        super(url);
/* <-MISALIGNED-> */ /* 192*/        ps = null;
/* <-MISALIGNED-> */ /* 196*/        errorStream = null;
/* <-MISALIGNED-> */ /* 199*/        setUserCookies = true;
/* <-MISALIGNED-> */ /* 200*/        userCookies = null;
/* <-MISALIGNED-> */ /* 220*/        currentProxyCredentials = null;
/* <-MISALIGNED-> */ /* 221*/        currentServerCredentials = null;
/* <-MISALIGNED-> */ /* 222*/        needToCheck = true;
/* <-MISALIGNED-> */ /* 223*/        doingNTLM2ndStage = false;
/* <-MISALIGNED-> */ /* 224*/        doingNTLMp2ndStage = false;
/* <-MISALIGNED-> */ /* 226*/        tryTransparentNTLMServer = NTLMAuthentication.supportsTransparentAuth();
/* <-MISALIGNED-> */ /* 227*/        tryTransparentNTLMProxy = NTLMAuthentication.supportsTransparentAuth();
/

The question is now if there is another decompiler which generates more accurate output linewise. The actual decompilation does not need to be extremely great or anything, but I really like it to be where the Java Stack Trace view expects it to be. If it works well with Jadclipse, thats even better.


Solution

  • The problem with formatting for debug comes from jadclipse and not from jad. jad does not have that capability.

    The jadclipse plug-in has a little code section in a class names DebugAlignWriter which does this:

    if((align = getAlignTarget(aLine)) != -1)
    {
       if(align < curLine)
       {
          if(curLine != 0)
          {
              out.write(10);
          }
          out.write("/* <-MISALIGNED-> */ ");
          out.write(aLine);
          curLine++;
       }
       else if(align == curLine)
       {
          out.write(aLine);
       }
       else
       {
          for(; align > curLine; curLine++)
          {
              out.write(10);
          }
          out.write(aLine);
       }
    

    }

    Basically it tries to align the output from jad.

    So the root cause is that jad produces an output that is not necessarily in reading order. Unfortunately I cannot shed light on why jad acts that way. According to jad help there is no way of controlling the order.

    I noticed in jadclipse that if you set JadClipse->Formatting->Don't insert a newline before opening brace - it will reduce the number of /* <-MISALIGNED-> */ segments due to the nature of how it works.

    Also, if you checked the Output fields before methods option it can increase the number of /* <-MISALIGNED-> */ segments, so avoid it.