代码混淆 -- SpringBoot集成Allatori对源代码混淆,防反编译获取源码

Allatori介绍

Allatori是第二代Java混淆器,可为您的知识产权提供全方位的保护。

尽管大多数第二代混淆器都提供了值得保护的级别,但我们已经在Allatori中开发了许多附加功能,
以使对代码进行逆向工程几乎不可能。

Allatori不仅会混淆,还会最大程度地减少应用程序的大小并提高速度,同时您和您的团队以外的任何人
都无法读取您的代码。作为每个现代Java混淆器,Allatori具有完整的水印功能,从而有可能为您的软件
提供适当的许可!

如果有必要保护您的软件,并且要减少软件的大小和缩短处理时间,则可以使用Allatori混淆器。

- - -  摘自官网

官网首页:http://www.allatori.com/
官网文档:http://www.allatori.com/doc.html/

使用

  1. 官网下载jar包,将jar包放入项目中
    在这里插入图片描述
  2. 配置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 -->
  1. 配置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>

  1. 使用maven正常打包即可,在target下会生成你配置的out的jar文件
    在这里插入图片描述

结果

在这里插入图片描述

注意的点

  1. 不混淆框架内的东西,最好只混淆自己的核心逻辑,所以在上面配置了ignore,否则可能jar包都运行不了。
  2. 不混淆Redis、Jbdc等相关连接信息类
  3. 不混淆DAO层和Entity层,因为混淆会把形参名字改掉,导致映射有问题
  4. 混淆Controller层时,可以配置:local-variables-naming=keep-parameters,保证形参名称不变,因为web层,spring要映射mapping和形参的,其实和上面是一样的道理
    在这里插入图片描述
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值