当前位置:   article > 正文

Java maven 环境下使用proguard-maven-plugin 插件混淆代码_java 代码混淆 自定义装载器技术proguard-maven-plugin

java 代码混淆 自定义装载器技术proguard-maven-plugin


相关链接

http://blog.csdn.net/zhyhang/article/details/18567409


http://blog.csdn.net/zhangjianying/article/details/7939593?c=127e3ef14a86fd3afef97eac34257db1


http://my.oschina.net/noahxiao/blog/304746?utm_source=tuicool&utm_medium=referral

 maven配置:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <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">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.yunshouhu</groupId>
  5. <artifactId>ApkProtect</artifactId>
  6. <version>1.0</version>
  7. <packaging>jar</packaging>
  8. <properties>
  9. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  10. <maven.compiler.source>1.7</maven.compiler.source>
  11. <maven.compiler.target>1.7</maven.compiler.target>
  12. <java.version>1.7</java.version>
  13. </properties>
  14. <build>
  15. <plugins>
  16. <plugin>
  17. <groupId>org.apache.maven.plugins</groupId>
  18. <artifactId>maven-compiler-plugin</artifactId>
  19. <configuration>
  20. <source>${java.version}</source>
  21. <target>${java.version}</target>
  22. </configuration>
  23. </plugin>
  24. <plugin>
  25. <groupId>org.apache.maven.plugins</groupId>
  26. <artifactId>maven-shade-plugin</artifactId>
  27. <executions>
  28. <execution>
  29. <phase>package</phase>
  30. <goals>
  31. <goal>shade</goal>
  32. </goals>
  33. <configuration>
  34. <transformers>
  35. <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
  36. <mainClass>com.yunshouhu.apkprotect.MainHelper</mainClass>
  37. </transformer>
  38. </transformers>
  39. </configuration>
  40. </execution>
  41. </executions>
  42. </plugin>
  43. <plugin>
  44. <groupId>com.pyx4me</groupId>
  45. <artifactId>proguard-maven-plugin</artifactId>
  46. <executions>
  47. <execution>
  48. <phase>package</phase>
  49. <goals>
  50. <goal>proguard</goal>
  51. </goals>
  52. </execution>
  53. </executions>
  54. <configuration>
  55. <obfuscate>true</obfuscate>
  56. <proguardInclude>${basedir}/proguard.conf</proguardInclude>
  57. <!-- 添加依赖,这里你可以按你的需要修改 -->
  58. <libs>
  59. <lib>${java.home}/lib/rt.jar</lib>
  60. <lib>lib/fcexporter_jdk1.5.jar</lib>
  61. <lib>lib/fcexporthandler.jar</lib>
  62. <lib>lib/jsp-api.jar</lib>
  63. <lib>lib/servlet-api.jar</lib>
  64. </libs>
  65. <addMavenDescriptor>false</addMavenDescriptor>
  66. </configuration>
  67. <dependencies>
  68. <!-- 使用4.8版本来混淆 -->
  69. <dependency>
  70. <groupId>net.sf.proguard</groupId>
  71. <artifactId>proguard</artifactId>
  72. <version>4.4</version>
  73. <scope>runtime</scope>
  74. </dependency>
  75. </dependencies>
  76. </plugin>
  77. </plugins>
  78. </build>
  79. </project>

