How do I access and open a .class file [duplicate] - java

This question already has answers here:
How can I open Java .class files in a human-readable way?
(17 answers)
Closed 9 years ago.
How can I open a .class file in Windows 7? I am getting a message saying that I can't see the file and that I have to choose a program to open it or look online for one. Is there any website, explanation, or download that will allow me to access ANY .class file I have extracted or have saved in my Documents?

Are you trying to decompile the .class file and view the source code? You can use Java Decompiler. It has a standalone GUI and also plugin for Eclipse/IntelliJ.

Is there any website, explanation, or download that will allow me to access ANY .class file I have extracted or have saved in my Documents?
It depends what you mean by "access" or "open". It also depends what you mean by extracting ... and what you extracted them from.
If you are trying to run the class files, then the standard way to run a Java application is to use the java command, as documented on the Oracle website. For example: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html. But how you use it depends on the nature of the thing that you downloaded and / or extracted. (Some ".class" files are not applications. Some ".class" files are designed to be run without extracting them from their JAR file container.)
If you are trying to look at the code in the class files, you could use the javap command to disassemble it. Or you could use a third-party tool to decompile it. But unless you have a clue as to what you are doing, this is not likely to help much. And since I can't really guess what you are trying to achieve, I can't offer you any useful references.
If you are trying to do something else, you'll need to explain what it is.
Either way, you need a Java installation on your machine before you can do anything.

You can use the javap command to view the disassembled class file. It is included in the JDK.

Related

source in jar file visible [duplicate]

This question already has answers here:
Jar File - Prevent Access to Source Code
(10 answers)
Closed 7 years ago.
I wrote a Java program and compiled it to jar file to distribute as a library that others import into their Java program and use it. It is a kind of simple library. The problem is when one imports the jar file into Netbeans to use it in their program, the source code is fully visible. They can open the classes in the jar file and see all the source. Is Netbeans decompiling the source or how is this possible? Is there a way to prevent users from seeing the source in Netbeans or any other IDE?
Yes, it's likely that Netbeans comes preloaded with a decompiler plugin, the only thing you can do is obfuscate all the classes in your jar with a tool like ProGuard.
They will still be able to decompile your classes, but it will be way harder to understand what your code is actually doing (heavily dependant on the complexity of your code). Sadly, you can't simply prevent decompilation.
I found out that this happens when the jar is imported to projects on the same machine on which the jar itself is developed. I took the jar file to another PC and imported it to a project, and alas the code is not visible. It is confusing why it behaving like that. I expect it should not show the code no matter what. Thanks for the replies.

How to make changes to a J2EE application on Glassfish server? [duplicate]

This question already has answers here:
How to decompile a whole Jar file? [closed]
(8 answers)
Closed 7 years ago.
I was asked to make a change to a Java app hosted on Glassfish 3.0. I do not have the source code. Will I be able to obtain the source code by decompiling it, make changes to it, and redeploy it with my changes? Would anyone be able to help?
This is going to depend on how your ear/war file was compiled, if it was compiled with the include source option your will be able to obtain the source code.You can import the ear/war file into your IDE(Eclipse/Netbeans).
Extending #ChristianMajuta 's clear answer, I must mention: most java application can be recompiled even if its source code wasn't compiled into its jar/war/ear. What you have to do:
extract the jar/war/ear , extract its components, etc, until you get a big directory containing the .class files.
Look for a java decompilator. It is a software which can decompile .class files to .java source code. Here you can't ask for a software recommendation, but on softwarecs.stackexchange.com it is allowed to do, and google is also your friend.
Decompile the classes to java with it.
Do you intentended modifications.
Compile this again (best if you import your decompiled code into a new eclipse/maven project).
There could be little problems, for example, decompiled java code removes all of the comments and its general lookup will be much worse, but it will work. Fortunately, java is a very easily decompilable language. Good luck!

how can I edit a Java application using .CLASS files

I've been trying to edit the .CLASS files inside this program using .jar containers, and a .bat file to launch it.
I'm not familiar with Java, and I've tried Java decompilers but they don't let me edit the source, only copy it. I don't seem to have a program that can actually correctly save and encode it.
What's the best option here to easily edit this Java program's .CLASS files?
Edit: To everyone who's enjoying downrepping this, the program is open source and permits modifications. So thank you for all the blame flinging about it being illegal.
You could try decompiling it with Fernflower, editing the code, then compiling it back into a classfile with the normal javac.
There is no real "easy" way. You could edit the bytecode...but that is a bit more involved. You can use JD but, that as you said, is only so useful.
Use java de-compliler to get source code from byte code, modify as per you want save in different location(like copy source code with your modifications) then compile & run.

