Skip to content

Commit 064f598

Browse files
committed
[generator] less aggressive obfuscation marking.
This is a fixup for c51469e, as well as bugfix for: https://bugzilla.xamarin.com/show_bug.cgi?id=51337 What's happening behind bug #51337 was this: BINDINGSGENERATOR: warning BG8800: Unknown parameter type org.osmdroid.ResourceProxy.bitmap in method GetBitmap in managed type OsmDroid.DefaultResourceProxyImpl. This was, because, "bitmap" is all lowercased and was marked as obfuscated (because, WHY NAME A CLASS ALL IN LOWERCASE!?). Such classes should not exist, or should be marked as "obfuscated='false'". However what bug #51337 implies is that people are not going to make this additional markup for generator improvements. What this generator change does is then - a hack. A hack to mark "classes with very short names" as obfuscated, instead of "all lowercase or number". As commented on c51469e, there isn't good way to check API element siblings (it can check sibling names every time at all expensive calculation). So we just count the sibling nodes and if name length is short enough to fit within the number of classes, we mark as obfucated. As some post-first-commit thought, the name check is done only for very short names i.e. only those within 3 letters. Also, the new proguard in Gradle task seems to obfuscates the names as "zzXXXXX" . They should be marked as obfuscated too.
1 parent 39f1744 commit 064f598

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tools/generator/GenBaseSupport.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public XmlGenBaseSupport (XmlElement pkg, XmlElement elem)
204204
full_name = String.Format ("{0}.{1}{2}", ns, idx > 0 ? StringRocks.TypeToPascalCase (java_name.Substring (0, idx + 1)) : String.Empty, name);
205205
}
206206

207-
obfuscated = IsObfuscatedName (java_name) && elem.XGetAttribute ("obfuscated") != "false";
207+
obfuscated = IsObfuscatedName (pkg.ChildNodes.Count, java_name) && elem.XGetAttribute ("obfuscated") != "false";
208208
}
209209

210210
public override bool IsAcw {
@@ -302,12 +302,21 @@ public override bool ValidateNamespace ()
302302
return true;
303303
}
304304

305-
bool IsObfuscatedName (String name)
305+
bool IsObfuscatedName (int threshold, string name)
306306
{
307307
if (name.StartsWith ("R.", StringComparison.Ordinal))
308308
return false;
309309
int idx = name.LastIndexOf ('.');
310310
string last = idx < 0 ? name : name.Substring (idx + 1);
311+
// probably new proguard within Gradle tasks, used in recent GooglePlayServices in 2016 or later.
312+
if (last.StartsWith ("zz", StringComparison.Ordinal))
313+
return true;
314+
// do not expect any name with more than 3 letters is an 'obfuscated' one.
315+
if (last.Length > 3)
316+
return false;
317+
// Only short ones ('a', 'b', 'c' ... 'aa', 'ab', ... 'zzz') are the targets.
318+
if (!(name.Length == 3 && threshold > 26*26 || name.Length == 2 && threshold > 26 || name.Length == 1))
319+
return false;
311320
if (last.Any (c => (c < 'a' || 'z' < c) && (c < '0' || '9' < c)))
312321
return false;
313322
return true;

0 commit comments

Comments
 (0)