ok版本

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <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">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.yunshouhu</groupId>
  5. <artifactId>ApkProtect</artifactId>
  6. <version>1.0</version>
  7. <packaging>jar</packaging>
  8. <properties>
  9. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  10. <maven.compiler.source>1.8</maven.compiler.source>
  11. <maven.compiler.target>1.8</maven.compiler.target>
  12. <java.version>1.8</java.version>
  13. </properties>
  14. <build>
  15. <plugins>
  16. <plugin>
  17. <groupId>org.apache.maven.plugins</groupId>
  18. <artifactId>maven-compiler-plugin</artifactId>
  19. <configuration>
  20. <source>${java.version}</source>
  21. <target>${java.version}</target>
  22. </configuration>
  23. </plugin>
  24. <plugin>
  25. <groupId>org.apache.maven.plugins</groupId>
  26. <artifactId>maven-shade-plugin</artifactId>
  27. <executions>
  28. <execution>
  29. <phase>package</phase>
  30. <goals>
  31. <goal>shade</goal>
  32. </goals>
  33. <configuration>
  34. <transformers>
  35. <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
  36. <mainClass>com.yunshouhu.apkprotect.MainHelper</mainClass>
  37. </transformer>
  38. </transformers>
  39. </configuration>
  40. </execution>
  41. </executions>
  42. </plugin>
  43. <plugin>
  44. <groupId>com.github.wvengen</groupId>
  45. <artifactId>proguard-maven-plugin</artifactId>
  46. <version>2.0.11</version>
  47. <executions>
  48. <execution>
  49. <phase>package</phase>
  50. <goals>
  51. <goal>proguard</goal>
  52. </goals>
  53. </execution>
  54. </executions>
  55. <configuration>
  56. <attach>true</attach>
  57. <attachArtifactClassifier>proguard</attachArtifactClassifier>
  58. <!-- attach 的作用是在 install 与 deploy 时将生成的 pg 文件也安装与部署 -->
  59. <options> <!-- 详细配置方式参考 ProGuard 官方文档 -->
  60. <!--<option>-dontobfuscate</option>-->
  61. <option>-ignorewarnings</option> <!--忽略所有告警-->
  62. <option>-dontshrink</option> <!--不做 shrink -->
  63. <option>-dontoptimize</option> <!--不做 optimize -->
  64. <option>-dontskipnonpubliclibraryclasses</option>
  65. <option>-dontskipnonpubliclibraryclassmembers</option>
  66. <!--不要重构包名
  67. <option>-repackageclasses org.noahx.proguard.example.project2.pg</option>
  68. -->
  69. <!--平行包结构(重构包层次),所有混淆的类放在 pg 包下-->
  70. <!--保护程序入口-->
  71. <option>-keep public class com.yunshouhu.apkprotect.MainHelper { public static void main(java.lang.String[]);}</option>
  72. <!-- 以下为 Keep,哪些内容保持不变,因为有一些内容混淆后(a,b,c)导致反射或按类名字符串相关的操作失效 -->
  73. <option>-keep class **.package-info</option>
  74. <!--保持包注解类-->
  75. <option>-keepattributes Signature</option>
  76. <!--JAXB NEED,具体原因不明,不加会导致 JAXB 出异常,如果不使用 JAXB 根据需要修改-->
  77. <!-- Jaxb requires generics to be available to perform xml parsing and without this option ProGuard was not retaining that information after obfuscation. That was causing the exception above. -->
  78. <option>-keepattributes SourceFile,LineNumberTable,*Annotation*</option>
  79. <!--保持源码名与行号(异常时有明确的栈信息),注解(默认会过滤掉所有注解,会影响框架的注解)-->
  80. <option>-keepclassmembers enum org.noahx.proguard.example.project2.** { *;}</option>
  81. <!--保持枚举中的名子,确保枚举 valueOf 可以使用-->
  82. <option>-keep class org.noahx.proguard.example.project2.bean.** { *;}</option>
  83. <!--保持 Bean 类,(由于很多框架会对 Bean 中的内容做反射处理,请根据自己的业务调整) -->
  84. <option>-keep class org.noahx.proguard.example.project2.Project2 { public void init(); public void
  85. destroy(); }
  86. </option>
  87. <!-- 保持对外的接口性质类对外的类名与方法名不变 -->
  88. </options>
  89. <outjar>${project.build.finalName}-proguard</outjar>
  90. <libs>
  91. <lib>${java.home}/lib/rt.jar</lib>
  92. </libs>
  93. </configuration>
  94. </plugin>
  95. </plugins>
  96. </build>
  97. </project>

