Jocky是金蝶中间件技术领袖袁红岗先生的个人作品(旧有名称JOC)。原本是方便Apusic 应用服务器的开发,现在开放出来,供大家自由使用 ... Jocky提供了对IDE Eclipse的支持,同时,也支持在Ant中使用(事实上,在Eclipse中,也是先生成一个ant文件,然后再编译).
是挺好用, 编译后的代码大部分反编译出来只有 JVM 指令! 的确是保护系统核心的利器! 支持 JDK 1.5. 可是 Jocky 竟然不开源... 领袖啊!
以下是官方IDE(Apusic IDE)中的详细说明:
原帖地址:http://www.cnblogs.com/qima/archive/2012/08/06/2625041.html
资源下载:http://download.csdn.net/detail/rchm8519/7993427
Jocky
Java Obfuscate Compiler Kit for You
1
public
class SimpleBean
implements Serializable
{ 2 3 private String name = "myname"; 4 5 private List myList = null; 6 7 public void SimpleBean() { 8 myList = new ArrayList(10); 9 } 10 11 public void foo1() { 12 myList.add("name"); 13 } 14 15 private void foo2() { 16 } 17 18 private void writeObject(java.io.ObjectOutputStream out) 19 throws IOException { 20 21 } 22 23} |
<未混淆的类文件反编译后的效果> |
1
public
class SimpleBean
implements Serializable
{ 2 3 private String _$2; 4 5 private List _$1; 6 7 public SimpleBean() { 8 _$2 = "myname"; 9 this; 10 JVM INSTR new #4 <Class ArrayList>; 11 JVM INSTR dup ; 12 JVM INSTR swap ; 13 10; 14 ArrayList(); 15 _$1; 16 } 17 public void foo1() { 18 _$1.add("name"); 19 } 20 21 private void _$1() { 22 } 23 24 private void writeObject(ObjectOutputStream objectoutputstream){ 25 throws IOException { 26 } 27} |
<Jocky混淆过的类文件反编译的效果> |
-scramble 混淆所有package private或private符号 -scrambleall 混淆所有符号 -scramble: < level > 混淆相应级别的符号 其中 < level > 指定混淆级别,可以是以下几种级别: -scramble:none 不进行混淆 -scramble:private 对所有private访问级别的元素进行混淆 -scramble:package 对所有private或package private元素进行混淆 -scramble:protected 对所有private, package private, protected元素进行混淆 -scramble:public 对所有的元素都进行混淆 -scramble:all 相当于-scramble:public 如果使用-scramble不带级别参数,则相当于-scramble:package
1
<
project
name
="jocky"
default
="build"
>
2 <!-- 引入Jocky Ant Task,要确保jocky-ant.jar位于ANT_HOME\lib目录下 --> 3 < taskdef resource ="jockytasks" > </ taskdef > 4 < target name ="build" > 5 <!-- 设置jocky.jar的位置以及混淆级别,当enable为true时,javac task将被自动替换成Jocky混淆编译器 --> 6 < jocky jar =" F:\Works2\Jocky\jocky1.0\lib\jocky.jar" enable =" true" level =" private" > </ jocky > 7 <!-- 下面的编译,将使用Jocky混淆编译器 --> 8 < javac destdir ="bin2" debug ="on" source ="1.5" target ="1.4" > 9 < src path ="src" ></ src > 10 </ javac > 11 <!-- 当enable为false时,javac task将被恢复成正常设置, Jocky编译器不再起作用 --> 12 < jocky enable ="false" ></ jocky > 13 <!-- 下面的编译,将使用正常的Javac编译器 --> 14 < javac destdir ="bin3" debug ="on" target ="1.4" > 15 < src path ="src" ></ src > 16 </ javac > 17 </ target > 18 </ project > |
<Jocky的Ant脚本示例> |
<Jocky在Eclipse中的右键菜单> |
<Jocky在Eclipse中的属性设置> |
1
<
project
basedir
="."
default
="build"
name
="jocky.example.jocky"
>
2 < property name ="jocky.jar" value ="f:\EclipseWTP1.0.8\workspace_jdk5_apusicstudio\org.apusic.jocky\jocky.jar" ></ property > 3 < property name ="jocky.output.dir" value ="jocky" ></ property > 4 < property name ="jocky.scramble.level" value ="package" ></ property > 5 < property name ="target" value ="1.4" ></ property > 6 < path id ="project.classpath" > 7 < pathelement location ="bin" ></ pathelement > 8 </ path > 9 < target name ="init" > 10 < jocky jar ="${jocky.jar}" level ="${jocky.scramble.level}" ></ jocky > 11 < mkdir dir ="${jocky.output.dir}" ></ mkdir > 12 < mkdir dir ="${jocky.output.dir}/bin" ></ mkdir > 13 </ target > 14 < target name ="clean" > 15 < delete dir ="${jocky.output.dir}/bin" ></ delete > 16 < delete dir ="${jocky.output.dir}" ></ delete > 17 </ target > 18 < target depends ="init" name ="build" > 19 < echo message ="${ant.project.name}: ${ant.file}" ></ echo > 20 < jocky enable ="true" ></ jocky > 21 < javac destdir ="${jocky.output.dir}/bin" target ="${target}" > 22 < src path ="src" ></ src > 23 < classpath refid ="project.classpath" ></ classpath > 24 </ javac > 25 </ target > 26 </ project > |
<Jocky在Eclipse中自动生成的Ant脚本示例> |
1
/**
2 * This class should preserve. 3 * @preserve 4 */ 5 public class Foo { 6 /** 7 * You can specify which field should be preserved. 8 * @preserve 9 */ 10 private int x; 11 12 /** 13 * This field is not preserved. 14 */ 15 private int y; 16 17 /** 18 * You can also preserve methods. 19 * @preserve 20 */ 21 public void hello() {} 22 23 /** 24 * This method is not preserved. 25 */ 26 private void collect() {} 27 } |
<使用preserved指令的示例> |
事实上,即便不加@preserve指令,Jocky对Java语言特有的一些private级别的方法不进行混淆,譬如,在序列化时有特殊作用的writeObject及readObject方法等。但笔者强烈建议: 针对这些有特殊含义不能够被混淆的 private级别的方法或者字段,请以@preserve指令予以保护。@preserve 仅对类名进行保留,类成员的保留根据-scramble命令行参数决定 @preserve public 保留所有public成员 @preserve protected 保留所有public和protected成员 @preserve package 保留所有public, protected, package private成员 @preserve private 保留所有成员 @preserve all 相当于@preserve private