现在,在对android应用程序APK文件进行逆向工程时,我可以看到纯文本中的数据模型类,就像我使用@keep注释一样。如果没有注释,应用程序将崩溃,因为这些文件正在被R8删除。
如何通过确保在逆向工程中看不到数据模型文件来保护它们?
发布于 2020-02-28 23:45:17
最近我遇到了同样的问题,我确定的问题是我有一套过时的防范规则。请注意,在2019年10月4日,Gson更新了他们的前卫规则,以将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>;
}还要记住添加您的特定模型类:查看中心的规则,因为它只是一个示例,必须使用您自己的模型进行更改。
发布于 2019-12-10 20:51:10
将以下代码行添加到gradle.properties文件中。
# Disables R8 for Android Library modules only.
android.enableR8.libraries = false
# Disables R8 for all modules.
android.enableR8 = falsehttps://stackoverflow.com/questions/59267535
复制相似问题