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!
Related
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.
This question already has answers here:
Java obfuscators [closed]
(6 answers)
Closed 7 years ago.
I have made a jar file for a software that I need to use. The problem is that since it is a jar file, anyone can get .class files and decompile them to get the actual java code.
Could some one please point out how to keep this java code secure. I have tried converting this jar to exe using launch4j but noticed that it just packs everything to exe. This exe can be extracted and then decompiled to get the actual java code.
I just need code to be secure, whether by converting to exe or by any other method. Please help.
Thanks in advance
What you need is Java Code obfuscator which will change the Java code without changing the actual functions.
Check ProGuard which does that.
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.
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.
I am trying to open Motorola BLE API library for Android. I am not too familiar with Java so I am not sure if it is even possible.
When I try to open .class file from the library with notepad++ it contains something like:
Êþº¾ and black squares.
Is there a way to open them properly?
You can use the tool javap to disassemble .class files (= compiled Java code) but that won't tell you much.
Try to find the official documentation or the source (= .java files) by googling for the class name instead.
You will need to de-compiler to read the .class files. There are various available in the market, which are open source and free. Here is one
A .class file means that the library has already been compiled into Java's version of machine code, so you won't be able to view it in notepad. There are programs for decompiling class files back into source, but you need to make sure that a) you have the rights to do so, and b) that the particular decompiler supports the class file's particular version of Java.
For more information on decompilers, see this question:
How do I decompile Java class files?
If there source code (.java files) are provided , better use those. If not, then you have to use one of the de-compiler program. But even then if the code is obfuscated , even de-compiler would not be of any use. You have to use just the API documentation for any work.
Java is a compiled language where the source is compiled into machine readable bytecode. You have to disassemble/decompile the bytecode to get it into an even semi-readable form.
Also note that the license of the library very probably forbids you from disassembling it.
If you are really using to use the api in your application then here is the way:
See the documentation of the api that is provided.
Also import the classes in with the import statement. For eg put the classes in a new folder as "api" in current folder and the import statement would be as follows:
import api.*;
Then in the application logic make use of documentation on how to access the library.
Documentation here might help: https://developer.motorola.com/docs/bluetooth-low-energy-gatt-framework-api/