Question

For our project we are doing kind of reverse engineering. For that we have to debug a third party jar.

I tried de-compiling that jar with DJ, JAD, but output is source code with compile time errors (say return type is boolean in method prototype, but returning int, broken for loops, etc...).

Now, out of this corrupted source code, there are few .java files, which I want to debug. And I want to attach these few files source code with the corresponding classes in jar.

I googled for this, but not found anything useful. ????

Was it helpful?

Solution

The blocker is that the decompilers most likely are unable to rewrite a source file with correct line numbers. So even if the compiled lib has the appropriate line number information, using the decompiled output out of the box won't work.

You will be able to set breakpoints in method (as long as line number information is available in the compiled class files) even without haveing the source code. You may even be able to read the values of local variables (again, if the classes have been compiled with debug information) but then you have to look at the decompiler output and hope for the best, that the decompiled method is close enough to the real code.

It is not impossible but requires some "manual" work.

OTHER TIPS

You did not mention which IDE you are using for debugging. Eclipse asks for the sources if trying to debug classes which are only available in class form. The main problem is as Andreas_D already mentioned the non-matching line numbers.

I would try the following.

  1. Delete all decompiled java files with has not been decompiled in a working state.
  2. Try to compile each working decompiled java file using the original JAR in classpath. This allows you to generate new class files with correct line infos for debugging.
  3. Now replace the class files in the JAR file with the ones you have successfully recompiled. Add also the java files. Your debugging IDE should automatically recognize the source files then.

To attach source code for a class in java code :

  • Right-click on the desired class

  • Go to Open Declaration [F3]
    Class File editor will open click on Attach Source button

  • Browse jar which has source code

  • Click <Ok>
    After doing above step,Open Declaration will open .class file having source code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top