【发布时间】:2014-08-11 08:37:24
【问题描述】:
我最近首次启用了 Proguard 的混淆功能,它似乎可以找到我的 -keep 规则中的所有漏洞。
我的保留规则是使用注释定义的:注释的元素将被单独保留。随后的配置如下所示:
# Keep the annotation.
-keep @interface org.mozilla.gecko.mozglue.JNITarget
# Keep classes tagged with the annotation.
-keep @org.mozilla.gecko.mozglue.JNITarget class *
# Keep all members of an annotated class.
-keepclassmembers @org.mozilla.gecko.mozglue.JNITarget class * {
*;
}
# Keep annotated members of any class.
-keepclassmembers class * {
@org.mozilla.gecko.mozglue.JNITarget *;
}
# Keep classes which contain at least one annotated element. Split over two directives
# because, according to the developer of ProGuard, "the option -keepclasseswithmembers
# doesn't combine well with the '*' wildcard" (And, indeed, using it causes things to
# be deleted that we want to keep.)
-keepclasseswithmembers class * {
@org.mozilla.gecko.mozglue.JNITarget <methods>;
}
-keepclasseswithmembers class * {
@org.mozilla.gecko.mozglue.JNITarget <fields>;
}
从 Reflection/JNI/etc 到 Java 的所有入口点。使用此(或等效配置但名称更好的)注释进行注释。
不幸的是,这并不能阻止 Proguard 重命名用作方法的返回类型的类,从而更改其签名并破坏入口点。
例如,Javap 显示带有签名的方法:
public org.mozilla.gecko.Tab loadUrl(java.lang.String);
从 Proguard 出来的样子:
public mt loadUrl(java.lang.String);
尽管被注释了。
那么,保持依赖类的神秘 -keep 语法是什么?奇怪的是,告诉它我希望保留一个入口点,它无论如何都会破坏它......
【问题讨论】: