开源混淆工具ProGuard配置详解及配置实例

简介:
ProGuard的作用: 
 
1.创建紧凑的代码文档是为了更快的网络传输,快速装载和更小的内存占用. 
2.创建的程序和程序库很难使用反向工程. 
3.所以它能删除来自源文件中的没有调用的代码 
4.充分利用java6的快速加载的优点来提前检测和返回java6中存在的类文件. 
 
参数: 
 
-include {filename}    从给定的文件中读取配置参数 
-basedirectory {directoryname}    指定基础目录为以后相对的档案名称 
-injars {class_path}    指定要处理的应用程序jar,war,ear和目录 
-outjars {class_path}    指定处理完后要输出的jar,war,ear和目录的名称 
-libraryjars {classpath}    指定要处理的应用程序jar,war,ear和目录所需要的程序库文件 
-dontskipnonpubliclibraryclasses    指定不去忽略非公共的库类。 
-dontskipnonpubliclibraryclassmembers    指定不去忽略包可见的库类的成员。 

保留选项 

-keep {Modifier} {class_specification}    保护指定的类文件和类的成员 
-keepclassmembers {modifier} {class_specification}    保护指定类的成员,如果此类受到保护他们会保护的更好
-keepclasseswithmembers {class_specification}    保护指定的类和类的成员,但条件是所有指定的类和类成员是要存在。 
-keepnames {class_specification}    保护指定的类和类的成员的名称(如果他们不会压缩步骤中删除) 
-keepclassmembernames {class_specification}    保护指定的类的成员的名称(如果他们不会压缩步骤中删除)
-keepclasseswithmembernames {class_specification}    保护指定的类和类的成员的名称,如果所有指定的类成员出席(在压缩步骤之后) 
-printseeds {filename}    列出类和类的成员-keep选项的清单,标准输出到给定的文件 
 
压缩 

-dontshrink    不压缩输入的类文件 
-printusage {filename} 
-whyareyoukeeping {class_specification}     
 
优化 

-dontoptimize    不优化输入的类文件 
-assumenosideeffects {class_specification}    优化时假设指定的方法,没有任何副作用 
-allowaccessmodification    优化时允许访问并修改有修饰符的类和类的成员 
 
混淆 

-dontobfuscate    不混淆输入的类文件 
-printmapping {filename} 
-applymapping {filename}    重用映射增加混淆 
-obfuscationdictionary {filename}    使用给定文件中的关键字作为要混淆方法的名称 
-overloadaggressively    混淆时应用侵入式重载 
-useuniqueclassmembernames    确定统一的混淆类的成员名称来增加混淆 
-flattenpackagehierarchy {package_name}    重新包装所有重命名的包并放在给定的单一包中 
-repackageclass {package_name}    重新包装所有重命名的类文件中放在给定的单一包中 
-dontusemixedcaseclassnames    混淆时不会产生形形色色的类名 
-keepattributes {attribute_name,...}    保护给定的可选属性,例如LineNumberTable, LocalVariableTable, SourceFile, Deprecated, Synthetic, Signature, and InnerClasses. 
-renamesourcefileattribute {string}    设置源文件中给定的字符串常量


Ant Example:

<!-- This Ant build file illustrates how to process applications,
     by including ProGuard-style configuration options.
     Usage: ant -f applications2.xml -->

<project name="Applications" default="obfuscate" basedir="../..">

