Tags

,

(Remote) debug is a great way to trouble-shooting, to figure out how the code works. But sometimes we only have the jars, no source code. For example the code is closed or proprietary, no where to get the sourc code.

Luckily, we can use JDEclipse-Realign to easily debug classes  without sources in Eclipse.

1. Install and Configure JDEclipse-Realign in eclipse
Install via JDEclipse-Realign update site http://mchr3k-eclipse.appspot.com/.

Click “Window” -> “Preferences”, type “File Association”. Select “class without source”, in the dialogue below,select “Class File Viewer [Decompiled]” as default.

2. Find jars contained classes which we want to debug
In linux, Use grep -r -s full_class_name * to find the jar.

3. Create a java project with the jars
Create a java project in Eclipse, add the jar(related jars) into the project’s build path.
Now if we right click on the jar, select “Attach Source”, we can see “Decompiled Source” is selected.. 

//<![CDATA[
if(showAdsense){
document.write("(adsbygoogle = window.adsbygoogle || []).push({});”)
} else {
if (window.CHITIKA === undefined) {
window.CHITIKA = { ‘units’ : [] };
};
var unit = {
‘publisher’ : “jefferyyuan”,
‘width’ : 728,
‘height’ : 90,
‘type’ : “mpu”,
‘sid’ : “Chitika Default”,
‘color_site_link’ : “FFFFFF”,
‘color_title’ : “FFFFFF”,
‘color_border’ : “FFFFFF”,
‘color_text’ : “4E2800”,
‘color_bg’ : “F7873D”
};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write(“

“);
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.src = ‘http://scripts.chitika.net/getads.js&#8217;;
try {
document.getElementsByTagName(‘head’)[0].appendChild(s);
} catch(e) {
document.write(s.outerHTML);
}
}
//]]>

4. Enable remote debug
Add the -Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=y in JVM options to remote java application. 

Then configure Eclipse for remote debugging by click “Run” -> “Debug Configuration”, then create a new “Remote Java Application”, enter the host, and port number: 1044 in this case, be sure to slect the previously-created project in project textbox.

Other tools
JD-GUI from http://jd.benow.ca/

Resources
Mchr3k – JDEclipse-Realign
JDEclipse-Realign Github
JD-GUI

via Blogger http://lifelongprogrammer.blogspot.com/2013/12/using-decompiler-to-debug-classes-without-source-in-eclipse.html

Advertisements