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

3

4

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.

Bethanybethe answered 10/9, 2010 at 12:20 Comment(1)
I'm not a decompiler or bytecode expert, but I'm pretty sure it's damn difficult to have a decompiler that can decompile to match the line numbers. I use Java Decompiler (what's in a name), it just puts the line number in comments before the actual line. Nothing's aligned, usually, but I only use it to look some stuff up, not to do any actual debugging - not my code, probably closed-source too, not my job.Marble
D
2

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.

Diatonic answered 25/5, 2011 at 12:4 Comment(0)
B
1

JD-Eclipse is a very good decompiler which also handles java 7 features.

It doesn't have an "Align code for debugging" feature yet but I added one myself. I've been using it for the last year.

I also handle the cases when the line has to be moved back; I still mark it as MISALIGNED to signal the special case but at least it's placed on the right line.

If anyone wants to give it a try it can be download from here. More details inside README.txt

Bender answered 1/6, 2012 at 5:41 Comment(0)
K
0

I use jad with as little formatting as possible and then I use eclipse's format command, as I can make it match my preferred style from the preferences.

Kazim answered 10/9, 2010 at 12:23 Comment(1)
Doesn't that break the association between line numbers in the stack trace and the line numbers after the Eclipse formatter is done?Ajaajaccio

© 2022 - 2024 — McMap. All rights reserved.