【Android 安全】DEX 加密 ( Proguard 简介 | 默认 ProGuard 分析 )

简介: 【Android 安全】DEX 加密 ( Proguard 简介 | 默认 ProGuard 分析 )

文章目录

一、Proguard 配置简介

二、Proguard 完整注释





一、Proguard 配置简介


更多 ProGuard 混淆配置参考 : https://www.guardsquare.com/en/products/proguard/manual/usage



1 . 不进行优化 :


# 不要进行优化 
-dontoptimize



2 . 混淆大小写 : 不要使用混合大小写类名进行混淆 , 混淆后的名称全部都是小写 , 增加阅读难度


# 不要使用混合大小写类名进行混淆 , 混淆后的名称全部都是小写 , 增加阅读难度 
-dontusemixedcaseclassnames


3 . 保留反射属性 : 保留一些反射中可能用到的属性


# 保留一些反射中可能用到的属性 
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod



4 . 保留这些类和类成员 :


# 保留这些类和类成员 
-keep public class com.google.vending.licensing.ILicensingService



5 . 控制日志输出 : -dontnote , 控制编译时不在 Build 对话框输出一些日志信息 ;


# 控制编译时不在 Build 对话框输出一些日志信息 
-dontnote com.android.vending.licensing.ILicensingService


6 . Native 函数混淆设置 :


# 不混淆 Native 函数
# http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}



7 . 保留类成员 , 包括成员函数 和 成员变量 :

# 不要混淆 Activity 及 子类的 成员 , 以防在 XML 的 onCLick 属性中用到 .
-keepclassmembers class * extends android.app.Activity {
    public void *(android.view.View);
}


8 . 保留注解 : 保留 android.support.annotation.Keep 注解类 , 不被混淆 ;


# 保留注解 
-keep class android.support.annotation.Keep



9 . 保留被注解声明的类 : 被 @android.support.annotation.Keep 注解修饰的类不被混淆 ;


# 保留被 @android.support.annotation 注解声明的类 
-keep @android.support.annotation.Keep class * {*;}


10 . 保留被注解声明的函数 : 被 @android.support.annotation.Keep 注解修饰的函数不被混淆 ;


# 保留被 @android.support.annotation 注解声明的函数 
-keepclasseswithmembers class * {
    @android.support.annotation.Keep <methods>;
}



11 . 保留被注解声明的成员 : 被 @android.support.annotation.Keep 注解修改的成员 , 不会被混淆 ;


# 保留被 @android.support.annotation 注解声明的成员
-keepclasseswithmembers class * {
    @android.support.annotation.Keep <fields>;
}


12 . 保留被注解声明的构造函数 : 被 @android.support.annotation.Keep 修饰的构造函数不会被混淆 ;


# 保留被 @android.support.annotation 注解声明的构造函数 
-keepclasseswithmembers class * {
    @android.support.annotation.Keep <init>(...);
}





二、Proguard 完整注释


# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
#
# 从 Gradle 插件 2.2 版本开始 , 该文件与插件一同发布, 在编译构建时取出 .
# 不再维护 $ANDROID_HOME 中的文件 , 新的 Gradle 插件版本将会忽略这些文件 .
# 
# 默认情况下 , 优化会被关闭 . 
# Dex 自己会执行优化 , 不建议在 ProGuard 步骤中进行优化 . 
# 如果想要启用优化 , 不能只在 ProGuard 项目配置中将优化标志设为 true ;
# 相反还要在 build.gradle 中指向 "proguard-android-optimize.txt" 文件 .
# 不要进行优化 
-dontoptimize
# 不要使用混合大小写类名进行混淆 , 混淆后的名称全部都是小写 , 增加阅读难度 
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
# 保留一些反射中可能用到的属性 
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
# 保留这些类和类成员 
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keep public class com.google.android.vending.licensing.ILicensingService
# 控制编译时不在 Build 对话框输出一些日志信息 
-dontnote com.android.vending.licensing.ILicensingService
-dontnote com.google.vending.licensing.ILicensingService
-dontnote com.google.android.vending.licensing.ILicensingService
# 不混淆 Native 函数
# http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}
# 不要混淆继承自 View 的 get set 函数 , 以便让动画可以继续工作
# 指定类成员 ( 成员方法 / 成员变量 ) 不被混淆 
-keepclassmembers public class * extends android.view.View {
    void set*(***);
    *** get*();
}
# 不要混淆 Activity 及 子类的 成员 , 以防在 XML 的 onCLick 属性中用到 .
-keepclassmembers class * extends android.app.Activity {
    public void *(android.view.View);
}
# 枚举成员不要混淆 
# http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
    public static final ** CREATOR;
}
-keepclassmembers class **.R$* {
    public static <fields>;
}
# Preserve annotated Javascript interface methods.
-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}
# The support libraries contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontnote android.support.**
-dontnote androidx.**
-dontwarn android.support.**
-dontwarn androidx.**
# This class is deprecated, but remains for backward compatibility.
-dontwarn android.util.FloatMath
# Understand the @Keep support annotation.
# 保留注解 
-keep class android.support.annotation.Keep
-keep class androidx.annotation.Keep
# 保留被 @android.support.annotation 注解声明的类 
-keep @android.support.annotation.Keep class * {*;}
# 保留被 @androidx.annotation 注解声明的类 
-keep @androidx.annotation.Keep class * {*;}
# 保留被 @android.support.annotation 注解声明的函数 
-keepclasseswithmembers class * {
    @android.support.annotation.Keep <methods>;
}
# 保留被 @androidx.annotation 注解声明的函数 
-keepclasseswithmembers class * {
    @androidx.annotation.Keep <methods>;
}
# 保留被 @android.support.annotation 注解声明的成员
-keepclasseswithmembers class * {
    @android.support.annotation.Keep <fields>;
}
# 保留被 @androidx.annotation 注解声明的成员 
-keepclasseswithmembers class * {
    @androidx.annotation.Keep <fields>;
}
# 保留被 @android.support.annotation 注解声明的构造函数 
-keepclasseswithmembers class * {
    @android.support.annotation.Keep <init>(...);
}
# 保留被 @androidx.annotation 注解声明的构造方法 
-keepclasseswithmembers class * {
    @androidx.annotation.Keep <init>(...);
}
# These classes are duplicated between android.jar and org.apache.http.legacy.jar.
-dontnote org.apache.http.**
-dontnote android.net.http.**
# These classes are duplicated between android.jar and core-lambda-stubs.jar.
-dontnote java.lang.invoke.**


