繁体   English   中英

在 Android 中使用 R8 和 Proguard 时,如何从逆向工程中保护数据模型类?

[英]How to secure data model classes from reverse engineering when using R8 and Proguard in Android?

现在,在对 android 应用程序 APK 文件进行逆向工程时,我可以在纯文本中看到数据模型类,因为我使用了@keep注释。 如果没有注释,应用程序就会崩溃,因为 R8 正在删除这些文件。

如何通过确保在逆向工程中看不到数据模型文件来保护数据模型文件?

最近我遇到了同样的问题,我的某些问题是我有一套过时的 proguard 规则。 请注意,2019 年 10 月 4 日,Gson 更新了他们的 proguard 规则以将 R8 考虑在内。 希望你必须更新它们。

您可以在https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg找到它

# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

还要记住添加您的某些模型类:查看中心的规则,因为它只是一个示例,必须使用您自己的模型进行更改。

将以下gradle.properties行添加到gradle.properties文件中。

# Disables R8 for Android Library modules only.
android.enableR8.libraries = false
# Disables R8 for all modules.
android.enableR8 = false

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM