Java obfuscation compiler (turn apusic.com)

Source: Internet
Author: User
Tags add command line file system reserved return access
Compilation recently tried several Java obfuscation (Java obfuscator), feel not a completely satisfactory, so I want to simply write one. After a few pages of Java Virtual Machine specifications, the whim of other obfuscation is compiled in the byte code on the fuss, can be directly compiled from the source code into a confusing class file? It took one weeks to write a Java obfuscation compiler (Java obfuscator Compiler).


Q: What is a obfuscation?
A: Because Java programs run dynamically, the compiled target file contains signed tables, making it easy to decompile Java programs, confusing the symbolic information in class files, and making reverse engineering very difficult.


Q: What is the problem with the existing obfuscation device?
A: The existing obfuscation is confusing the compiled class file so that two steps need to be compiled and confused. Not all symbols need to be confused, if you are developing a class library, or some classes need dynamic loading, those public APIs must keep the symbols unchanged so that others can use your class library. The existing obfuscation provides a GUI or scripting way to configure the symbolic names that need to be preserved, and if the program becomes more complex when it is larger, the program will be restarted once the configuration is modified. Some obfuscation is able to adjust the order of bytecode, making it more difficult to decompile, but I have experienced a situation where a confusing program runs wrong.


Q:java How does the compiler work?
The A:java obfuscation compiler is done on the basis of the Java compiler (JAVAC) provided in the Sun JDK, modifies the code generation process, confuses the compiler-generated intermediate code, and eventually regenerates it into a class file, so that compilation and obfuscation takes only one step to complete. In addition, you can insert symbol retention directives in the source program to control which symbols need to be retained, and no separate configuration is required.


