为什么ProGuard不会混淆内部类/枚举

时间:2019-01-04 15:26:18

标签: java proguard obfuscation inner-classes enumeration

我试图混淆某些包含许多内部枚举的类,我理解这些内部枚举在编译时由javac编译为使用“ $”分隔符分隔独立的类。

但是,我遇到的问题是,尽管混淆了枚举的内容,但是父/外部类以及枚举类名称本身以及它们的包名称并未被混淆,因为这些类本身就是不被迷惑。

我们已指定ProGuard将各种其他类保留在我们的专有程序包中(正在正确处理),但是这些不应影响上述类。

这是我们的config.pro文件:

-injars .\build\libs\plugin.jar
-outjars .\build\libs\plugin_obfuscated.jar

-libraryjars .\jre\lib\rt.jar
-libraryjars .\jre\lib\jce.jar
-libraryjars .\jre\lib\ext\jfxrt.jar

## Mapping
-classobfuscationdictionary .\config_classnames.pro
-packageobfuscationdictionary .\config_packagenames.pro

-printmapping .\build\libs\proguard_obfuscation_map.txt
-printseeds .\build\libs\proguard_seeds_map.txt
-printusage .\build\libs\proguard_deadusage_map.txt

## Shrinking
-dontshrink

## Optimizations
#-dontoptimize
-optimizations method/removal/parameter,method/inlining/short,
  method/inlining/unique
-optimizations code/removal/advanced,code/simplification/string,
  code/removal/exception,code/removal/variable,code/merging
-optimizations class/unboxing/enum
-allowaccessmodification
-mergeinterfacesaggressively
#-optimizationpasses 5

#-repackageclasses ''
-flattenpackagehierarchy 'software'

## Obfuscation
-dontusemixedcaseclassnames
-overloadaggressively

## Keep attributes
-keepattributes !InnerClasses,Signature,Deprecated,*Annotation*,Synthetic 
-adaptresourcefilecontents **.fxml


# ProGuard doesn't print notes about classes with matching names
-dontnote com.google.**
-dontnote com.sun.**
-dontnote org.apache.log4j.**
-dontnote org.apache.logging.**
-dontnote com.itextpdf.**
-dontnote org.apache.commons.io.**
-dontnote org.apache.commons.codec.**
-dontnote org.apache.commons.lang3.**
-dontnote org.hibernate.**

-dontnote **
-dontwarn **

# Keep specific proprietary classes
-keep class com.mycompany.product.framework.logging.** {
}

-keep class com.mycompany.product.plugin.persistence.** {
    <fields>;
    <methods>;
}

-keep class com.mycompany.product.plugin.networking.** { 
    <fields>;
    <methods>;
}

-keep class com.mycompany.product.framework.automation.events.** {
    <fields>;
    <methods>;
}

-keep class com.mycompany.product.plugin.events.** {
    <fields>;
    <methods>;
}

-keep class com.mycompany.product.plugin.remote.** { 
    <fields>;
    <methods>;
}

-keepnames class com.mycompany.product.plugin.providers.* {
}

-keepclassmembers class com.mycompany.product.framework.events.TestCase 
{
    <fields>;
    <methods>;
}

# Keep class members with @FXML annotations
-keepclassmembers,allowshrinking class * {
    @javafx.fxml.FXML
    <fields>;
    @javafx.fxml.FXML
    <methods>;
}

# Keep - Antlr library 
-keep class antlr.** {
    <fields>;
    <methods>;
}

# Keep fasterxml
-keep class com.fasterxml.** { 
    <fields>;
    <methods>; 
}

# Keep - Google classes
-keep class com.google.** {
    <fields>;
    <methods>;
}

... remaining other classes not to be included / sanitized
... followed by standard Proguard template configuration (truncated)

# Keep classes that implement Serializable
 -keepnames class * implements java.io.Serializable
 -keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}
# Keep - Applications. Keep all application classes, along with their 
 'main' methods.
-keepclasseswithmembers public class * {
    public static void main(java.lang.String[]);
}

# Also keep - Enumerations. Keep the special static methods that are 
 required in enumeration classes.
-keepclassmembers enum  * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Keep - Native method names. Keep all native class/method names.
-keepclasseswithmembers,includedescriptorclasses,allowshrinking class * {
    native <methods>;
}

我们要混淆的类包括以下内部/嵌套枚举类:

com.mycompany.packageContainingEnum1.enumOuterClass1
com.mycompany.packageContainingEnum1.enumOuterClass1$enum1ClassName

com.mycompany.packageContainingEnum2.enumouterClass2
com.mycompany.packageContainingEnum2.enumOuterClass2$enum2ClassName

如您所见,出现问题的软件包在“产品”软件包下方,因此不应该受到上述规则的影响吗?

有什么想法可以保留enumouterClass2enumOuterClass2$enum2ClassName(枚举)名称吗?这似乎很奇怪,因为默认情况下,大多数人似乎在防止混淆内部类时遇到麻烦。

非常感谢您的帮助。

0 个答案:

没有答案