赞
踩
著名的反编译软件 JD-GUI :下载地址
Java虚拟机工具接口(JVMTI)提供了一个编程接口,允许您(软件开发人员)创建可以监视和控制Java编程语言应用程序的软件代理。关于JVMTI的官方说明
通俗的说,就是用C++生成动态链接库(DLL),给你指定的二进制的class文件中插入一段数字,进行篡改,使其无法被JD-GUI用简单的AST抽象语法树进行反编译,在运行 jar 包时,再通过DLL文件,消除那段数字,从而实现解密。
这个博客内有github源码,以及c++的具体讲解,和普通java项目的加解密的实现。
参考博客:https://blog.csdn.net/wangyangzhizhou/article/details/75316826
本文从java的角度,主要讲springboot项目的加解密。
1.2 VS2010 新建DLL项目?
1.4 github下载源码,创建DLL项目,将c++ 的 源代码(.cpp)和头文件(.h)复制粘贴进去。

1.5 关于头文件 jni.h,jvmti.h,jni_md.h 都在JDK的安装目录。
jni.h 、jvmti.h 在 jdk/include 目录下
jni_md.h 在 jdk/include/linux 目录下
关于头文件的添加。
1.6 修改 c++ com_seaboat_bytecode_ByteCodeEncryptor.cpp 文件第60行,修改if条件,改成自己解密的包路径。

1.7生成DLL文件。

2.1 修改 ByteCodeEncryptor.java,加载DLL文件。

2.2 修改 JarEncryptor.java,修改成自己的包路径名。

2.3 修改成需要加密的 jar 绝对路径。执行main方法。同路径生成 demo2-0.0.1_encrypted.jar(加密后)

2.4 使用 jd-gui-1.4.1.jar 验证是否加密。

2.5 发布 jar


正确的去启动命令:需要加载DLL文件,并且指向启动类。
java -agentpath:C:\Users\lenovo\Desktop\FeByteCodeEncryptor.dll -cp demo2-0.0.1_encrypted.jar com.wyd.demo2.Demo2Application
浏览器访问接口:

常规java项目的jar包

springboot项目的jar包

如果要加密springboot项目,那是不是将加密路径和解密的路径修改成BOOT-INF/classes,是否也就可以呢。
本人测试了一下,加密是可以的,解密不可以(读不到路径)。



思路是:打包时,将依赖包和配置文件分离
修改pom.xml文件
<?xml version="1.0" encoding="UTF-8"?> <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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.wyd</groupId> <artifactId>demo2</artifactId> <version>0.0.1</version> <name>demo2</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <spring-boot.version>2.1.4.RELEASE</spring-boot.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <!-- springboot自带的打包插件 <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> </plugins> </build>--> <build> <resources> <resource> <!--指定mapping下的所有xml文件打包在jar中--> <targetPath>${project.build.directory}/classes</targetPath> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>mapping/*.xml</include> </includes> </resource> <resource> <!--resources下一级的所有.xml .properties文件复制到config目录下--> <targetPath>${project.build.directory}/config</targetPath> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**.xml</include> <include>**.yml</include> </includes> </resource> </resources> <plugins> <!--maven-dependency插件,将项目所有依赖包放到lib目录下--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <type>jar</type> <includeTypes>jar</includeTypes> <outputDirectory> ${project.build.directory}/lib </outputDirectory> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <classesDirectory>target/classes/</classesDirectory> <archive> <!--生成的jar中,不要包含pom.xml和pom.properties这两个文件--> <addMavenDescriptor>false</addMavenDescriptor> <manifest> <mainClass>com.wyd.demo2.Demo2Application</mainClass> <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 --> <useUniqueVersions>false</useUniqueVersions> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> <manifestEntries> <!--jar中的MANIFEST.MF文件ClassPath需要添加config目录才能读取到配置文件--> <Class-Path>config/</Class-Path> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build> </project>


这样springboot项目就成功的将依赖包(lib)和配置文件(cinfig)分离开,变成普通的java项目结构。JVMTI自然可以读取到,并进行加解密。


Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。