Spring Boot使用Allatori代码混淆的方法
作者:Lovnx 发布时间:2023-11-24 16:34:55
Allatori混淆技术介绍
Allatori是一个Java 混淆器,它属于第二代混淆器,因此它能够全方位地保护你的知识产权。 Allatori具有以下几种保护方式:命名混淆,流混淆,调试信息混淆,字符串混淆,以及水印技术。对于教育和非商业项目来说这个混淆器是免费的。支持war和jar文件格式,并且允许对需要混淆代码的应用程序添加有效日期。 有项目需要对代码进行保护,比较初级的方案就是对代码进行混淆,打包之后的文件进行反编译后,就可以看到效果。此外,使用Allatori打的包体积也会小一点。
工程介绍
一个很普通的maven工程,不同的是在根目录下加入Allatori的jar包。
下面我们来看看pom.xml文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lovnx</groupId>
<artifactId>confusion</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- Allatori plugin start -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-and-filter-allatori-config</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${basedir}/allatori</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>
<argument>${basedir}/lib/allatori.jar</argument>
<argument>${basedir}/target/allatori.xml</argument>
</arguments>
</configuration>
</plugin>
<!-- Allatori plugin end -->
</plugins>
</build>
<dependencies>
<!-- Test Begin -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Test End -->
<!-- springboot启动 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
</project>
使用maven打包插件,Spring Boot构建的工程,Allatori的配置在上面也有说明,Allatori配置里面比较重要的是:
<argument>${basedir}/lib/allatori.jar</argument>
<argument>${basedir}/target/allatori.xml</argument>
指定Allatori的allatori.jar文件路径,如果你的工程是一个pom工程,可以在父工程中放lib目录,然后子工程只需要:
<argument>../lib/allatori.jar</argument>
即可。
allatori.xml这个文件也很重要,看看其中的内容:
<config>
<input>
<jar in="confusion-0.0.1-SNAPSHOT.jar" out="confusion-0.0.1-SNAPSHOT-obfuscated.jar"/>
</input>
<keep-names>
<class access="protected+">
<field access="protected+"/>
<method access="protected+"/>
</class>
</keep-names>
<property name="log-file" value="log.xml"/>
</config>
即是对Allatori混淆器的具体配置,这里可以配置很多信息,很多种策略,也可以指定哪些类不被混淆,具体的各种方式可以在在文末附件里面的文档得到。
这里需要说明的是:
<input>
<jar in="confusion-0.0.1-SNAPSHOT.jar" out="confusion-0.0.1-SNAPSHOT-obfuscated.jar"/>
</input>
confusion-0.0.1-SNAPSHOT.jar这个是打包后的未被混淆的包,而confusion-0.0.1-SNAPSHOT-obfuscated.jar是混淆后的包,这个是我们需要的。
打包步骤
1、clean maven工程。
2、将resources下面的allatori.xml文件复制到target目录下面。
3、install maven工程,看到如下信息后表示成功:
################################################
# #
# ## # # ## ### ### ## ### #
# # # # # # # # # # # # # #
# ### # # ### # # # ## # #
# # # ### ### # # # ### # # ### #
# #
# DEMO VERSION! #
# NOT FOR COMMERCIAL USE! #
# #
# Demo version adds System.out's #
# and gives 'ALLATORI_DEMO' name #
# to some fields and methods. #
# #
# #
# Obfuscation by Allatori Obfuscator v6.4 DEMO #
# #
# http://www.allatori.com #
# #
################################################
4、成功后的工程:
箭头所指处即是我们需要的包,此包代码已被混淆。
效果查看
这里使用反编译工具对混淆后的包进行查看,我用的是jd-gui这个软件,小巧实用。
TestApplication.java混淆前:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
TestApplication.java混淆后:
import java.io.PrintStream;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestApplication
{
public static String ALLATORIxDEMO(String a)
{
int tmp4_3 = 4;
int tmp7_6 = 1;
int tmp21_18 = a.length();
int tmp25_24 = 1;
tmp25_24;
int j;
int ? = tmp25_24;
int k = tmp21_18;
int tmp35_31 = (j = new char[tmp21_18] - 1);
tmp35_31;
int i = 5 << 4 ^ (0x2 ^ 0x5);
(tmp4_3 << tmp4_3 ^ tmp7_6 << tmp7_6);
if (tmp35_31 >= 0)
{
int tmp45_44 = j;
j--;
?[tmp45_44] = ((char)(a.charAt(tmp45_44) ^ i));
int tmp66_63 = (j--);
?[tmp66_63] = ((char)(a.charAt(tmp66_63) ^ k));
}
return new String(?);
}
public static void main(String[] a)
{
System.out.println("\n################################################\n# #\n# ## # # ## ### ### ## ### #\n# # # # # # # # # # # # # #\n# ### # # ### # # # ## # #\n# # # ### ### # # # ### # # ### #\n# #\n# Obfuscation by Allatori Obfuscator v6.4 DEMO #\n# #\n# http://www.allatori.com #\n# #\n################################################\n"); SpringApplication.run(TestApplication.class, a);
}
}
TestController.java混淆前:
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@GetMapping("/test")
public String test(){
return "88888888888888888";
}
}
TestController.java混淆后:
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController
{
@GetMapping({"/test"})
public String test()
{
return ALLATORIxDEMO("*]*]*]*]*]*]*]*]*");
}
public static String ALLATORIxDEMO(String a)
{
int tmp27_24 = a.length();
int tmp31_30 = 1;
tmp31_30;
int j;
int ? = tmp31_30;
int k = tmp27_24;
int tmp41_37 = (j = new char[tmp27_24] - 1);
tmp41_37;
int i = (0x3 ^ 0x5) << 4 ^ 0x5;
(2 << 3 ^ 0x2);
if (tmp41_37 >= 0)
{
int tmp51_50 = j;
j--;
?[tmp51_50] = ((char)(a.charAt(tmp51_50) ^ i));
int tmp72_69 = (j--);
?[tmp72_69] = ((char)(a.charAt(tmp72_69) ^ k));
}
return new String(?);
}
}
哈哈哈,怎么样,是不是看不懂?并且混淆包照常运行,没有任何问题。
-------》github 源码与文档地址《-------
来源:https://juejin.im/post/5a97b50a518825558358a024


