基于Allatori7.6的Java代码混淆

基于Allatori7.6对Java代码实现代码混淆

第一步:下载Allatori7.6

http://www.allatori.com/

第二步:解压Allatori-7.6-Demo.zip

在这里插入图片描述

解压下来就是这个样子,然后你可以用两种方式实现代码混淆

方式一:就是在你项目中打包的时候进行混洗代码
第一步:Allatori-7.6-Demo下的lib下面的jar包复制到你要打包的项目中去

在这里插入图片描述

第二步:配置在你项目下src/main/resources新建一个allatori.xml这个文件
<config>
    <!--原编译的jar文件,混淆后输出的jar文件-->
    <input>
        <jar in="test-boot-module-system-1.0.0.jar" out="test-boot-module-system-1.0.0-obfuscated.jar"/>
    </input>
    <!-- 不替换类名、方法名、属性名 -->
    <keep-names>
        <class access="protected+">
            <field access="private+"/>
            <method access="protected+"/>
        </class>
    </keep-names>
    <property name="local-variables-naming" value="keep-parameters"/>
    <!-- 排除(不做代码混淆)-->
    <ignore-classes>
        <!-- 排除springboot依赖文件(springboot构建的项目需要排除,否则业务程序会报错) -->
        <class template="class  *springframework*"/>
        <class template="class *apache*"/>
        <class template="class *yaml*"/>
        <class template="class *baomidou*"/>
        <class template="class *alibaba*"/>
        <class template="class *jeecg*"/>
        <class template="class *codehaus*"/>
        <class template="class *servlet*"/>
        <class template="class *mail*"/>
        <class template="class *tio*"/>
        <class template="class *quartz*"/>
        <class template="class *misc*"/>
       <!-- <class template="class **"/> -->
       <!-- 排除如下两个包下的类 -->
        <class template="class com.csp.*.entity.*"/>
        <class template="class com.csp.*.mapper.xml.*"/>
        <class template="class org.jeecg.JeecgApplication.*"/>
        <class template="class org.jeecg.modules.*"/>
        <class template="class org.jeecg.config.*"/>
        <class template="class cn.im.vim.*"/>
    </ignore-classes>
<!--    <keep-names>-->
        <!-- 防止部分类、方法、变量找不到名称而报错 -->
        <!-- 所有方法名称不变,parameters="keep"表示方法参数名也不变 -->
<!--        <method template="*(**)" parameters="keep"/>-->
<!--    </keep-names>-->
    <!-- 随机命名混淆字符-->
<!--    <property name="random-seed" value="abcdef ghnljk svi"/>-->
    <property name="log-file" value="log.xml"/>
</config>
第三步:在你的项目中的pom.xml里面进行插件配置
<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<!-- resouces拷贝文件插件 -->
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.6</version>
				<executions>
					<!-- 执行这个插件的时候执行申明的所有phase -->
					<execution>
						<id>copy-and-filter-allatori-config</id>
						<phase>package</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<!-- 这个地方需要注意拷贝的文件位置需要是target目录,target目录是最终打jar包存放的位置 -->
							<outputDirectory>${basedir}/target</outputDirectory>
							<resources>
								<resource>
<!-- 这个地方的文件目录需要注意,网上很多目录都是${basedir}/allatori这个,所以才会需要手动拷贝allatori.xml文件到target目录下,有了这个mvn会自动帮我们拷贝了 -->
									<directory>src/main/resources</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>
						<!-- 指定引用的allatori的jar包位置,这里把jar包放在了根目录下的lib目录里 -->
						<argument>${basedir}/lib/allatori.jar</argument>
					<!-- 指定代码混淆时的配置文件,因为是混淆指定的是jar包,jar包位置在target下,所以我们的allatori.xml也需要拷贝到该目录下 -->
						<argument>${basedir}/target/allatori.xml</argument>
					</arguments>
				</configuration>
			</plugin>
		</plugins>
	</build>
第四步:就是使用maven插件进行打包,我这边使用第一种方式没有成功。

这里可以使用插件打包:->clean->install就可以打包成功,我看了很多博客上有些是这样打包

还有些是这样的在根目录下执行命令:mvn package -DskipTests

反正我是使用第一种方式打包的时候混淆代码没有成功。

第五步:如果出现这个样子基本上是成功了

在这里插入图片描述

第六步:如果你出现了这种情况那可能没有混淆成功

在这里插入图片描述

还报警告Some classes weren’t found. It may result in weaker obfuscation. Add needed jars to the ‘classpath’ element of the configuration file.

说明可能没有成功我这边推荐你使用第二种方式

方式二:就是在你打包好的jar包在进行混淆
第一步:就是在解压下的Allatori-7.6-Demo双击进入到

在这里插入图片描述

第二步:进入到这个路劲下

在这里插入图片描述

第三步:将你打包好的文件复制到Allatori-7.6-Demo\tutorial\step01\files

在这里插入图片描述

第四步:就是更改这个config.xml
<config>
    <!--原编译的jar文件,混淆后输出的jar文件-->
    <input>
        <jar in="csp-boot-module-system-1.0.0.jar" out="csp-boot-module-system-1.0.0-obfuscated.jar"/>
    </input>
    <!-- 不替换类名、方法名、属性名 -->
    <keep-names>
        <class access="protected+">
            <field access="private+"/>
            <method access="protected+"/>
        </class>
    </keep-names>
