Allatori代码混淆
*在项目(模块)中添加代码混淆,采用allatori官网提供的allatori.jar,本案例采用SpringBoot搭建,maven私服搭建引入allatori依赖
一、采用pom方式引入
1、pom.xml中引入依赖
在dependencies标签中添加
<!-- 私服allatori -->
<dependency>
<groupId>com.cs.allatori</groupId>
<artifactId>allatori</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
在plugins标签中添加
<!-- 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>${settings.localRepository}/cs/xxx/xxxx/allatori/allatori/1.0/allatori-1.0.jar</argument>
<!-- allatori混淆的配置文件-->
<argument>${basedir}/src/main/resources/allatori.xml</argument>
</arguments>
</configuration>
</plugin>
<!-- Allatori plugin end -->
二、直接引入allatori.jar方式
TODO
三、添加代码混淆配置文件allatori.xml
官配详细配置
项目的resources目录中添加allatori.xml配置文件,写入以下配置,按自己的项目做配置调整
<config>
<!-- cs-xxxxxx-compile 原编译的jar文件,cs-xxxxxx 混淆后的输出的jar文件 -->
<input>
<jar in="../../../target/cs-xxxxxx-compile.jar" out="../../../target/cs-xxxxxx.jar"/>
</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.cs.biz.pojo.*"/>
<class template="class com.cs.biz.vo.*"/>
<class template="class com.cs.biz.config.*"/>
<class template="class com.cs.biz.mapper.*"/>
<!-- 排除启动类 -->
<class template="class com.cs.biz.xxxxxxBootstrap"/>
<!-- 排除springboot依赖文件(springboot构建的项目需要排除,否则业务程序会报错) -->
<class template ="class org.springframework.boot.*"/>
</ignore-classes>
<!-- 广泛流混淆 最大级别混淆-->
<property name="extensive-flow-obfuscation" value="maximum" apply2class="class com.cs.biz.*"/>
<property name="extensive-flow-obfuscation" value="maximum" apply2class="class com.cs.rest.*"/>
<!-- 其他路径正常混淆 -->
<property name="extensive-flow-obfuscation" value="normal"/>
<!-- 到期时间(到期后无法启动jar) 格式:yyyy/mm/dd-->
<expiry date="2019/09/09" string="EXPIRED!"/>
<!-- 随机命名混淆字符-->
<property name="random-seed" value="cshxzf jrncbd hh"/>
</config>