在很多企業中,代碼管理是非常重要的,每個企業都有自己的私有機制,生產出一好的產品,又不想讓別人知道自己的技術是如何實現的(作者在這裏吐槽:好東西還是需要分享的),就會讓搞編程的人,或者是安全師對代碼進行保護,這裏就是運用Allatori技術對class文件中的代碼進行混淆,繼而使得其他人即便獲取到程序,反編譯程序也是徒勞無功、無功而返,這就保證了自己代碼的專利性。在編程界有許多開源的防反編譯工具,例如 ProGuard在這裏介紹利用Allatori混淆步驟。
- 下載 allatori.jar 和 allatori-annotations.jar
下載地址:http://www.allatori.com/ 點擊右側 demo dowload 即可, - 將下載好的壓縮包解壓,將lib文件夾(文件夾內包含上面步驟的兩個jar包)放入項目路徑中,在這裏我將lib文件夾放入resources文件夾下:
- 創建 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時報錯!!!
-
在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>
-
將第3步驟創建寫好的allatori.xml 文件複製方式編譯後的target根路徑下,這樣就完成了我們混淆的所有操作步驟。
-
直接maven - package 打jar包,測試test,出現類似以下愛的輸出信息,恭喜你證明混淆成功了。可以下載反編譯工具 jd-gui-1.4.0.jar 進行反編譯查看做對比。