Q: How to install and run Joc?
A: Download Joc.jar (http://www.apusic.com/product/cpsy.htm), run Java-jar Joc.jar can start Java obfuscation compiler, JOC command line parameters and Javac exactly the same, but added a new parameter-xobfuscate, its use is as follows:
-xobfuscate:<level>
Where <level> specifies the level of obfuscation, which can be the following levels:
-xobfuscate:none not to be confused
-xobfuscate:private the elements of all private access levels
-xobfuscate:package to confuse all private or package private elements
-xobfuscate:protected is confused with all private, package private, protected elements
-xobfuscate:public to confuse all elements.
-xobfuscate:all is equivalent to-xobfuscate:public
If you use-xobfuscate without a level parameter, it is equivalent to-xobfuscate:package


Q: How do I use symbolic retention instructions?
A: In addition to controlling the symbol obfuscation level with the-xobfuscate parameter on the command line, you can also use symbolic reservation directives in your source code to control those symbols that need to be retained, which is a Java document annotation directive that can be inserted into a document comment for a class and class member, for example:
/**
* This class should preserve.
* @preserve
*/
public class Foo {
/**
* You can specify which field should to be preserved.
* @preserve
*/
private int x;


/**
* This field isn't preserved.
*/
private int y;


/**
* You can also preserve methods.
* @preserve
*/
public void Hello () {}


/**
* This is the not preserved.
*/
private void Collect () {}
}
If there is no @preserve directive, the symbol is persisted based on the level of obfuscation and the access level of the member.


A reserved level parameter can be attached to a symbol reservation instruction for a class to control the symbolic retention of a class member, including:
@preserve the class name is reserved only, and the retention of the class member is determined by the-xobfuscate command line arguments
Keep all public members @preserve public
@preserve protected keep all public and protected members
@preserve package retains all public, protected, package private members
Keep all members @preserve private
@preserve all equivalent to @preserve private


What are the limitations of Q:JOC?
A: Separate compilation is not supported, and all source files must be confused and compiled.




Finally, a JOC is given to confuse the effect:


Source file:


Import java.awt.event.*;
Import javax.swing.*;


public class AboutBox extends JDialog
{
Public AboutBox ()
{
InitForm ();
}


JPanel Panel1 = new JPanel ();
JButton button1 = new JButton ();
JLabel JLabel2 = new JLabel ();
JTextArea jTextArea1 = new JTextArea ();


/**
* note:the following code is required by the form designer.
* It can be modified using the Form editor. Do not
* Modify it using the Code Editor.
*/


private void InitForm ()
{
This.setdefaultcloseoperation (Windowconstants.dispose_on_close);
This.getcontentpane (). setlayout (New Java.awt.CardLayout ());
This.setmodal (TRUE);
This.setresizable (FALSE);
This.settitle ("About ...");
Panel1.setlayout (NULL);
Button1.settext ("OK");
Button1.setbounds (272, 168, 88, 24);
Panel1.add (button1);
Jlabel2.settext ("File System Viewer for Swing 1.1.1");
Jlabel2.setverticalalignment (Swingconstants.top);
Jlabel2.setbounds (64, 32, 240, 56);
Panel1.add (JLABEL2);
Jtextarea1.setfont (New Java.awt.Font ("Dialog", 0, 10));
Jtextarea1.setlinewrap (TRUE);
Jtextarea1.setopaque (FALSE);
Jtextarea1.settext ("This computer are protected by copyright)";
Jtextarea1.setwrapstyleword (TRUE);
Jtextarea1.setbounds (8, 112, 256, 80);
Panel1.add (JTEXTAREA1);
This.getcontentpane (). Add (Panel1, "Card1");
This.setsize (376, 228);
Button1.addactionlistener (New Java.awt.event.ActionListener () {
public void actionperformed (Java.awt.event.ActionEvent ev) {
button1_actionperformed (EV);
}});
}


private void button1_actionperformed (ActionEvent ev)
{
This.dispose ();
}
}


The result of Javac compiled with Jad:


Import java.awt.*;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import javax.swing.*;
Import javax.swing.text.JTextComponent;


public class AboutBox extends JDialog
{


JPanel Panel1;
JButton button1;
JLabel JLabel2;
JTextArea jTextArea1;


Public AboutBox ()
{
Panel1 = new JPanel ();
button1 = new JButton ();
JLabel2 = new JLabel ();
JTEXTAREA1 = new JTextArea ();
InitForm ();
}


private void InitForm ()
{
Setdefaultcloseoperation (2);
Getcontentpane (). setlayout (New CardLayout ());
Setmodal (TRUE);
Setresizable (FALSE);
Settitle ("About ...");
Panel1.setlayout (NULL);
Button1.settext ("OK");
Button1.setbounds (272, 168, 88, 24);
Panel1.add (button1);
Jlabel2.settext ("File System Viewer for Swing 1.1.1");
Jlabel2.setverticalalignment (1);
Jlabel2.setbounds (64, 32, 240, 56);
Panel1.add (JLABEL2);
Jtextarea1.setfont (New Font ("Dialog", 0, 10));
Jtextarea1.setlinewrap (TRUE);
Jtextarea1.setopaque (FALSE);
Jtextarea1.settext ("This computer are protected by copyright)";
Jtextarea1.setwrapstyleword (TRUE);
Jtextarea1.setbounds (8, 112, 256, 80);
Panel1.add (JTEXTAREA1);
Getcontentpane (). Add (Panel1, "Card1");
SetSize (376, 228);
Button1.addactionlistener (new ActionListener () {


public void actionperformed (ActionEvent actionevent)
{
Button1_actionperformed (ActionEvent);
}


});
}


private void Button1_actionperformed (ActionEvent actionevent)
{
Dispose ();
}
}


After Joc confuse the result of compiling with Jad:


Import java.awt.*;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import javax.swing.*;
Import javax.swing.text.JTextComponent;


public class AboutBox extends JDialog
{


JPanel _$1;
JButton _$2;
JLabel _$3;
JTextArea _$4;


Public AboutBox ()
{
_$1 = new JPanel ();
_$2 = new JButton ();
_$3 = new JLabel ();
_$4 = new JTextArea ();
_$1 ();
}


private void _$1 ()
{
2;
This
JVM INSTR swap;
Setdefaultcloseoperation ();
Getcontentpane (). setlayout (New CardLayout ());
True
This
JVM INSTR swap;
Setmodal ();
False
This
JVM INSTR swap;
Setresizable ();
"About ...";
This
JVM INSTR swap;
Settitle ();
_$1.setlayout (NULL);
_$2.settext ("OK");
_$2;
168;
272;
JVM INSTR swap;
24;
88;
JVM INSTR swap;
SetBounds ();
_$1.add (_$2);
_$3.settext ("File System Viewer for Swing 1.1.1");
_$3.setverticalalignment (1);
_$3;
32;
64;
JVM INSTR swap;
56;
240;
JVM INSTR swap;
SetBounds ();
_$1.add (_$3);
_$4;
JVM INSTR new #13 <class font>;
JVM INSTR DUP;
0;
"Dialog";
JVM INSTR swap;
10;
Font ();
SetFont ();
_$4.setlinewrap (TRUE);
_$4.setopaque (FALSE);
_$4.settext ("This computer are protected by copyright)";
_$4.setwrapstyleword (TRUE);
_$4;
112;
8;
JVM INSTR swap;
80;
256;
JVM INSTR swap;
SetBounds ();
_$1.add (_$4);
Getcontentpane (). Add (_$1, "Card1");
376;
This
JVM INSTR swap;
228;
SetSize ();
_$2.addactionlistener (This) (new IILILIIIILLLIIII);
Return
}


private void _$1 (ActionEvent actionevent)
{
Dispose ();
}




/*
static void Access$0 (AboutBox aboutbox, ActionEvent actionevent)
{
ActionEvent;
AboutBox;
JVM INSTR swap;
_$1 ();
Return
}


*/


Unreferenced inner classes:


/* Anonymous class * *
Final class IILILIIIILLLIIII
Implements ActionListener
{


public void actionperformed (ActionEvent actionevent)
{
Aboutbox.access$0 (Aboutbox.this, ActionEvent);
}



{
Aboutbox.this;
This
JVM INSTR swap;
this$0;
}
}
}


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.