<target name="obfuscate">
  <taskdef resource="proguard/ant/task.properties"
           classpath="lib/proguard.jar" />

  <proguard>

    <!-- Specify the input jars, output jars, and library jars. -->

    -injars  in.jar
    -outjars out.jar

    -libraryjars ${java.home}/lib/rt.jar
    <!-- -libraryjars junit.jar    -->
    <!-- -libraryjars servlet.jar  -->
    <!-- -libraryjars jai_core.jar -->
    <!-- ...                       -->

    <!-- Save the obfuscation mapping to a file, and preserve line numbers. -->

    -printmapping out.map
    -renamesourcefileattribute SourceFile
    -keepattributes SourceFile,LineNumberTable

    <!-- Preserve all annotations. -->

    -keepattributes *Annotation*

    <!-- Preserve all public applications. -->

    -keepclasseswithmembers public class * {
        public static void main(java.lang.String[]);
    }

    <!-- Preserve all native method names and the names of their classes. -->

    -keepclasseswithmembernames class * {
        native &lt;methods&gt;;
    }

    <!-- Preserve the methods that are required in all enumeration classes. -->

    -keepclassmembers class * extends java.lang.Enum {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }

    <!-- Explicitly preserve all serialization members. The Serializable
         interface is only a marker interface, so it wouldn't save them.
         You can comment this out if your library doesn't use serialization.
         If your code contains serializable classes that have to be backward
         compatible, please refer to the manual. -->

    -keepclassmembers class * implements java.io.Serializable {
        static final long serialVersionUID;
        static final java.io.ObjectStreamField[] serialPersistentFields;
        private void writeObject(java.io.ObjectOutputStream);
        private void readObject(java.io.ObjectInputStream);
        java.lang.Object writeReplace();
        java.lang.Object readResolve();
    }

    <!-- Your application may contain more items that need to be preserved;
         typically classes that are dynamically created using Class.forName -->

  </proguard>
</target>

</project>

本文转自demoblog博客园博客,原文链接http://www.cnblogs.com/0616--ataozhijia/p/3723967.html如需转载请自行联系原作者


demoblog

相关文章
|
SQL 存储 关系型数据库
一文搞懂SQL优化——如何高效添加数据
**SQL优化关键点:** 1. **批量插入**提高效率,一次性建议不超过500条。 2. **手动事务**减少开销,多条插入语句用一个事务。 3. **主键顺序插入**避免页分裂,提升性能。 4. **使用`LOAD DATA INFILE`**大批量导入快速。 5. **避免主键乱序**,减少不必要的磁盘操作。 6. **选择合适主键类型**,避免UUID或长主键导致的性能问题。 7. **避免主键修改**,保持索引稳定。 这些技巧能优化数据库操作,提升系统性能。
909 4
一文搞懂SQL优化——如何高效添加数据
|
关系型数据库 流计算 PostgreSQL
关于PostgreSQL逻辑订阅中的复制状态
关于PostgreSQL逻辑订阅中的复制状态
3013 0
|
缓存 Linux 开发工具
CentOS 7- 配置阿里镜像源
阿里镜像官方地址http://mirrors.aliyun.com/ 1、点击官方提供的相应系统的帮助 :2、查看不同版本的系统操作: 下载源1、安装wget yum install -y wget2、下载CentOS 7的repo文件wget -O /etc/yum.
255276 0
|
安全 Java Maven
SpringBoot如何防止反编译?proguard+xjar 完美搞定
【8月更文挑战第10天】在软件开发过程中,保护源代码不被反编译是确保应用安全性的重要一环。对于使用Spring Boot框架的项目来说,防止反编译尤为重要。本文将详细介绍如何使用ProGuard和xjar这两种工具来增强Spring Boot项目的安全性,防止代码被恶意反编译。
2119 8
|
9月前
|
SQL Java API
|
8月前
|
存储 人工智能 自然语言处理
Lindorm作为AI搜索基础设施,助力Kimi智能助手升级搜索体验
Lindorm作为AI搜索基础设施,助力Kimi智能助手升级搜索体验
192 0
|
Java 测试技术 开发工具
使用Spring Boot和Spock进行单元测试
使用Spring Boot和Spock进行单元测试
|
Java Maven 数据安全/隐私保护
jar包加密防止反编译--classFinal
jar包加密防止反编译--classFinal
3676 0
|
安全 Java jenkins
Java | ProGuard——java代码混淆利器
Java | ProGuard——java代码混淆利器
5038 0
Java | ProGuard——java代码混淆利器
|
移动开发 JavaScript 前端开发
Web Worker:JavaScript的后台任务解决方案
Web Worker:JavaScript的后台任务解决方案