<!--    <classpath basedir="library-jars">-->
<!--        &lt;!&ndash; Adding library.jar to the classpath &ndash;&gt;-->
<!--        <jar name="library.jar"/>-->
<!--        &lt;!&ndash; Adding all jars in the lib directory to the classpath &ndash;&gt;-->
<!--        <jar name="lib/*.jar"/>-->
<!--        &lt;!&ndash; Adding all jars in the lib2 directory and its subdirectories to the classpath &ndash;&gt;-->
<!--        <jar name="lib2/**/*.jar"/>-->
<!--    </classpath>-->
    <!-- 接口形参名保持不变 -->
    <property name="local-variables-naming" value="keep-parameters"/>
    <!-- 排除(不做代码混淆)-->
    <ignore-classes>
        <!-- 排除springboot依赖文件(springboot构建的项目需要排除,否则业务程序会报错) -->
        <class template="class  *springframework*"/>
        <class template="class *apache*"/>
        <class template="class *yaml*"/>
        <class template="class *baomidou*"/>
        <class template="class *alibaba*"/>
        <class template="class *jeecg*"/>
        <class template="class *codehaus*"/>
        <class template="class *servlet*"/>
        <class template="class *mail*"/>
        <class template="class *tio*"/>
        <class template="class *quartz*"/>
        <class template="class *misc*"/>
       <!-- <class template="class **"/> -->
       <!-- 排除如下两个包下的类 -->
        <class template="class com.csp.*.entity.*"/>
        <class template="class com.csp.*.mapper.xml.*"/>
        <class template="class org.jeecg.JeecgApplication.*"/>
        <class template="class org.jeecg.modules.*"/>
        <class template="class org.jeecg.config.*"/>
        <class template="class cn.im.vim.*"/>
<!--        <class template="class com.baomidou.mybatisplus.extension.service.impl.IService.*"/>-->
<!--        <class template="class com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.*"/>-->
<!--        <class template="class com.baomidou.mybatisplus.core.mapper.BaseMapper.*"/>-->
<!--        <class template="class org.jeecg.common.system.base.controller.JeecgController.*"/>-->
<!--        <class template="class org.springframework.beans.factory.DisposableBean.*"/>-->
<!--        <class template="class org.springframework.context.ApplicationContextAware.*"/>-->
<!--        <class template="class javax.mail.Authenticator.*"/>-->
<!--        <class template="class org.jeecg.common.handler.IFillRuleHandler.*"/>-->
<!--        <class template="class org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter.*"/>-->
<!--        <class template="class org.springframework.web.servlet.HandlerInterceptor.*"/>-->
<!--        <class template="class org.jeecg.common.system.base.entity.JeecgEntity.*"/>-->
<!--        <class template="class org.jeecgframework.poi.excel.imports.base.ImportFileServiceI.*"/>-->
<!--        <class template="class org.jeecg.common.system.base.service.JeecgService.*"/>-->
<!--        <class template="class org.jeecgframework.dict.service.AutoPoiDictServiceI.*"/>-->
<!--        <class template="class org.springframework.boot.CommandLineRunner.*"/>-->
<!--        <class template="class org.tio.websocket.server.WsServerAioListener.*"/>-->
<!--        <class template="class org.quartz.Job.*"/>-->
<!--        <class template="class org.springframework.boot.actuate.health.HealthIndicator.*"/>-->
<!--        <class template="class org.jeecg.common.system.base.service.impl.JeecgServiceImpl.*"/>-->
<!--        <class template="class org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.*"/>-->
<!--        <class template="class org.apache.shiro.realm.AuthorizingRealm.*"/>-->
<!--        <class template="class org.apache.mina.core.service.IoHandlerAdapter.*"/>-->
<!--        <class template="class org.apache.shiro.authc.AuthenticationToken.*"/>-->
<!--        <class template="class org.jeecg.common.system.api.ISysBaseAPI.*"/>-->
<!--        <class template="class org.apache.shiro.web.filter.AccessControlFilter.*"/>-->
<!--        <class template="class org.springframework.web.servlet.config.annotation.WebMvcConfigurer.*"/>-->
<!--        <class template="class org.tio.websocket.server.handler.IWsMsgHandler.*"/>-->
<!--        <class template="class org.tio.core.stat.IpStatListener.*"/>-->
<!--        <class template="class org.springframework.cache.annotation.CachingConfigurerSupport.*"/>-->
<!--        <class template="class org.apache.ibatis.plugin.Interceptor.*"/>-->
    </ignore-classes>
<!--    <keep-names>-->
        <!-- 防止部分类、方法、变量找不到名称而报错 -->
        <!-- 所有方法名称不变,parameters="keep"表示方法参数名也不变 -->
<!--        <method template="*(**)" parameters="keep"/>-->
<!--    </keep-names>-->
    <!-- 随机命名混淆字符-->
<!--    <property name="random-seed" value="abcdef ghnljk svi"/>-->
    <!--这个是你项目打包好后的一个lib包你要引入进来不然会引起找不到类然后导致代码混淆较弱-->
    <classpath>
        <jar name="lib/*.jar"/>
    </classpath>
    <property name="log-file" value="log.xml"/>
</config>

第四步:配置好后,Allatori-7.6-Demo\tutorial\step02\files双击运行RunAllatori.bat文件然后他会生成一个你那边配置输出的一个obfuscated.jar文件

在这里插入图片描述

最后一步就是你把你混淆出来的jar文件解压一下然后你idea中启用了反编译插件你就可以看出来效果了,我这个图片是混淆后的效果图

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

great-sword

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值