首页
技术知识库
Task工作计划
网站简介
DON框架
后台管理
文章分类
JAVA
框架知识
操作系统
容器相关
数据库层
优化技术
界面编程
网络编程
开发工具
GO语言
其他
读书随笔
观影随笔
每日随笔
APP
JAVA代码混淆方案
所属分类
:[JAVA] |
创建时间
:2014-11-11 |
文章属性
:原创 |
文章来源
:http://windfly.cn |
作者
:windfly
##目的 >可快速、方便地对已经完成的jar或web项目进行代码混淆 ##选用技术 >Allatori-5.1-Demo版,商用软件的演示版。在代码中会有System.out的打印 DEMO VERSION! NOT FOR COMMERCIAL USE!语句,在混淆的代码名中也会使用ALLATORI_DEMO关键字,但对项目运行没有明显影响。 ##依赖两个jar包和一个配置文件 >allatori.jar >allatori-annotations.jar >config.xml ##运行方式 >java -Xms128m -Xmx512m -jar allatori.jar config.xml ##配置文件常用内容 ##针对桌面程序 ``` <config> <jars> <jar in="test.jar" out="obf-test.jar"/> <jar in="mousegestures-1.2.jar" out="obf-mousegestures-1.2.jar"/> </jars> <keep-names> <class template="class *.TestFrame"/> </keep-names> <property name="log-file" value="log.xml"/> </config> ``` ##针对web程序,即war包,以某springMVC项目为例 ``` <config> <jars> <jar in="${basedir}/war/vmp-product.war" out="${basedir}/war/obf-vmp-product.war"/> </jars> <classpath> <jar name="${basedir}/WebContent/WEB-INF/lib/*.jar"/> <jar name="${basedir}/devLib/*.jar"/> </classpath> <keep-names> <!-- <class access="protected+"> <field access="private+"/> <method access="private+" parameters="keep"/> </class> --> <!-- <class access="private+" ignore="true"> <field template="*Service"/> <field template="*Dao"/> </class> --> <!-- 在web.xml或spring配置文件中显示指定的类文件和方法必须保留 --> <class template="public class *.interceptor.*"> <method template="public get*(*)"/> <method template="public set*(*)"/> </class> <class template="public class *.listener.*"> <method template="public get*(*)"/> <method template="public set*(*)"/> </class> <class template="public class *.filter.*"> <method template="public get*(*)"/> <method template="public set*(*)"/> </class> <class template="class com.ausc.vmp.core.controller.MultView"> <method template="public get*(*)"/> <method template="public set*(*)"/> </class> <!-- springMVC的controller映射方法参数名必须保留 --> <class template="public class *Controller" ignore="true"> <!-- <field template="*Service"/> <field template="*Dao"/> --> <method access="public" parameters="keep"/> </class> <!-- ORM实体映射和POJO必须保留,实体可能是按类名和属性名映射,POJO类可能会在JSP文件中被用到取属性值 --> <class template="public class com.ausc.vmp.core.beans.*"> <field access="private+"/> <method template="public get*(*)"/> <method template="public set*(*)"/> <method template="public is*(*)"/> <method template="public has*(*)"/> </class> <class template="class com.ausc.vmp.plug.wh.bean.*"> <field access="private+"/> <method template="public get*(*)"/> <method template="public set*(*)"/> <method template="public is*(*)"/> <method template="public has*(*)"/> </class> <!-- 工具类可能会在JSP文件中被用到,必须保留 --> <class template="public class com.ausc.vmp.common.*"> <field template="public static *"/> <method access="public"/> </class> </keep-names> <property name="log-file" value="${basedir}/war/log.xml"/> <!-- 字符串加密 --> <property name="string-encryption" value="enable"/> <property name="string-encryption-type" value="fast"/> <!-- 混淆时,windows下不区分大小写,所以使用小写字母并且文件名唯一 --> <property name="classes-naming" value="abc"/> <property name="classes-naming" value="unique"/> <!-- 保留异常信息中原代码里的类名和行数 --> <property name="line-numbers" value="keep"/> <!-- 加入定义关键字 --> <property name="version-marker" value="AU_COMP_VERSION"/> <!-- 文件水印签名 --> <watermark key="secure-key-to-extract-watermark" value="Customer: windfly"/> <!-- 设置项目有效期 --> <expiry date="2014/12/12" string="EXPIRED!"/> </config> ``` ##与ant集成 ``` <target name="obfuscate" depends="jar"> <taskdef name="allatori" classname="com.allatori.ant.ObfuscatorTask" classpath="allatori.jar"/> <allatori config="config.xml"/> </target> ```
返回