allatori混淆技術介紹
allatori是一個java 混淆器,它屬于第二代混淆器,因此它能夠全方位地保護你的知識產權。 allatori具有以下幾種保護方式:命名混淆,流混淆,調試信息混淆,字符串混淆,以及水印技術。對于教育和非商業項目來說這個混淆器是免費的。支持war和jar文件格式,并且允許對需要混淆代碼的應用程序添加有效日期。 有項目需要對代碼進行保護,比較初級的方案就是對代碼進行混淆,打包之后的文件進行反編譯后,就可以看到效果。此外,使用allatori打的包體積也會小一點。
工程介紹
一個很普通的maven工程,不同的是在根目錄下加入allatori的jar包。
下面我們來看看pom.xml文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
<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> <groupid>com.lovnx</groupid> <artifactid>confusion</artifactid> <version> 0.0 . 1 -snapshot</version> <packaging>jar</packaging> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> <!-- allatori plugin start --> <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.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> <argument>${basedir}/lib/allatori.jar</argument> <argument>${basedir}/target/allatori.xml</argument> </arguments> </configuration> </plugin> <!-- allatori plugin end --> </plugins> </build> <dependencies> <!-- test begin --> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <scope>test</scope> </dependency> <!-- test end --> <!-- springboot啟動 --> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> </dependencies> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version> 1.5 . 8 .release</version> </parent> </project> |
使用maven打包插件,spring boot構建的工程,allatori的配置在上面也有說明,allatori配置里面比較重要的是:
1
2
|
<argument>${basedir}/lib/allatori.jar</argument> <argument>${basedir}/target/allatori.xml</argument> |
指定allatori的allatori.jar文件路徑,如果你的工程是一個pom工程,可以在父工程中放lib目錄,然后子工程只需要:
1
|
<argument>../lib/allatori.jar</argument> |
即可。
allatori.xml這個文件也很重要,看看其中的內容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<config> <input> <jar in= "confusion-0.0.1-snapshot.jar" out= "confusion-0.0.1-snapshot-obfuscated.jar" /> </input> <keep-names> < class access= "protected+" > <field access= "protected+" /> <method access= "protected+" /> </ class > </keep-names> <property name= "log-file" value= "log.xml" /> </config> |
即是對allatori混淆器的具體配置,這里可以配置很多信息,很多種策略,也可以指定哪些類不被混淆,具體的各種方式可以在在文末附件里面的文檔得到。
這里需要說明的是:
1
2
3
|
<input> <jar in= "confusion-0.0.1-snapshot.jar" out= "confusion-0.0.1-snapshot-obfuscated.jar" /> </input> |
confusion-0.0.1-snapshot.jar這個是打包后的未被混淆的包,而confusion-0.0.1-snapshot-obfuscated.jar是混淆后的包,這個是我們需要的。
打包步驟
1、clean maven工程。
2、將resources下面的allatori.xml文件復制到target目錄下面。
3、install maven工程,看到如下信息后表示成功:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
################################################ # # # ## # # ## ### ### ## ### # # # # # # # # # # # # # # # # ### # # ### # # # ## # # # # # ### ### # # # ### # # ### # # # # demo version! # # not for commercial use! # # # # demo version adds system.out's # # and gives 'allatori_demo' name # # to some fields and methods. # # # # # # obfuscation by allatori obfuscator v6. 4 demo # # # # http: //www.allatori.com # # # ################################################ |
4、成功后的工程:
箭頭所指處即是我們需要的包,此包代碼已被混淆。
效果查看
這里使用反編譯工具對混淆后的包進行查看,我用的是jd-gui這個軟件,小巧實用。
testapplication.java混淆前:
1
2
3
4
5
6
7
8
9
10
|
import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; @springbootapplication public class testapplication { public static void main(string[] args) { springapplication.run(testapplication. class , args); } } |
testapplication.java混淆后:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
import java.io.printstream; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; @springbootapplication public class testapplication { public static string allatorixdemo(string a) { int tmp4_3 = 4 ; int tmp7_6 = 1 ; int tmp21_18 = a.length(); int tmp25_24 = 1 ; tmp25_24; int j; int ? = tmp25_24; int k = tmp21_18; int tmp35_31 = (j = new char [tmp21_18] - 1 ); tmp35_31; int i = 5 << 4 ^ ( 0x2 ^ 0x5 ); (tmp4_3 << tmp4_3 ^ tmp7_6 << tmp7_6); if (tmp35_31 >= 0 ) { int tmp45_44 = j; j--; ?[tmp45_44] = (( char )(a.charat(tmp45_44) ^ i)); int tmp66_63 = (j--); ?[tmp66_63] = (( char )(a.charat(tmp66_63) ^ k)); } return new string(?); } public static void main(string[] a) { system.out.println( "\n################################################\n# #\n# ## # # ## ### ### ## ### #\n# # # # # # # # # # # # # #\n# ### # # ### # # # ## # #\n# # # ### ### # # # ### # # ### #\n# #\n# obfuscation by allatori obfuscator v6.4 demo #\n# #\n# http://www.allatori.com #\n# #\n################################################\n" ); springapplication.run(testapplication. class , a); } } |
testcontroller.java混淆前:
1
2
3
4
5
6
7
8
9
|
import org.springframework.web.bind.annotation.getmapping; import org.springframework.web.bind.annotation.restcontroller; @restcontroller public class testcontroller { @getmapping ( "/test" ) public string test(){ return "88888888888888888" ; } } |
testcontroller.java混淆后:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import org.springframework.web.bind.annotation.getmapping; import org.springframework.web.bind.annotation.restcontroller; @restcontroller public class testcontroller { @getmapping ({ "/test" }) public string test() { return allatorixdemo( "*]*]*]*]*]*]*]*]*" ); } public static string allatorixdemo(string a) { int tmp27_24 = a.length(); int tmp31_30 = 1 ; tmp31_30; int j; int ? = tmp31_30; int k = tmp27_24; int tmp41_37 = (j = new char [tmp27_24] - 1 ); tmp41_37; int i = ( 0x3 ^ 0x5 ) << 4 ^ 0x5 ; ( 2 << 3 ^ 0x2 ); if (tmp41_37 >= 0 ) { int tmp51_50 = j; j--; ?[tmp51_50] = (( char )(a.charat(tmp51_50) ^ i)); int tmp72_69 = (j--); ?[tmp72_69] = (( char )(a.charat(tmp72_69) ^ k)); } return new string(?); } } |
哈哈哈,怎么樣,是不是看不懂?并且混淆包照常運行,沒有任何問題。
-------》github 源碼與文檔地址《-------
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://juejin.im/post/5a97b50a518825558358a024