目录
相关文章
|
存储 安全 Cloud Native
云原生安全必修课:RDS透明加密(TDE)与数据脱敏联动实施方案
云原生环境下,数据泄露风险日益严峻,传统安全方案面临加密与脱敏割裂、保护不连续、权限控制粗放三大挑战。本方案融合TDE透明加密与动态数据脱敏技术,构建存储-传输-计算全链路防护体系,通过SQL级加密与角色化脱敏规则,实现细粒度数据保护。结合密钥管理、权限控制与多云适配,提升安全性与性能,广泛适用于金融、医疗等高安全要求场景。
560 3
|
12月前
|
安全 算法 量子技术
量子来了,DeFi慌了吗?——聊聊量子安全加密对去中心化金融的“革命冲击”
量子来了,DeFi慌了吗?——聊聊量子安全加密对去中心化金融的“革命冲击”
354 0
|
存储 安全 数据安全/隐私保护
Hyper V文件复制安全:加密与访问控制
在Hyper-V环境中,确保文件复制的安全性至关重要。主要措施包括:启用数据加密、使用HTTPS协议和磁盘加密技术(如BitLocker)保护数据传输和存储;通过身份验证、权限管理和审核日志控制访问;定期更新补丁、实施网络隔离及制定备份恢复策略。这些多层次的安全措施共同防止未经授权的访问和数据泄露,保障数据安全。
Hyper V文件复制安全:加密与访问控制
|
监控 安全 算法
【Android 安全】DEX 加密 ( Application 替换 | 兼容 ContentProvider 操作 | 源码资源 )(三)
【Android 安全】DEX 加密 ( Application 替换 | 兼容 ContentProvider 操作 | 源码资源 )(三)
282 0
【Android 安全】DEX 加密 ( Application 替换 | 兼容 ContentProvider 操作 | 源码资源 )(三)
|
安全 Android开发 数据安全/隐私保护
【Android 安全】DEX 加密 ( Application 替换 | 兼容 ContentProvider 操作 | 源码资源 )(二)
【Android 安全】DEX 加密 ( Application 替换 | 兼容 ContentProvider 操作 | 源码资源 )(二)
329 0
|
监控 安全 Java
【Android 安全】DEX 加密 ( Application 替换 | 兼容 ContentProvider 操作 | 源码资源 )(一)
【Android 安全】DEX 加密 ( Application 替换 | 兼容 ContentProvider 操作 | 源码资源 )(一)
410 0
|
安全 Java Android开发
【Android 安全】DEX 加密 ( Application 替换 | 分析 ContentProvider 组件中调用 getApplication() 获取的 Application 二 )(二)
【Android 安全】DEX 加密 ( Application 替换 | 分析 ContentProvider 组件中调用 getApplication() 获取的 Application 二 )(二)
343 0
|
人工智能 安全 Java
【Android 安全】DEX 加密 ( Application 替换 | 分析 ContentProvider 组件中调用 getApplication() 获取的 Application 二 )(一)
【Android 安全】DEX 加密 ( Application 替换 | 分析 ContentProvider 组件中调用 getApplication() 获取的 Application 二 )(一)
360 0
|
安全 Java Android开发
【Android 安全】DEX 加密 ( Application 替换 | 分析 Activity 组件中获取的 Application | ActivityThread | LoadedApk )(三)
【Android 安全】DEX 加密 ( Application 替换 | 分析 Activity 组件中获取的 Application | ActivityThread | LoadedApk )(三)
241 0