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
猜你喜欢
- 题目描述Java创建线程的几种方式Java使用Thread类代表线程,所有线程对象都必须是Thread类或者其子类的实例。Java可以用以下
- URL(Uniform Resource Locator)是统一资源 * ,它是对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,
- 我们平时使用的一些常见队列都是非阻塞队列,比如PriorityQueue、LinkedList(LinkedList是双向链表,它实现了De
- 在使用Gateway 调用一个文件上传服务时 前端传来的File的base64字符串怎么都接受不到 但是用Body方式请求就能接收到后来经过
- 效果:原图加水印后的图片废话不多说,直接上代码代码:package com.example.demo;import java.awt.Alp
- 把spring-boot项目按照平常的web项目一样发布到tomcat容器下一、修改打包形式在pom.xml里设置 <packagin
- 1、什么是 ThreadLocal:ThreadLocal,即线程本地变量,如果你创建了一个变量,那么访问这个变量的每个线程都会有这个变量的
- File 类:文件和目录路径名的抽象表示。注意:File 类只能操作文件的属性,文件的内容是不能操作的。1、File 类的字段我们知道,各个
- Spring Boot 2.7.6整合redis与低版本的区别最近在写程序的时候参考了之前写过的一篇文章spring boot整合redis
- 相信不少喜欢开发的朋友都已经知道微信小程序是个什么物种了,楼主也是从小程序内测期间就开始关注,并且也写过几个已经上线的微信小程序。但是基本上
- Lambda 表达式Lambda 表达式是现代 C++ 中最重要的特性之一,而 Lambda 表达式,实际上就是提供了一个类似匿名函数的特性
- 引言:关于java IO流的操作是非常常见的,基本上每个项目都会用到,每次遇到都是去网上找一找就行了,屡试不爽。上次突然一个同事问了我jav
- 在实施接口中,我们利用interface语法,将interface从类定义中独立出来,构成一个主体。interface为类提供了接口规范。在
- @ApiImplicitParam作用在方法上,表示单独的请求参数参数name:参数名。value:参数的具体意义,作用。required:
- 本文实例讲述了Java截取字符串的方法。分享给大家供大家参考。具体实现方法如下:public static void main(String
- 本文实例为大家分享了java文件上传下载的具体代码,供大家参考,具体内容如下文件上传@RequestMapping(value="
- 从功能上说,可以分为两部分,分布式功能和数据功能。分布式功能主要是节点集群及集群附属功能如restful借口、集群性能检测功能等,数据功能主
- 在基于Mybatis-plus实现多租户架构中,介绍了在多租户项目中如果要开启一个子线程,那么需要手动进行RequestAttributes
- 1.需求背景需要实现一个动态加载但不显示出来的视图,且该视图上有个动态生成的二维码,最后用其去生成一张快照(也就是图片)。(常见这种情况是来
- 一、Kotlin 调用 Java1. kotlin 关键字转义java 中的方法或变量 是 kotlin 的关键字时,使用反引号 `` 对关