proguard.cfg 文件方式配置ok版本

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <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">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.yunshouhu</groupId>
  5. <artifactId>ApkProtect</artifactId>
  6. <version>1.0</version>
  7. <packaging>jar</packaging>
  8. <properties>
  9. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  10. <maven.compiler.source>1.7</maven.compiler.source>
  11. <maven.compiler.target>1.7</maven.compiler.target>
  12. <java.version>1.7</java.version>
  13. </properties>
  14. <build>
  15. <plugins>
  16. <plugin>
  17. <groupId>org.apache.maven.plugins</groupId>
  18. <artifactId>maven-compiler-plugin</artifactId>
  19. <configuration>
  20. <source>${java.version}</source>
  21. <target>${java.version}</target>
  22. </configuration>
  23. </plugin>
  24. <plugin>
  25. <groupId>org.apache.maven.plugins</groupId>
  26. <artifactId>maven-shade-plugin</artifactId>
  27. <executions>
  28. <execution>
  29. <phase>package</phase>
  30. <goals>
  31. <goal>shade</goal>
  32. </goals>
  33. <configuration>
  34. <transformers>
  35. <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
  36. <mainClass>com.yunshouhu.apkprotect.MainHelper</mainClass>
  37. </transformer>
  38. </transformers>
  39. </configuration>
  40. </execution>
  41. </executions>
  42. </plugin>
  43. <plugin>
  44. <groupId>com.github.wvengen</groupId>
  45. <artifactId>proguard-maven-plugin</artifactId>
  46. <version>2.0.11</version>
  47. <executions>
  48. <execution>
  49. <phase>package</phase>
  50. <goals>
  51. <goal>proguard</goal>
  52. </goals>
  53. </execution>
  54. </executions>
  55. <configuration>
  56. <obfuscate>true</obfuscate>
  57. <proguardInclude>${basedir}/proguard.cfg</proguardInclude>
  58. <attach>true</attach>
  59. <attachArtifactClassifier>proguard</attachArtifactClassifier>
  60. </configuration>
  61. </plugin>
  62. </plugins>
  63. </build>
  64. </project>
proguard.cfg文件
  1. # ----------------------------------
  2. # 通过指定数量的优化能执行
  3. # -optimizationpasses n
  4. # ----------------------------------
  5. -optimizationpasses 3
  6. # ----------------------------------
  7. # 混淆时不会产生形形色色的类名
  8. # -dontusemixedcaseclassnames
  9. # ----------------------------------
  10. -dontusemixedcaseclassnames
  11. # ----------------------------------
  12. # 指定不去忽略非公共的库类
  13. # -dontskipnonpubliclibraryclasses
  14. # ----------------------------------
  15. #-dontskipnonpubliclibraryclasses
  16. # ----------------------------------
  17. # 不预校验
  18. # -dontpreverify
  19. # ----------------------------------
  20. # -dontpreverify
  21. # ----------------------------------
  22. # 输出生成信息
  23. # -verbose
  24. # ----------------------------------
  25. -verbose
  26. #混淆时应用侵入式重载
  27. -overloadaggressively
  28. #优化时允许访问并修改有修饰符的类和类的成员
  29. -allowaccessmodification
  30. #确定统一的混淆类的成员名称来增加混淆
  31. -useuniqueclassmembernames
  32. -ignorewarnings
  33. -dontshrink
  34. -dontoptimize
  35. -dontskipnonpubliclibraryclasses
  36. -dontskipnonpubliclibraryclassmembers
  37. -keep public class com.yunshouhu.apkprotect.MainHelper { public static void main(java.lang.String[]);}
  38. -keep class **.package-info
  39. -keepattributes Signature
  40. -keepattributes SourceFile,LineNumberTable,*Annotation*
  41. -keep public class com.yunshouhu.apkprotect.MainHelper {
  42. public static void main(java.lang.String[]);
  43. }
  44. #这里添加你不需要混淆的类
  45. -keep class com.zsoftware.common.cache.** {*;}
  46. -keep public class * extends javax.servlet.Servlet
  47. -keepattributes **
  48. #-keepnames class * implements java.io.Serializable
  49. # ---------保护所有实体中的字段名称----------
  50. -keepclassmembers class * implements java.io.Serializable {
  51. <fields>;
  52. }
  53. # --------- 保护类中的所有方法名 ------------
  54. -keepclassmembers class * {
  55. public <methods>;
  56. }


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/614228
推荐阅读
相关标签
  

闽ICP备14008679号