Steve Kero
Steve Kero

Reputation: 713

Is it possible to decompile and debug Java application?

Is it possible to decompile a Java application and debug it using the decompiled code?

I'm interested more in the ability to debug using the decompiled code, rather than decompilation itself (it's trivial).

Upvotes: 2

Views: 9395

Answers (5)

Sybuser
Sybuser

Reputation: 1382

If the application was compiled with line number information, it's possible.

However, most decompilers do not handle line number realignment natively, except https://github.com/java-decompiler/jd-gui. In Preferences menu, tick checkbox Realign Line Numbers. See also this fork, line number realignment can't be perfect, and misaligned line numbers appear in red: https://github.com/nbauma109/jd-gui-duo?tab=readme-ov-file#realign-line-numbers

An Eclipse plugin introduced line number realignment as a post-decompilation process from the decompiled code: https://github.com/ecd-plugin/ecd. In Window -> Preferences menu, choose Java -> Decompiler and tick checkboxes in Debug Settings :

  • Output original line numbers as comments
  • Align code for debugging

See also this fork https://github.com/nbauma109/ecd for line number realignment with CFR decompiler and other bug fixes.

See also, this interesting thread from CFR decompiler project about a possible debug friendly output : https://github.com/leibnitz27/cfr/issues/73.

Upvotes: 0

Xavi López
Xavi López

Reputation: 27880

It is indeed possible, as many others have already pointed out.

If you want to just decompile a JAR and debug the decompiled classes by running them directly (i.e. using them as sources), there are plenty of decompilers that will serve you well.

If you're planning to debug a JAR in use in your application, look out for proper source code line number alignment features when choosing your decompiler. Take a look for instance at this question. You can end up with decompiled code like this:

Line X /* Line Y */ int x = y
Line Y (anything can be here, it could even not exist)

With totally different values for X and Y. This means that Line X in your decompiled .java file corresponds to line Y of the compiled code. When debugging the jar, you'll have to put a breakpoint at line Y in the source file to stop there. That can be quite annoying to debug. There are decompilers that will align the decompiled code in the source file respecting line numbers.

Line X /* Line X */ int x = y

I have used JD-Eclipse Realign with success on Eclipse. Believe me, it does make a difference to debug decompiled code with source line alignment.

Upvotes: 2

Juned Ahsan
Juned Ahsan

Reputation: 68715

Yes there are java decompilers available on internet, both paid and unpaid. I am currently using one called 'DJ java decompiler', which provides a free trial version, just google it.

You can hope that the jar you are trying to decompile and make some sense out of the class files, is not obfuscated.

Upvotes: 2

SpringLearner
SpringLearner

Reputation: 13854

yes it is possible click to download java decompiler for free

other links link1 link2

Upvotes: 2

Kayaman
Kayaman

Reputation: 73568

If the application decompiles nicely and hasn't been stripped of debug info, sure.

Upvotes: 0

Related Questions