Talking about the decompile of Java program

Source: Internet
Author: User
Tags bit set return zip
compiling | programs

Talking about the decompile of Java program

Now that the Java language is wildly popular around the world, it is widely used in the production of Internet databases, multimedia, CGI, and Dynamic Web pages. Demand for Java programmers in the United States exceeded c++! for the first time in 1999
Recently analyzed a number of Java programs, to the Java decompile a bit of understanding, the following I understand the situation as described below, I hope to help Java enthusiasts.
Java is a program structure called "Byte Encoding", which is divided into small programs (embedded in HTML files) and applications (executed directly in the command state) of two types. Regardless of the structure, once compiled with the Javac command, it becomes an executable with the same name as the suffix class. This file is not readable code.
After reviewing the Sun's JDK (JDK1.1.3) documentation, I found a javap file (EXE) that was supposedly decompile Java, located under \jdk\bin\, and was disappointed after being used by the instructions, which turned out to be a "decompile" You can only decompile the data area (definition) of a Java program, references to several methods, and classes, and so on.
Here I use a simple example to illustrate the problem.
Java source program Hello_java.java is as follows:
Import java.applet.*;
Import java.awt.*;
public class Hello_java extends Applet
{
public void Paint (Graphics g)
{
g.DrawString ("Hello java!\n", 20,20);
}
}
Anti-compile command: javap-c-package-public-private Hello_java Hello.java
The resulting decompile results (Hello.java) are as follows: (see the instructions for selecting the JAVAP command, here-C indicates that the decompile was selected)
Compiled from Hello_java.java
Public synchronized class Hello_java extends Java.applet.Applet
/* Acc_super bit set */
{
public void paint (java.awt.Graphics);
public Hello_java ();
method void Paint (Java.awt.Graphics)
0 aload_1
1 LDC #1
3 Bipush 20
5 Bipush 20
7 invokevirtual #6
Ten return
Method Hello_java ()
0 Aload_0
1 invokespecial #5 () v>
4 return
}
From the above results it is not difficult to see that the decompile failed to translate the source program into full, like the statement g.drawstring ("Hello java!\n", 20,20); There is no. There will be more Java statements that failed to compile as the program volume increases. So this counter compiler can only play a reference role.
Thanks to the Internet, the author quickly found a Java decompile "free Software" (shareware), http://www.inter.nl.net/users/H.P.van.Vliet/mocha.htm via Yahoo. The software, called Mocha, is said to have been completed by a 30-Year-old graduate student in Canada, only a "?" Version, the reason is that this guy called H.p.van.vliet died of cancer, it is a pity!
After using mocha decompile software, I feel this software is very easy to use, the author tried to decompile a number of Java programs, have been very good results.
Here gives how to use this software, first of all, with WinZip and so on "mocha-b1.zip" to unlock "mocha.zip" file, "Mocha.zip" no need to untie, this package includes the reverse-compiled class file, just copy it to the JDK in the directory, such as: C : \jdk\bin\ In addition, you must set the path: Set Classpath=c:\myclasses;c:\jdk\bin\mocha.zip
Mocha Usage:
Java Mocha. Decompiler [-v] [-o] class1.class class2.class ...
Java calls Java virtual machines
"Mocha. Decompiler "indicates that you want to do a Java decompile
"-V" select Verbose output
"-O" Optional write to an existing. Mocha file
"Classx.class" indicates that you want to decompile the class name
Note that the Java filename for the output is not required because Mocha automatically produces a Java source file with the same name as class but with the extension mocha.
For the previous example, you can use the command:
Java Mocha. Decompiler [-v] [-O] Hello_java.class
Source files obtained:
/* decompiled by Mocha from Hello_java.class * *
/* Originally compiled from Hello_java.java * *
Import Java.applet.Applet;
Import Java.awt.Graphics;
Public synchronized class Hello_java extends Applet
{
public void Paint (Graphics g)
{
g.DrawString ("Hello java!\n", 20, 20);
}
Public Hello_java ()
{
}
}
It's not hard to find that this file is exactly the same as the Java source file before it was compiled! The author has been using Mocha to decompile the largest 80K source files, have been successful.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.