Java decode class file

How do I decompile a java class file? [closed]

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

I understand that similar questions to this have been asked, but non of them have answered how to decompile a java class with java. I want to make a java decompiler in java but I do not know how to take the contents of a class file and convert it to a java file. I am quite sure I will be able to open up a jar file and view it’s contents, but my question is how do I decompile the class files in the jar? I do not want a decompiler; I want to make my own. I am assuming that every compiler for java encrypts the code the same way and I just want to know what that is or how to reverse it. I do not know much about how java code is compiled, but I am pretty sure it has something to do with the jdk developer kit. Lets say I have an entire class loaded into a byte array. How would I convert the byte array to readable code. I have a java decompiler right now, but it is an executable, so I can not decompile it and see how it is done. I understand that it will take a lot of information to answer this question, and I have very little knowledge of how Java compiles java file, so if you could point me in the right direction to learn how java compiles stuff. Could you simply post links to tutorials or things I should read to learn how to decompile a class or how java compiles classes in the first place?

Читайте также:  Android java runtime class

Источник

.JAR and .Class to Java decompiler

Until recently, you needed to use a Java decompiler and all of them were either unstable, obsolete, unfinished, or in the best case all of the above. And, if not, then they were commercial. The obsoleteness was typically proved by the fact that they can only decompile JDK 1.3 bytecode.
The only so-so working solution was to take the .class file and pre-process it, so it becomes JDK 1.3 compatible, and then run Jad over it (one of those older, but better decompilers).

But recently, a new wave of decompilers has forayed onto the market: Procyon, CFR, JD, Fernflower, Krakatau, Candle.
Here’s a list of decompilers presented on this site:

CFR

This free and open-source decompiler is available here: http://www.benf.org/other/cfr/
Author: Lee Benfield

  • Java 7: String switches
  • Java 8: lambdas
  • Java 9: modules
  • Java 11: dynamic constants
  • Java 12: Kotlin style «switch expressions»
  • Java 14: ‘instance of’ pattern match and ‘Record types’
JD

free for non-commercial use only, http://jd.benow.ca/
Author: Emmanuel Dupuy

Updated in 2015. Has its own visual interface and plugins to Eclipse and IntelliJ . Written in C++, so very fast. Supports Java 5.

Procyon
  • Enum declarations
  • Enum and String switch statements
  • Local classes (both anonymous and named)
  • Annotations
  • Java 8 Lambdas and method references (i.e., the :: operator).
Fernflower

