编译
简单就是把代码跑一哈,然后我们的代码 .java文件 就被编译成了 .class 文件

基于 Spring Boot + MyBatis Plus + Vue & Element 实现的后台管理系统 + 用户小程序,支持 RBAC 动态权限、多租户、数据权限、工作流、三方登录、支付、短信、商城等功能
- 项目地址:https://github.com/YunaiV/ruoyi-vue-pro
- 视频教程:https://doc.iocoder.cn/video/
反编译
就是针对编译生成的 jar/war 包 里面的 .class 文件 逆向还原回来,可以看到你的代码写的啥。
比较常用的反编译工具 JD-GUI ,直接把编译好的jar丢进去,大部分都能反编译看到源码:

那如果不想给别人反编译看自己写的代码呢?
怎么做?
基于 Spring Cloud Alibaba + Gateway + Nacos + RocketMQ + Vue & Element 实现的后台管理系统 + 用户小程序,支持 RBAC 动态权限、多租户、数据权限、工作流、三方登录、支付、短信、商城等功能
混淆
该篇玩的代码混淆 ,是其中一种手段。
我给你看,但你反编译看到的不是真正的代码。
先看一张效果示例图 :

开搞
正文
先看一下我们混淆一个项目代码,要做啥?

一共就两步
第一步, 在项目路径下,新增一份文件 proguard.cfg :
proguard.cfg
#指定Java的版本
-target1.8
#proguard会对代码进行优化压缩,他会删除从未使用的类或者类成员变量等
-dontshrink
#是否关闭字节码级别的优化,如果不开启则设置如下配置
-dontoptimize
#混淆时不生成大小写混合的类名,默认是可以大小写混合
-dontusemixedcaseclassnames
#对于类成员的命名的混淆采取唯一策略
-useuniqueclassmembernames
#混淆时不生成大小写混合的类名,默认是可以大小写混合
-dontusemixedcaseclassnames
#混淆类名之后,对使用Class.forName('className')之类的地方进行相应替代
-adaptclassstrings
#对异常、注解信息予以保留
-keepattributesExceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
#此选项将保存接口中的所有原始名称(不混淆)-->
-keepnamesinterface**{*;}
#此选项将保存所有软件包中的所有原始接口文件(不进行混淆)
#-keepinterface*extends*{*;}
#保留参数名,因为控制器,或者Mybatis等接口的参数如果混淆会导致无法接受参数,xml文件找不到参数
-keepparameternames
#保留枚举成员及方法
-keepclassmembersenum*{*;}
#不混淆所有类,保存原始定义的注释-
-keepclassmembersclass*{
@org.springframework.context.annotation.Bean*;
@org.springframework.beans.factory.annotation.Autowired*;
@org.springframework.beans.factory.annotation.Value*;
@org.springframework.stereotype.Service*;
@org.springframework.stereotype.Component*;
}
#忽略warn消息
-ignorewarnings
#忽略note消息
-dontnote
#打印配置信息
-printconfiguration
-keeppublicclasscom.example.myproguarddemo.MyproguarddemoApplication{
publicstaticvoidmain(java.lang.String[]);
}
注意点:

其余的看注释,可以配置哪些类不参与混淆,哪些枚举保留,哪些方法名不混淆等等。
第二步,在pom文件上 加入proguard 混淆插件 :
build标签里面改动加入一下配置
<build>
<plugins>
<plugin>
<groupId>com.github.wvengengroupId>
<artifactId>proguard-maven-pluginartifactId>
<version>2.6.0version>
<executions>
<execution>
<phase>packagephase>
<goals>
<goal>proguardgoal>
goals>
execution>
executions>
<configuration>
<injar>${project.build.finalName}.jarinjar>
<outjar>${project.build.finalName}.jaroutjar>
<obfuscate>trueobfuscate>
<proguardInclude>${project.basedir}/proguard.cfgproguardInclude>
<libs>
<lib>${java.home}/lib/rt.jarlib>
<lib>${java.home}/lib/jce.jarlib>
<lib>${java.home}/lib/jsse.jarlib>
libs>
<inLibsFilter>!META-INF/**,!META-INF/versions/9/**.classinLibsFilter>
<outputDirectory>${project.basedir}/targetoutputDirectory>
<options>
options>
configuration>
plugin>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<executions>
<execution>
<goals>
<goal>repackagegoal>
goals>
<configuration>
<mainClass>com.example.myproguarddemo.MyproguarddemoApplicationmainClass>
configuration>
execution>
executions>
plugin>
plugins>
build>
注意点:


然后可以看到:

然后点击package,正常执行编译打包流程就可以 :

然后可以看到jar的生成:

看看效果:

好了,该篇就到这。
审核编辑 :李倩
-
JAVA
+关注
关注
19文章
2967浏览量
104741 -
代码
+关注
关注
30文章
4787浏览量
68589 -
spring
+关注
关注
0文章
340浏览量
14341 -
编译
+关注
关注
0文章
657浏览量
32869 -
SpringBoot
+关注
关注
0文章
173浏览量
177
原文标题:SpringBoot 玩一玩代码混淆,防止反编译代码泄露
文章出处:【微信号:芋道源码,微信公众号:芋道源码】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
相关推荐
【RA-Eco-RA0E1-32PIN-V1.0开发板试用】开箱+环境搭建 终于会用HAL框架了,环境搭建玩成了!
苹果下一代Mac mini代码泄露:五端口设计成焦点
代码整洁之道-大师眼中的整洁代码是什么样

hex文件如何查看原c语言代码
linux驱动程序的编译方法是什么
LKT(LCS)代码移植芯片优势
一招掌握C语言代码如何变成bin文件?

评论