一、Allatori
Allatori是一个Java 混淆器,它属于第二代混淆器,因此它能够全方位地保护你的知识产权。 Allatori具有以下几种保护方式:命名混淆,流混淆,调试信息混淆,字符串混淆,以及水印技术。对于教育和非商业项目来说这个混淆器是免费的。支持war和jar文件格式,并且允许对需要混淆代码的应用程序添加有效日期。 有项目需要对代码进行保护,比较初级的方案就是对代码进行混淆,打包之后的文件进行反编译后,就可以看到效果。此外,使用Allatori打的包体积也会小一点。
官网:http://www.allatori.com/
二、简单混淆
解压找到目录: Allatori-8.6-Demo\tutorial\step01\files
Clean.bat
config.xml 配置文件
mousegestures-1.2.jar
MouseGesturesObfuscated.bat
MouseGesturesOriginal.bat
RunAllatori.bat 双击生成混淆的jar
test.jar 混淆前的jar
如果你只有一个项目,并且混淆次数也不多,你也可以通过这种方式,把项目拷贝到这个目录,修改配置文件,手动执行混淆的脚本。
三、多项目集成idea
2.1、lib 文件夹添加
allatori.jar
allatori-annotations.jar
2.2、pom.xml
<build>
<plugins>
<plugin>
<!-- springboot打包插件 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<!-- resouces拷贝文件插件 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<!-- 执行这个插件的时候执行申明的所有phase -->
<execution>
<id>copy-and-filter-allatori-config</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- 这个地方需要注意拷贝的文件位置需要是target目录,target目录是最终打jar包存放的位置 -->
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<!-- 这个地方的文件目录需要注意,网上很多目录都是${basedir}/allatori这个,所以才会需要手动拷贝allatori.xml文件到target/config目录下,有了这个mvn会自动帮我们拷贝了 -->
<directory>src/main/resources/config</directory>
<includes>
<!-- 配置文件文件名 -->
<include>allatori.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<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包位置,这里把jar包放在了根目录下的lib目录里 -->
<argument>../lib/allatori.jar</argument>
<!-- 指定代码混淆时的配置文件,因为是混淆指定的是jar包,jar包位置在target下,所以我们的allatori.xml也需要拷贝到该目录下 -->
<argument>${basedir}/target/allatori.xml</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
2.3、allatori.xml
<config>
<input>
<!-- in中是待混淆的jar包,out是混淆后的jar包,路径是相对本配置文件所在位置 -->
<jar in="web-api-1.0.jar" out="web-obfuscated.jar"/>
</input>
<!-- ignore-classes中配置不被混淆的类 -->
<ignore-classes>
<!-- 配置了启动相关类不被混淆,保证springboot可以正常启动 -->
<class template="class *Application*"/>
<class template="class *springframework*"/>
<class template="class *alibaba*"/>
<class template="class *persistence*"/>
<class template="class *apache*"/>
<class template="class *model*"/>
<class template="class *enums*"/>
<class template="class *repository*"/>
</ignore-classes>
<keep-names>
<!-- 防止部分类、方法、变量找不到名称而报错 -->
<!-- 所有方法名称不变,parameters="keep"表示方法参数名也不变 -->
<method template="*(**)" parameters="keep"/>
<!-- com.a.b.c中的类以及其子包中的类的名称不变 -->
<!-- <class template="class com.a.b.c.*"/>-->
</keep-names>
<property name="log-file" value="log.xml"/>
</config>
打包 mvn package -DskipTests
。
评论