Updated in 2015. Very promising analytical Java decompiler, now becomes an integral part of IntelliJ 14. (https://github.com/JetBrains/intellij-community/tree/master/plugins/java-decompiler)
Supports Java up to version 6 (Annotations, generics, enums)

JAD

given here only for historical reason. Free, no source-code available, jad download mirror
Author: Pavel Kouznetsov

Probably, this is the most popular Java decompiler, but primarily of this age only. Written in C++, so very fast.
Outdated, unsupported and does not decompile correctly Java 5 and later.

Источник

How do I decode a Java 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.

The file extension for the application package is.apk. The applications are installed on the operating system in an APK file. All of the parts of the program are packaged into a single file to make it an APK file.

Drag the APK file you want to install (either Google’s app package, or another) into your SDK folder. Next, use the command prompt to enter (in that folder) adb installation while your AVD runs. apk You should add the app to your virtual device’s app list.

How do I view a .class file?

Programs that can open CLASS files Eclipse IDE for Java Developers, with JD-Eclipse plug in. Jetbrains IntelliJ IDEA Consequently, can java read .class files? It produces bytecode, which is not Java-like code, but it is very readable and instructive. If you really want to, You can open any. Open a hex editor to create a class file and then read the bytecode directly. The result is identical to using Javap

Moreover, what are the contents of a .class file in java?

What is in a Java class file? The Java class file contains all the information a JVM requires about one Java interface or class. The main components of the Java class file are listed in order of appearance. magic, version constant pool, access flags. This class, superclass, interfaces. Fields, methods. and attributes How do I open a Java class file in eclipse? All you need to do to source is to use your browser or file editor. Find the file. You can then open it in you know that it doesn’t need to be in a Project to do it.

A cascading style sheet is a file used to format the contents of a website. It has global properties for how to display. CSS files can be used to define the size, color, fonts, line spacing, and location of elements.

In respect to this, can we edit .class file java?

Save the class file to your computer. Open the class file using «Dirty Joe Java Overall Editor», make the necessary changes, and then click file/save. Once you’re done, you will have a working exe with all the modifications you made. There is no need to decompile Correspondingly, where the class file is saved in java? When you compile Java, a class file in Java is generated. Java file generated by any Java compiler such as Sun’s javac. It is included with JDK installation.

You can also ask how do i open a class file in text editor?

Binary files are class files. They are not text files and therefore, Can’t be opened with a text editor You will need an editor to view the binary file. One may also ask how do i view a java file? To run the file (Java Runtime Environment). Right-click the file to open it and choose Open With Click the Browse button in the Open With window to open the File Explorer window. You will need to locate the Java executable (java.exe) file on your computer’s hard drive.

And another question, how do i open a .class file in intellij?

Navigate using the Select In popup The Project tool window will automatically locate the class. If the class is opened in editor, To open the Select In popup, press Alt+F1. Select Project View in the popup and hit Enter. IntelliJ IDEA locates the target in the Project tool window.

Similar articles

  • What does DWG file stand for? DWG is a file format used for 2D and 3D design data. DWG files are a type of computer aided design drawings. It is the native format of most applications.
  • What does EML file stand for? A file extension for an email message saved to a file in the internet message format is called electronic mailEML. Microsoft Outlook Express and other email programs use the standard format.
  • What’s the meaning of RAW file? A raw file is the image data captured by a digital camera. A high level of image detail is captured with large file sizes.
  • What is ICA file? The ICA file is used by the application server. The configuration information may be used to link to a published application or a server desktop environment.
  • How do I translate a JSON file?
  • How do I open a CBR file?
  • What exactly is an EPS file?
  • What can open a DDS file?

Источник

How to decompile Java class files?

Every Java developer during their career comes across a common situation where he/she has to work with existing 3rd party .jar files. You might have already been through this and if you are reading this article then chances are that you are facing this problem right now.

Let’s elaborate on the problem for newbies. Suppose you are working with any third party JAR file and you need to check the code written in it or let’s say you have created a JAR file that you have to share with someone and later you want to check the code in it. So the question here is, as we know JAR file will have .class files which we can’t see directly, then, how are we going to check the code written in it?

Here comes the role of Java Decompiler. Let’s check below what Decompiler is and how to use it.

What is Decompiler?

The art of «decompiling» can also be thought upon as reverse engineering. Decompilation involves transforming the bytecode back into Java source.

How to do it?

We have various ways and tools to achieve it. The tool that I prefer is «Java Decompiler» which can be found at http://java-decompiler.github.io/. In this tool, I prefer Java Decompiler’s UI version which is known as «JD-GUI».

JD-GUI is a standalone application that is used to display Java source codes of .class files. You can browse any .class file and the source code can be seen in the tool directly.

As we are using decompiler we need to be very cautious as a lot of low-level information(like comments etc) will get lost in the converted Java source code.

For example, let’s say we have a code which prints a message «Hello World» and it also has a comment section as shown below:

using Java decompiler

Now, when you compile your .java file you will have .class file with you. When you try to decompile this .class file using «JD-GUI» the java source code will look as below:

Using java decompiler

Here, you can see the difference. We don’t have the comments in the decompiled version. Additionally, the string parameter present in the main method has also been changed along with the formatting of the code.

Conclusion:

To see the code that is present in .class format file we will need one of the many Java decompilers that are available. In this blog we saw how to use «Java Compiler: JD-GUI» to convert our byte code to the Java source code. I hope the blog makes sense about what decompiler is used for and how to use it. For any questions/comments you can always connect us.

You may also like:

Источник

Оцените статью