SpingBoot2.0以上利用allatori对class混淆输出jar防止反编译

在很多企业中,代码管理是非常重要的,每个企业都有自己的私有机制,生产出一好的产品,又不想让别人知道自己的技术是如何实现的(作者在这里吐槽:好东西还是需要分享的),就会让搞编程的人,或者是安全师对代码进行保护,这里就是运用Allatori技术对class文件中的代码进行混淆,继而使得其他人即便获取到程序,反编译程序也是徒劳无功、无功而返,这就保证了自己代码的专利性。在编程界有许多开源的防反编译工具,例如 ProGuard在这里介绍利用Allatori混淆步骤。

  1.  下载 allatori.jar 和 allatori-annotations.jar 
     下载地址:http://www.allatori.com/ 点击右侧 demo dowload 即可,
  2. 将下载好的压缩包解压,将lib文件夹(文件夹内包含上面步骤的两个jar包)放入项目路径中,在这里我将lib文件夹放入resources文件夹下:
                                        
  3. 创建 allatori.xml 文件,文件中写入
    <config>
        <input>
            <jar in="jxkh_NeiMengGu-1.0-SNAPSHOT.jar" out="jxkh_NeiMengGu_allatori.jar"/>
        </input>
        <ignore-classes>
            <class template="class *springframework*" />
            <class template="class *shardingjdbc*" />
            <class template="class *jni*" />
            <class template="class *alibaba*"/>
            <class template="class *persistence*"/>
            <!-- 排除如下两个包下的类-->
            <class template="class com.forezp.ApplicationStart" />
            <class template="class com.forezp.service*" />
            <class template="class com.forezp.entity*" />
            <class template="class com.forezp.util*" />
         </ignore-classes>
         <keep-names>
             <class access="protected+">
                 <field access="protected+"/>
                 <method access="protected+"/>
             </class>
         </keep-names>
    
         <property name="log-file" value="log.xml"/>
     </config>
    

    相关具体配置 查询 资料 ,不排除数据service层和实体entity和主方法applocationStart会在启动jar时报错!!!

  4. 在pom.xml中加入此插件信息
     

    <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.6.0</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}/src/main/resources/lib/allatori.jar</argument>
    						<argument>${basedir}/target/allatori.xml</argument>
    					</arguments>
    				</configuration>
    			</plugin>

     

  5. 将第3步骤创建写好的allatori.xml 文件复制方式编译后的target根路径下,这样就完成了我们混淆的所有操作步骤。

  6. 直接maven - package 打jar包,测试test,出现类似以下爱的输出信息,恭喜你证明混淆成功了。可以下载反编译工具 jd-gui-1.4.0.jar 进行反编译查看做对比。
    é«æ使ç¨Javaæ··æ·å¨Allatoriï¼å¬å¸æ°ç­ç¾åº¦é½æä¸å°è®©æç»æäºå¥½å å¤©

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章