Jocky for eclipse

Source: Internet
Author: User
Tags echo message
Document directory
  • I. Preface

Http://www.blogjava.net/beansoft/archive/2008/03/26/90748.html

JockyHttp://www.operamasks.org/ProjectDetails.jsp? Proid = 9c89b9f7010d1000e000007cca67bf51

Jocky is a personal work of Mr. Yuan honggang, Kingdee middleware technology leader (formerly JOC ). It was originally intended to facilitate the development of apusic application servers and is now open for free use... jocky provides support for IDE eclipse and can also be used in ant (in fact, in eclipse, it is also an ant file, and then compiled ).

It is quite useful. Most of the compiled code is decompiled with only JVM commands! It is indeed a powerful tool to protect the core of the system! JDK 1.5 is supported. But jocky is not open source... leader!

The following is a detailed description of the official IDE (apusic IDE:

Jocky

Java obfuscate compiler kit for you

I. Preface 1.1 What is jocky?

We know that Java is a cross-platform programming language. Its source code (. Java file) is compiled into a bytecode (. Class file) unrelated to the platform, and then dynamically linked at runtime. In this way, the compiled class file will contain a signed table, so that the Java program is easily decompiled. I believe that every Java developer has used anti-compilers such as Jad to decompile Java class files, so as to observe the program structure and implementation details. As a result, developers often need to address how to effectively protect customers' business investment for Java applications that require strict intellectual property protection.
As a result, the Java obfuscation compiler is used to disrupt the symbolic information in the class file, making reverse engineering very difficult.
Jocky is such an excellent Java obfuscation compiler.

1.2 Why do I need jocky?

At present, there are many commercial or open-source obfuscation compilers in the industry, but they generally have some problems. In general, the existing obfuscators confuse compiled class files. In this way, the compilation and obfuscation steps are required. In fact, not all symbols need to be confused. If you are developing a class library or some classes need to be dynamically loaded, those public APIs (or the APIs that are published by publish) must keep the symbols unchanged, other people can use your class library. The existing obfuscators provide a GUI or script to configure the symbol names to be retained. However, if the program is large, the configuration becomes complicated. Once the program is modified, the configuration must be performed again. Some obfuscators can adjust the byte code sequence to make decompilation more difficult. However, I have experienced program running errors after obfuscation.
The biggest difference between jocky and other obfuscation compilers is that it is directly written from the source code, that is, the compilation process itself is a obfuscation process.

1.3 How does jocky work?

The jocky obfuscation compiler is based on the Java compiler (javac) provided by Sun JDK. It modifies the code generation process and obfuscation the intermediate code generated by the compiler, finally, generate the class file. In this way, only one step is required for compilation and obfuscation. You can also insertSymbol retention commandTo control which symbols need to be retained and combine the obfuscation process with the development process without separate configuration.

1.4 jocky's role 1.4.1 code obfuscation

As mentioned above, obfuscation compilation is the primary purpose of jocky. Let's take a simple example. The simplebean below is the source file obtained after non-obfuscation of the class file through Jad decompilation:

public class SimpleBean implements Serializable {
private String name = "myname";
private List myList = null;
  public void SimpleBean() {
myList = new ArrayList(10);
}
  public void foo1() {
myList.add("name");
}
private void foo2() {    
}
private void writeObject(java.io.ObjectOutputStream out)
throws IOException {
}
}

<Unobfuscated class file decompilation results>

The following is a class file obfuscated by jocky, which is generated after Jad decompilation:

public class SimpleBean implements Serializable {
private String _$2;
private List _$1;
  public SimpleBean() {
_$2 = "myname";
this;
JVM INSTR new #4   <Class ArrayList>
JVM INSTR dup ;
JVM INSTR swap ;
10;
ArrayList();
_$1;
}  
  public void foo1() {
_$1.add("name");
}
private void _$1() {
}
private void writeObject(ObjectOutputStream objectoutputstream){
throws IOException {
}
}

<Decompilation of class files obfuscated by jocky>

1.4.2 support compiling the JDK 5.0 syntax into class files that can be run on JDK 1.4

JDK 5.0 has many new features in terms of syntax, which can simplify application development. For example, generics, enhanced for loop, and autoboxing/unboxing. However, unfortunately, using these New syntaxes to develop applications means that it cannot run on JDK 1.4, and JDK 1.4 is currently the most popular VM version. Fortunately, another feature of jocky is that through parameter configuration, applications written in JDK 5.0 syntax can be compiled into the class file version on JDK 1.4. We can open the class file compiled by jocky with ultraedit. We can find that the value of the class file major version on the 8th bytes is 0x30, that is, 48 in decimal format, this is the version of the class file that JDK 1.4 can understand (JDK 5.0 compiles the class file version 49 by default ). The premise is that some APIs not available in JDK 1.4 cannot be used in applications.

Ii. jocky usage 2.1 General Usage

It is very easy to use jocky to obtain jocky. after jar, you only need to run Java-jar jocky. jar can start the jocky obfuscation compiler. The command line parameters of jocky are identical to those of javac, but a new parameter-scramble is added. Its usage is as follows:

-Scramble obfuscation of all package private or private symbols-scrambleall obfuscation of all symbols-scramble: <level> obfuscation of symbols of the corresponding level where <level> specifies the obfuscation level, which can be of the following levels: -scramble: None do not confuse-scramble: Private obfuscation of all elements of the private access level-scramble: Package obfuscation of all private or package private elements-scramble: protected obfuscation of all private, package private, and protected elements-scramble: Public obfuscation of all elements-scramble: All is equivalent to-scramble: public if you use-scramble without a level parameter, it is equivalent to-scramble: Package
2.2 jocky for ant

In recent years, ant has become the de facto standard for packaging tools in Java application development. In the process of application development, we usually have an ant script that can be used to compile, package, and publish an application. Therefore, the best entry point for jocky is ant support.
Using jocky in ant is very simple:
Copy the LIB/jocky-ant.jar to the ant_home/lib directory.
2. add such a line of code to the ant script to introduce jocky task

<Taskdef resource = "jockytasks/">

3. Set some basic attributes of jocky, including the location of the jocky. jar package and the obfuscation level, as shown below:

<Jocky jar = "F:/works2/jocky/jocky1.0/lib/jocky. Jar" enable = "true" level = "private/">

4. when the Enable attribute of jocky is set to true, the javac compilation command in the ant script is automatically replaced with the jocky compiler. When the Enable attribute is set to false, the javac compilation command will return to normal settings. The sample script is as follows:

<Project name = "jocky" default = "build">

<! -- Introduce jocky ant task, make sure that the jocky-ant.jar is in the ant_home/lib directory -->

<Taskdef resource = "jockytasks"> </taskdef>

<Target name = "build">

<! -- Set the location and obfuscation level of jocky. Jar. When enable is true, javac task will be automatically replaced with jocky obfuscation compiler -->

<Jocky jar = "F:/works2/jocky/jocky1.0/lib/jocky. Jar" enable = "true" level = "private"> </jocky>

<! -- The following compilation will use the jocky obfuscation compiler -->

<Javac destdir = "bin2" DEBUG = "on" Source = "1.5" target = "1.4">

<SRC Path = "src"> </src>

</Javac>

<! -- When enable is set to false, the javac task will be restored to the normal setting, and the jocky compiler will no longer work. -->

<Jocky enable = "false"> </jocky>

<! -- The following compilation will use the normal javac compiler -->

<Javac destdir = "bin3" DEBUG = "on" target = "1.4">

<SRC Path = "src"> </src>

</Javac>

</Target>

</Project>

<Example of the ant script of jocky>

Note: jocky for ant is developed on Ant 1.6.5. This version is recommended.

2.3 jocky for eclipse

Jocky provides Eclipse plug-ins so that jocky can be used directly in eclipse.
1. Install the jocky plug-in:
Installing the jocky plug-in eclipse is very simple. You only need to copy the eclipse/plugins/org. apusic. jocky_1.0.0 directory to the eclipse plugins directory. Alternatively, you can use the Link Method in the eclipse/links folder to specify the jocky ins directory.
2. Use jocky in Eclipse:
Using jocky in eclipse is also very simple. For any Java project, you can right-click the project and choose the shortcut menu of jocky:

<Jocky right-click the menu in eclipse>

<Jocky attribute settings in eclipse>

In fact, when jocky is used in eclipse, jocky first generates the ant Build File (default name: jocky_build.xml) for the selected project, and then completes obfuscation compilation through ant.
The following is an example of the ant build file automatically generated by jocky in Eclipse:

<Project basedir = "." default = "build" name = "jocky. example. jocky">

<Property name = "jocky. Jar" value = "F:/eclipsewtp1.0.8/workspace_jdk5_apusicstudio/org. apusic. jocky/jocky. Jar"> </property>

<Property name = "jocky. Output. dir" value = "jocky"> </property>

<Property name = "jocky. Scramble. Level" value = "package"> </property>

<Property name = "target" value = "1.4"> </property>

<Path id = "project. classpath">

<Pathelement location = "bin"> </pathelement>

</Path>

<Target name = "init">

<Jocky jar = "$ {jocky. Jar}" level = "$ {jocky. Scramble. Level}"> </jocky>

<Mkdir dir = "$ {jocky. Output. dir}"> </mkdir>

<Mkdir dir = "$ {jocky. Output. dir}/bin"> </mkdir>

</Target>

<Target name = "clean">

<Delete dir = "$ {jocky. Output. dir}/bin"> </delete>

<Delete dir = "$ {jocky. Output. dir}"> </delete>

</Target>

<Target depends = "init" name = "build">

<Echo message = "$ {ant. Project. Name }:$ {ant. File}"> </echo>

<Jocky enable = "true"> </jocky>

<Javac destdir = "$ {jocky. Output. dir}/bin" target = "$ {target}">

<SRC Path = "src"> </src>

<Classpath refID = "project. classpath"> </classpath>

</Javac>

</Target>

</Project>

<Example of ant script automatically generated by jocky in eclipse>

Note 1: Only eclipse 3.1.1 and later versions are supported.
NOTE 2: If the jocky plug-in cannot be found in eclipse, delete the eclipse installation directory/configuration/org. Eclipse. Update folder (maybe an eclipse bug ?).

2.4 how to use the symbol retention command

In addition to using the-scramble parameter in the command line to control the symbol obfuscation level, you can also use the symbol retention command in the source code to control the symbols to be retained. The symbol retention instruction is a Java document comment instruction that can be inserted into the document comment of classes and class members. For example:

/**
* This class should preserve.
* @preserve
*/
public class Foo {
/**
* You can specify which field should be preserved.
* @preserve
*/
private int x;
/**
* This field is not preserved.
*/
private int y;
/**
* You can also preserve methods.
* @preserve
*/
public void hello() {}
/**
* This method is not preserved.
*/
private void collect() {}
}

<Example of using the preserved command>

If the @ preserve command is not available, determine whether the symbol is retained Based on the obfuscation level and the access level of the member.
The Class symbol retention command can include a retention level parameter to control the symbol retention of class members, including:

@ Preserve only retains the class name, class member retention is determined by the-scramble command line parameter @ preserve public keep all public members @ preserve protected keep all public and protected members @ preserve package keep all public, protected, package private member @ preserve private keep all members @ preserve all is equivalent to @ preserve private

In fact, even if the @ preserve command is not added, jocky does not confuse some private-level methods that are unique to the Java language, for example, writeobject and readobject methods that have special functions during serialization. However, I strongly recommend that you use the @ preserve command to protect private-level methods or fields with special meanings that cannot be obfuscated.
Note 1: We recommend that you use the javadoc setting of IDE to help write the @ preserve command.

3. Restrictions on jocky

As mentioned above, jocky is a source code-based obfuscation compiler. Therefore, jocky does not support separate compilation, and all source files must be obfuscated at the same time. But in fact, if the obfuscation level is controlled at the private level, this restriction will no longer exist.

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.