Debugging ProGuard obfuscated code in Eclipse can be tricky, which is especially true given the Eclipse Market lacking (at least unaware ) of any usable ProGuard debug plugins. Although we can try our best to write high quality code, but we, even as topnatch developers, are inevitably hear oops sooner or later. Therefore we often face the necessity of debugging obfuscated code.
However simply setting breakpoints on the original unobfuscated code is not enough anymore due to the JPDA backend can’t match the received BreakpointRequest with the obfuscated byte code in JVM. However a break point on the unobfuscated code or the byte code itself should still work. Here below are two solutions to help the debug.
Solution#1: Set breakpoint on unobfuscated code
Assume you are interested in looking into an obfuscated method and you know its call stack has an unobfuscated class on the path, then you can set a breakpoint (i.e. UnobfClass.getName from the stack below) there and step into the original unobfuscated code that matches b.a (see below). You may need to tell Eclipse where to load the unobfuscted source code upon prompt (see the attached screenshot below).
Thread [1852725909@jetty-1617] (Suspended (entry into method a in b))
b.a(Map, Date, Date, int, Group) line: 314
b.a(ContextItem, Date, Date, int) line: 108
UnobfClass.getName(ContextItem, Date, Date, int) line: 161
Solution#2: Set a breakpoint on byte code
Bytecode Visualizer can be used for this approach and you need to install the plugin to Eclipse. Refer to its document to set the file association. Then the following steps can be taken:
- Create an empty Java project and set its Java Build Path -> Libraries to contain your deployed obfuscated jars (via Add External JARS…) and classes (via Add External Class Folder…)
- Go to the project -> Referenced Libraries to find the obfuscated class of interest (either by using ProGuard command or manually matching the mappings), double click to open it in the Bytecode Visualizer editor
- Compare to the unobfuscated code to find out where you want the JVM to pause (this step may need your most patience) then set a breakpoint
- Set up the remote debugger on this project to connect to the remote debuggee, and start the debugger
- When it prompts for the source code, provide it with the unobfuscated version
Now you are all set and ready to debug the obfuscated running code by stepping into/through the ubobfuscated source code.