Convert .jar file to JAVA DOC

How can I put my jar file to web. i.e is there a software that decompile jar file and make html pages of it?
In other words I want to make a java doc.
[Edit according to user comment]
So you want to extract javadoc from a jar...
First you must understand that if your jar doesn't contain the sources, but only the compiled code that your javadoc will not show any comment.
Then you just need to extract the file in your jar using any zip program (for exemple on windows, rename file to .zip, and extract it).
Last thing to do, is to call the javadoc tool on it. Like other said you can use an IDE for that, or simply call from the command line :
http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/javadoc.html#examples
javadoc -d \home\html -sourcepath \home\src -subpackages java -exclude java.net:java.lang
Creating Javadoc the way it was intended works, as far as I know, only from sources. If the JAR file also contains the source files, then it's just a matter of writing a Java program that opens the JAR file and puts any source files through the javadoc utility.
Interesting idea, but I don't know of anything doing that at the moment. To my knowledge it is however possible to generate Javadoc from inside of java program.
Another approach would be to load the classes into your classpath and use reflection to figure out methods, fields, etc. It will give you a rough overview of the classes, but sadly not the detailed stuff "normal" javadoc generation gives you. A lot of information is discarded upon compilation.
Converting .jar file to html seems impossible, except if you intend to users to download the .jar file from the web. However, html to .jar is possible.
I am certain that only the java source can be converted to javadoc. See here to convert java source to javadoc.
I have created a JAVADOC from a jar file that is not created by you i.e you don't have its source code.
Its simple but tricky.
Get source code from .jar file by using java decompiler. I use JD-GUI | Java Decompiler
Make a new project in myEclipse and copy the 'source code' in source folder.
In project menu you will see Generate Javadoc. Click and select you project and follow the steps. Java doc will be ready after you finish it.
Cheers
Imran Tariq
Once you downloaded your APK file , You need to do the following steps to get a editable java code/document.
Convert your apk file to zip (while start your download don't go
with save option , just go with save as and mention your
extension as .zip) by doing like this you may avoid APKTOOL...
Extract the zip file , there you can find somefilename.dex. so
now we need to convert dex -> .class
To do that, you need dex2jar(you can download it from
here , after extracted, in
command prompt you have to mention like,
[here] (Keep in mind that your somefilename.dex must be inside the same folder where you
have keep your dex2jar.)
Download jad from
http://www.viralpatel.net/blogs/download/jad/jad.zip and
extract it. Once extracted you can see two files like "jad.exe" and
"Readme.txt" (sometimes "jad.txt" may there instead of "jad.exe", so
just rename its extension as.exe to run)
Finally, in command prompt you have to mention like [D:\jad>jad
-sjava yourfilename.class] it will parse your class file into editable java document.
Use mvn javadoc:javadoc in Maven.

How can I extract java exe to jar

I have an exe that I know was written in java. I understand that java programs can be made into an exe and there are tools to convert jar files to exe but is it possible to convert back? AFAIK jar files can be run on any platform that can run java and I would like to use a windows compiled java program on mac without using any extra virtualisation (wine,vmware)
It depends how the exe has been built:
If it has simply wrapped, with a tool like JSmooth, the same tool can extract the jar
If it it has been compiled, with for instance gcj (as illustrated by this question),... I am not sure.
If it has been compiled by a static compiler (or AOT - Ahead-Of-Time -), I believe it is not possible to extract the orignial jars.
If your application was wrapped using JSmooth, you can look in your default temp directory (C:\Documents and Settings\Username\Local Settings\Temp) while the application is running.
Open a windows explorer window to the temp dir, then start up your application. You should see a jar file show up (Temp#.jar). Just make a copy of this and you should be on your way.
i suggest just rename your file extension from .exe to .jar and try to extract them.
to view the code use java Decompiler LIKE:
http://java-decompiler.github.io
It is possible to convert file.exe back to file.jar , To go with this reversing process to will require you to know how the file was beeen encrypted ,for example if is the first level encryption class name and files are not hidden , for the second level file classes are hidden , for the 3rd level file and classes are hidden . to get this well download jar to exe software and try how they convert jar to exe then you will be able to know the reverse. to know how you proceed with reversing the process there is a single blog which helped me and all tools you may use are listed there like : Resource Hacker
Winhex
Ollydbg 1.10+ MemoryDump 0.9 and Olly Advanced or StrongOD Plugin(for advanced ctrl+g).
DJ Java Decompiler
7-Zip or Winrar
The link:
https://reverseengineeringtips.blogspot.com/2014/12/unpacking-jar2exe-21-extracting-jar.html?showComment=1480364662658#c447064983483780468
thanks

Categories

Resources