How Spring Boot uses Allatori to obfuscate code
This time I will show you how Spring Boot uses Allatori to obfuscate the code. What are the precautions for Spring Boot to use Allatori to obfuscate the code. The following is a practical case, let's take a look.
Introduction to Allatori obfuscation technology
Allatori is a Java obfuscator. It is a second-generation obfuscator, so it can fully protect your intellectual property. Allatori has the following protection methods: name obfuscation, stream obfuscation, debugginginformation obfuscation, string obfuscation, and watermark technology. This obfuscator is free for educational and non-commercial projects. Supports war and jar file formats, and allows adding valid dates for applications that require obfuscated code. There are projects that need to protect the code. A relatively basic solution is to obfuscate the code. After decompiling the packaged files, you can see the effect. In addition, the size of bags made with Allatori will be smaller.
A very ordinary maven project, the difference is that Allatori's jar package is added to the root directory.
Let’s take a look at the pom.xml file:
<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>
For projects built using maven packaging plug-ins and Spring Boot, the Allatori configuration is also explained above. The more important ones in the Allatori configuration are:
<argument>${basedir}/lib/allatori.jar</argument> <argument>${basedir}/target/allatori.xml</argument>
Specify the path of Allatori's allatori.jar file. If your project is a pom project, you can put the lib directory in the parent project, and then the sub-project only needs:
<argument>../lib/allatori.jar</argument>
That’s it.
allatori.xml This file is also very important, take a look at its contents:
<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>
It is the specific configuration of the Allatori obfuscator. Here you can configure a lot of information, many strategies, and you can also specify which classes are not to be obfuscated. The specific methods can be found in the document attached at the end of the article.
What needs to be explained here is:
<input> <jar in="confusion-0.0.1-SNAPSHOT.jar" out="confusion-0.0.1-SNAPSHOT-obfuscated.jar"/> </input>
confusion-0.0.1-SNAPSHOT.jar is the unobfuscated package after packaging, and confusion-0.0.1-SNAPSHOT-obfuscated.jar is the obfuscated package. This is what we need.
Packaging steps
1. Clean maven project.
2. Copy the allatori.xml file under resources to the target directory.
3. Install the maven project. It means success after seeing the following information:
################################################ # # # ## # # ## ### ### ## ### # # # # # # # # # # # # # # # # ### # # ### # # # ## # # # # # ### ### # # # ### # # ### # # # # 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. Project after success:
The arrow points to the package we need, and the code of this package has been obfuscated.
Effect View
Here, a decompilation tool is used to view the obfuscated package. I use the jd-gui software, which is small and practical.
TestApplication.java before obfuscation:
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); } }
After TestApplication.java is obfuscated:
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 before obfuscation:
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"; } }
After TestController.java is confused:
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(?); } }
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
JS summary of binary data operation methods
The above is the detailed content of How Spring Boot uses Allatori to obfuscate code. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics


![Windows ISO file too large BootCamp error [Fixed]](https://img.php.cn/upload/article/000/887/227/170831702395455.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
If you get the error message "The Windows ISO file is too large" when using BootCampAssistant on a Mac computer, this may be because the ISO file size exceeds the limit supported by BootCampAssistant. The solution to this problem is to use other tools to compress the ISO file size to ensure that it can be processed in BootCamp Assistant. BootCampAssistant is a convenient tool provided by Apple for installing and running Windows operating system on Mac computers. It helps users set up a dual-boot system, allowing them to easily choose to use MacOS or Wind at startup

In 2023, AI technology has become a hot topic and has a huge impact on various industries, especially in the programming field. People are increasingly aware of the importance of AI technology, and the Spring community is no exception. With the continuous advancement of GenAI (General Artificial Intelligence) technology, it has become crucial and urgent to simplify the creation of applications with AI functions. Against this background, "SpringAI" emerged, aiming to simplify the process of developing AI functional applications, making it simple and intuitive and avoiding unnecessary complexity. Through "SpringAI", developers can more easily build applications with AI functions, making them easier to use and operate.

As an industry leader, Spring+AI provides leading solutions for various industries through its powerful, flexible API and advanced functions. In this topic, we will delve into the application examples of Spring+AI in various fields. Each case will show how Spring+AI meets specific needs, achieves goals, and extends these LESSONSLEARNED to a wider range of applications. I hope this topic can inspire you to understand and utilize the infinite possibilities of Spring+AI more deeply. The Spring framework has a history of more than 20 years in the field of software development, and it has been 10 years since the Spring Boot 1.0 version was released. Now, no one can dispute that Spring

How to implement spring programmatic transactions: 1. Use TransactionTemplate; 2. Use TransactionCallback and TransactionCallbackWithoutResult; 3. Use Transactional annotations; 4. Use TransactionTemplate in combination with @Transactional; 5. Customize the transaction manager.

Java implements scheduled tasks In the library that comes with Jdk, there are two ways to implement scheduled tasks, one is Timer, and the other is ScheduledThreadPoolExecutor. When Timer+TimerTask creates a Timer, it creates a thread, which can be used to schedule TimerTask tasks. Timer has four construction methods, and you can specify the name of the Timer thread and whether to set it as a daemon thread. The default name is Timer-number, and the default is not a daemon thread. There are three main methods: cancel(): terminate task scheduling, cancel all currently scheduled tasks, running tasks will not be affected purge(): remove tasks from the task queue

SpringBoot and SpringCloud are both extensions of Spring Framework that help developers build and deploy microservice applications faster, but they each have different purposes and functions. SpringBoot is a framework for quickly building Java applications, allowing developers to create and deploy Spring-based applications faster. It provides a simple, easy-to-understand way to build stand-alone, executable Spring applications

How to set the transaction isolation level in Spring: 1. Use the @Transactional annotation; 2. Set it in the Spring configuration file; 3. Use PlatformTransactionManager; 4. Set it in the Java configuration class. Detailed introduction: 1. Use the @Transactional annotation, add the @Transactional annotation to the class or method that requires transaction management, and set the isolation level in the attribute; 2. In the Spring configuration file, etc.

With the update and iteration of technology, Java5.0 began to support annotations. As the leading framework in Java, spring has slowly begun to abandon xml configuration since it was updated to version 2.5, and more annotations are used to control the spring framework.