猜你喜欢
- https://www.jb51.net/article/114838.htm这篇文章很详细的介绍了JS的跨域,给出的解决方案是spring
- -vmargs -Xms128M -Xmx512M -XX:PermSize=64M -XX:MaxPermSize=128M 这里有几个问
- 本文介绍了Android ListView 实现上拉加载的示例代码,分享给大家,具体如下:我们先分析一下如何实现 ListView 上拉加载
- 项目中经常会用到分享的功能,有分享链接也有分享图片,其中分享图片有的需要移动端对屏幕内容进行截取分享,说白了就是将view 转成bitmap
- using System;using System.Collections.Generic;using System.ComponentMo
- 本文为大家分享了Android中Drawable方法的详细使用方法,供大家参考,具体内容如下1. BitmapDrawable相关方法:新建
- Java SSM框架即指Spring+SpringMVC+MyBatis的简称,框架集由Spring、MyBatis两个开源框架整合而成(S
- TypeScript简介:TypeScript是一种由微软开发的自由和开源的编程语言。它是JavaScript的一个超集,而且本质上向这个语
- ActiveMQ是Apache的一个开源项目,它是一个功能强劲的开源消息总线,也是一个中间件产品,它是JMS的一个实现。在介绍ActiveM
- 本文实例讲述了C#遍历子目录的方法。分享给大家供大家参考。具体实现方法如下:DirectoryInfo directoryInfo = ne
- Java 散列存储Java中散列存储的数据结构主要是指HashSet、HashMap、LinkedHashSet、LinkedHashMap
- 前言在第一篇文字中,我们完全人工方式,一个命令一个命令输入,实现一个java tomcat运行环境,虽然也初见成效,但很累人。如果依靠依靠脚
- bean 的生命周期对象创建实例化Bean对象,默认选择无参构造方法,如果只有一个有参构造那么调用有参构造,如果只有多个有参构造那么报错,除
- SelectMany操作符提供了将多个from子句组合起来的功能,相当于数据库中的多表连接查询,它将每个对象的结果合并成单个序列。示例:st
- 定义享元模式(FlyWeight Pattern),也叫蝇量模式,运用共享技术,有效的支持大量细粒度的对象,享元模式就是池技术的重要实现方式
- 本文实例讲述了Android实现仿通讯录侧边栏滑动SiderBar效果代码。分享给大家供大家参考,具体如下:之前看到某些应用的侧边栏做得不错
- 概述在JDK 1.8里,可以使用如下代码获取List元素对象中某个属性的列表。package test;import java.util.A
- 使用的场景常常遇到一些项目中多环境切换的问题。比如在开发过程中用到开发环境,在测试中使用测试环境,在生产中用生产环境的情况。springbo
- 本文为大家分享了java实现学生选课系统的具体代码,供大家参考,具体内容如下案例要求:学生(学号,姓名,专业,所选课程{<3}) 老师
- 问题使用前后端分离模式开发项目时,往往会遇到这样一个问题 -- 无法跨域获取服务端数据这是由于浏览器的同源策略导致的,目的是为了安全。在前后