Reputation: 3238
I have simple POJO with various attributes each with getters and setters. All is being obfuscated fine except for those named id and serialNumber.
The id attribute does not get renamed nor does its getters and setters.
The serialNumber attribute does get renamed but its getters and setters don't.
There is nothing special about these attributes nor have I put anything in my Proguard configuration to make Proguard treat them differently.
My Proguard configuration
# Fudge around some issues
-dontskipnonpubliclibraryclasses
# Preserve all annotations.
-keepattributes *Annotation*
# Preserve all native method names and the names of their classes.
-keepclasseswithmembernames class * {
native <methods>;
}
# Preserve the special static methods that are required in all enumeration
# classes.
-keepclassmembers class * extends java.lang.Enum {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
# You can comment this out if your application doesn't use serialization.
# If your code contains serializable classes that have to be backward
# compatible, please refer to the manual.
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# Keep some source file attributes so we have a chance of decoding stack traces
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
# make sure we keep info for downstream libraries
-dontshrink
-dontoptimize
-useuniqueclassmembernames
and the output from the map file
java.lang.String id -> id
int productCode -> a
int platform -> b
java.lang.String model -> c
java.lang.String serialNumber -> d
java.lang.String machineID -> e
java.lang.String parentSerialNumber -> f
long clientTime -> g
38:38:java.lang.String getId() -> getId
47:48:void setId(java.lang.String) -> setId
52:52:int getProductCode() -> a
57:58:void setProductCode(int) -> a
62:62:int getPlatform() -> b
67:68:void setPlatform(int) -> b
72:72:java.lang.String getModel() -> c
77:78:void setModel(java.lang.String) -> a
82:82:java.lang.String getSerialNumber() -> getSerialNumber
87:88:void setSerialNumber(java.lang.String) -> setSerialNumber
92:92:java.lang.String getMachineID() -> d
97:98:void setMachineID(java.lang.String) -> b
102:102:java.lang.String getParentSerialNumber() -> e
107:108:void setParentSerialNumber(java.lang.String) -> c
112:112:long getClientTime() -> f
117:118:void setClientTime(long) -> a
Upvotes: 0
Views: 1516
Reputation: 45676
The option -useuniqueclassmembernames
does this, to future-proof the obfuscation mapping for changes in your code. Future code might add a common interface for this class and some of your library classes containing these methods. This would break the mapping if the methods were renamed.
Upvotes: 3
Reputation: 14222
It is due to the use of the -useuniqueclassmembernames
option.
If the class member names have to correspond globally (which includes the Java Runtime Library), this option links all class members in all classes together.
That means, if there is any method Foo#getName()
being obfuscated to a()
in one class, methods in other classes but with the same name Bar#getName()
will also be mapped to the obfuscated name a()
:
Foo.getName() -> Foo.a()
Bar.getName() -> Bar.a()
Now come the library jars into play. Since ProGuard also looks into the library jars to find out about references, it will scan rt.jar
for classes and will find classes such as:
These classes do also have methods the methods:
These members are ignored for obfuscation, but their name mapping (getSerialNumber
> getSerialNumber
) is recorded by ProGuard and kept in a descriptor map due to the useUniqueClassMemberNames configuration option.
For reference: i found this out by debugging ProGuard with your config file. It seems to be the case where for the member info linker, the AllMemberVisitor is used instead of the BottomClassFilter, but i haven't got such a deep understanding on how the internals of ProGuard work to be sure.
Upvotes: 4