【SpringBoot】代码混淆
2022-01-22 本文已影响0人
如雨随行2020
混淆
https://gitee.com/minhengqiang/proguard-spring-boot-example/blob/master/pom.xml
链接项目pom.xml有proguard混淆的基本配置,其中混淆程度需要根据项目具体摸索
自动化
将混淆后的代码打包
1、只保留混淆的代码
需要注意几点,injar标签中使用classes(因为最终repackge是替换jar包中的classes)outjar标签要和最终jar相同名称。不要用inFilter标签过滤,过滤了什么,jar包就少了什么。
2、保留混淆和非混淆的
之前
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<configuration>
<argLine>-javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
<agent>${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar</agent>
</configuration>
</plugin>
之后
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>repackage</id>
<phase>package</phase>
<configuration>
<target>
<ant antfile="${basedir}/build.xml">
<target name = "repackage" />
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
build.xml
<?xml version="1.0"?>
<project name="test6">
<property name="buildDir" location="${basedir}/target" />
<property name="binDir" location="${buildDir}/bin" />
<property name="guardJar" value="dems-0.0.1-SNAPSHOT-pg.jar" />
<property name="demsJar" value="dems-0.0.1-SNAPSHOT.jar" />
<property name="comDir" value="${binDir}/BOOT-INF/classes" />
<property name="guardClasses" value="classes-pg/com" />
<target name="init">
<delete dir="${binDir}"/>
<mkdir dir="${binDir}"/>
</target>
<target name="unzip" depends="init">
<unzip dest="${binDir}">
<fileset dir="${buildDir}">
<include name="${demsJar}" />
</fileset>
</unzip>
</target>
<target name="replace" depends="unzip">
<delete dir="${comDir}/com" />
<copy toDir="${comDir}/com">
<fileset dir="${buildDir}/${guardClasses}"/>
</copy>
</target>
<target name="mkjar" depends="replace">
<jar jarfile="${buildDir}/${guardJar}" manifest="${binDir}/META-INF/MANIFEST.MF" compress="false">
<fileset dir="${binDir}"/>
</jar>
</target>
<target name="repackage" depends="init, unzip, replace, mkjar">
<echo message="guard version repackaged!!!"/>
</target>
</project>
技巧
https://blog.csdn.net/jacke121/article/details/73756949
换句话说,请确保您的选项中没有以下内容
-keepattributes LocalVariableTable,LocalVariableTypeTable