Allatori介绍
Allatori是第二代Java混淆器,可为您的知识产权提供全方位的保护。
尽管大多数第二代混淆器都提供了值得保护的级别,但我们已经在Allatori中开发了许多附加功能,
以使对代码进行逆向工程几乎不可能。
Allatori不仅会混淆,还会最大程度地减少应用程序的大小并提高速度,同时您和您的团队以外的任何人
都无法读取您的代码。作为每个现代Java混淆器,Allatori具有完整的水印功能,从而有可能为您的软件
提供适当的许可!
如果有必要保护您的软件,并且要减少软件的大小和缩短处理时间,则可以使用Allatori混淆器。
- - - 摘自官网
官网首页:http://www.allatori.com/
官网文档:http://www.allatori.com/doc.html/
使用
- 官网下载jar包,将jar包放入项目中
- 配置maven插件,如果是maven多模块,可以将jar包提取到父目录共用,xml文件各自配置各自的
<!-- Allatori plugin start -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>run-allatori</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Xms128m</argument>
<argument>-Xmx512m</argument>
<argument>-jar</argument>
<!-- allatori混淆的jar文件目录 -->
<argument>../lib/allatori.jar</argument>
<!-- allatori混淆的配置文件-->
<argument>${basedir}/src/main/resources/allatori.xml</argument>
</arguments>
</configuration>
</plugin>
<!-- Allatori plugin end -->
- 配置allatori.xml文件,配置混淆规则
混淆的成功与否在于配置的对与错
<config>
<!-- cs-xxxxxx-compile 原编译的jar文件,cs-xxxxxx 混淆后的输出的jar文件 -->
<input>
<jar in="../../../target/artemis-web-1.0-SNAPSHOT.war" out="../../../target/artemis-web.war"/>
</input>
<!-- 不替换类名、方法名、属性名 -->
<keep-names>
<class access="protected+">
<field access="private+"/>
<method access="protected+"/>
</class>
</keep-names>
<!-- 接口形参名保持不变 -->
<property name="local-variables-naming" value="keep-parameters"/>
<!-- 排除(不做代码混淆)-->
<ignore-classes>
<!-- 排除指定路径 -->
<!--<class template="class com.caxs.warn.config.*"/>-->
<!-- 排除启动类 -->
<class template="class com.caxs.artemis.ArtemisWebApplication"/>
<class template="class com.caxs.artemis.shiro*"/>
<class template="class com.caxs.artemis.config*"/>
<class template="class com.caxs.artemis.redis.service.*"/>
<class template="class com.caxs.artemis.hive.datasource.*"/>
<class template="class com.caxs.artemis.api*"/>
<class template="class com.caxs.artemis.base*"/>
<class template="class com.caxs.artemis.enums*"/>
<class template="class com.caxs.artemis.**.dto*"/>
<class template="class com.caxs.artemis.**.domain*"/>
<!-- 排除springboot依赖文件(springboot构建的项目需要排除,否则业务程序会报错) -->
<class template="class *springframework*"/>
<class template="class *netty*"/>
<class template="class com.alibaba.dubbo**"/>
<class template="class org.springframework.core.io.ClassPathResource"/>
</ignore-classes>
<!-- 广泛流混淆 最大级别混淆-->
<!--<property name="extensive-flow-obfuscation" value="maximum" apply2class="class com.caxs.warn.*"/>-->
<!-- 其他路径正常混淆 -->
<!--<property name="extensive-flow-obfuscation" value="normal"/>-->
<!-- 到期时间(到期后无法启动jar) 格式:yyyy/mm/dd-->
<expiry date="2020/06/15" string="EXPIRED!"/>
<!-- 随机命名混淆字符-->
<property name="random-seed" value="cshxzf jrncbd hh"/>
</config>
- 使用maven正常打包即可,在target下会生成你配置的out的jar文件
结果
注意的点
- 不混淆框架内的东西,最好只混淆自己的核心逻辑,所以在上面配置了ignore,否则可能jar包都运行不了。
- 不混淆Redis、Jbdc等相关连接信息类
- 不混淆DAO层和Entity层,因为混淆会把形参名字改掉,导致映射有问题
- 混淆Controller层时,可以配置:local-variables-naming=keep-parameters,保证形参名称不变,因为web层,spring要映射mapping和形参的,其实和上面是一样的道理