my dog learned polymorphism*
The moose likes Java in General and the fly likes decompilation of .class file into .java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "decompilation of .class file into .java" Watch "decompilation of .class file into .java" New topic
Author

decompilation of .class file into .java

Mr Anil Kumar Pandey
Greenhorn

Joined: Sep 13, 2010
Posts: 29
hi everybody
can .class file decompiled into .java file and then after important modification and then after compilation be used as original?
thanks
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Firstly am not sure if the decompiled version will be exactly same as that of the original file. Moreover, if you have a valid java file with all imports resolved, you can as well edit that file and compile it again. And for decompiling details- you can search in the Beginner or Java General forums.

This is somewhat not encouraged because you would be making use of some else's work. If the code is open sourced then you can download the source directly and this is fine because the original author wanted it to be shared and reused.


Mohamed Sanaulla | My Blog
Mr Anil Kumar Pandey
Greenhorn

Joined: Sep 13, 2010
Posts: 29
thanks

may i know what are free decompiler available.
is there decompiler plugine available there?
Mehmet Gunacti
Ranch Hand

Joined: Oct 26, 2004
Posts: 34
Take a look at http://java.decompiler.free.fr
Meherdad Bomanbehram
Ranch Hand

Joined: May 28, 2007
Posts: 139

many are available here
Mr Anil Kumar Pandey
Greenhorn

Joined: Sep 13, 2010
Posts: 29
thanks

is decompile code(.class->.java) 100% reliable as original one
Mehmet Gunacti
Ranch Hand

Joined: Oct 26, 2004
Posts: 34
AFAIK there's no guaranty for a 100% success. I wouldn't rely on it.
Mr Anil Kumar Pandey
Greenhorn

Joined: Sep 13, 2010
Posts: 29
Mehmet Gunacti wrote:AFAIK there's no guaranty for a 100% success. I wouldn't rely on it.

sir thanks
i have a .class file.
original source file missed.
i have to change url in this file
how one can do it?
please tell me sir a successfull way
Mehmet Gunacti
Ranch Hand

Joined: Oct 26, 2004
Posts: 34
well, create an empty project in your favorite IDE and put the original jar file into the build-path.

decompile the class, put the .java file into your source folder (preserve package structure).

after compilation just update the original jar file using Winrar, drag and drop the new class file and overwrite the original one.

That should do the trick ;)
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

There is no reliable way to do this. Your decompiled java classes may well... not compile because the decompilation process is not fool proof.

You can however follow the approach mentioned by Mehmet. It will bring you closest to success.

Why are you decompiling anyway ? Did you lose the source ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10491
    
    9

It might be a good idea to carefully read the license. Some licenses explicitly forbid decompiling.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Tommy Delson
Ranch Hand

Joined: Apr 13, 2011
Posts: 206
Why don't you just use Eclipse IDE to open .class file? Eclipse has everything you need for the project...harness the tool to it full power.


OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

well mr pandy may be completely innocent, but i always thought one of the big advantages of compilers vs interpreters is that your source code is sate.


SCJP
Visit my download page
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19726
    
  20

Safe? No. You can do your best to make it hard to decompile, by using a code obfuscator, but in the end most of the code can be decompiled. After all, the JVM needs to be able to read the byte code, and therefore so can any decompiler.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mehmet Gunacti
Ranch Hand

Joined: Oct 26, 2004
Posts: 34
the question is, why did the designers of Java allow that ?

they must have discussed this, and accepted the fact that Java code will be decompilable.

Shouldn't they have included an option (parameter maybe ?) that would prevent decompilation ?

Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Mehmet Gunacti wrote:the question is, why did the designers of Java allow that ?

they must have discussed this, and accepted the fact that Java code will be decompilable.

Shouldn't they have included an option (parameter maybe ?) that would prevent decompilation ?



The JLS and the class format are specifications. This means your specification can have a JVM vendor (Sun/IBM/JBOSS) and it allows for freedom. You need not be tied down with a vendor.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Mehmet Gunacti wrote:. . . an option (parameter maybe ?) that would prevent decompilation ?
As Rob has already told us, if you can execute the bytecode you can decompile it. So it is not possible to prevent decompilation.
Mehmet Gunacti
Ranch Hand

Joined: Oct 26, 2004
Posts: 34
Campbell Ritchie wrote:
Mehmet Gunacti wrote:. . . an option (parameter maybe ?) that would prevent decompilation ?
As Rob has already told us, if you can execute the bytecode you can decompile it. So it is not possible to prevent decompilation.


You mean, if you can interpret the code, you can decompile it.

Still, there should be a mechanism like, compiling the java source code to binary instead of bytecode. the JVM should then be able to run binary-bytecode...

ok, I was just thinking loud.

AFAIK one is able to decompile .net code (intermediate language ?), too, right ? So I guess MS would have prevented that, if there would be a way to do it.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

run binary-bytecode...




Assembly you mean ? Here are some links that can clarify the matter for you

http://en.wikipedia.org/wiki/Bytecode

http://en.wikipedia.org/wiki/Assembly_language

http://en.wikipedia.org/wiki/Just-in-time_compilation
Mehmet Gunacti
Ranch Hand

Joined: Oct 26, 2004
Posts: 34
Deepak Bala wrote:
run binary-bytecode...




Assembly you mean ? Here are some links that can clarify the matter for you


Was just wondering why they didn't come up with a method to prevent decompiling Java classes.

It's not possible, I guess, that's why.

Yes, I meant assembly (or machine code). sorry for the inappropriate term.

Thanks for the links.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Compiling to machine code would tie your application to a particular platform. You would have to recompile a Windows® application to run on a Mac, for example.
Sam Hazim
Greenhorn

Joined: Jul 19, 2011
Posts: 26
I haven't had cause to look into it, but there are Java Obfuscators that will attempt to amend your class files to prevent/make decompilation difficult. If that's something that concerns you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: decompilation of .class file into .java