Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decompile with correct line numbers using fernflower?

I'm using Intellij Idea 14 working with big java project where a lot of code is compiled and w/o sources.

As far as I know Idea can't make a search in compiled code (as eclipse does), but it can decompile single file using build-in fernflower and this also gives a possibility to debug through compiled code.

Is there a way to decompile all compiled code at once the same way Idea does and attach it to project so that it was possible to search through "Project and Libs" w/o loosing debugging feature in decompiled sources?

I've tried using Bytecodeviewer with different fernflower options, but the result was that debugging was broken (showed wrong lines) after attaching the decompiled sources.

like image 380
hahn Avatar asked Sep 18 '15 07:09

hahn


People also ask

How do you use FernFlower decompiler?

In contrast to Eclipse, IntelliJ IDEA provides the FernFlower decompiler as a default. To use it, we simply Ctrl+Left-Click on a class name and view the code: Also, we can download the source. Downloading the source will provide the actual code and comments.

How do I decode a .class file?

In order to decompile class file, just open any of your Java projects and go to Maven dependencies of libraries to see the jar files included in your project. Just expand any jar file for which you don't have the source attached in Eclipse and click on the . class file.

Can bytecode be decompiled?

The decompiler can not only convert bytecode to Java code, but it can also debug it. This means you can use breakpoints anywhere in the decompiled code with almost the same experience that you'd normally have when you debug your source code. Of course, you can always open the bytecode viewer for any compiled class.


2 Answers

I found that on OSX you can change this setting in the following file:

~/Library/Preferences/IntelliJIdea2016.1/options/options.xml

Add the following properties:

    <property name="decompiler.use.line.mapping" value="true" />
    <property name="decompiler.dump.original.lines" value="true" />
like image 186
b1gg33k Avatar answered Sep 28 '22 03:09

b1gg33k


ok, as there are no news regarding this, I've created a little plugin which decompiles the jar file with compiled code to new *-sources.jar file using build-in Intellij fernflower decompiler and attaches sources to project. anyone interested, can take a look at decompile and attach plugin in jetbrains plugin repository

Update answering my question about line numbers in decompiled code using fernflower. I found 'decompiler.use.line.table' flag in Intellij's fernflower which preserves line numbers.

like image 38
hahn Avatar answered Sep 28 '22 03:09

hahn