From b70ff9a4d6923df7372ad930933d2f7c3bf55492 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Thu, 9 Aug 2012 04:31:58 +0900 Subject: [PATCH] Add obfuscation detector. The rule is quite simple (simpler than what was originally planned). It marks any classes and interfaces whose name only consist of lowercase alphabets and $ as obfuscated="true" in the element. obfuscated types are later filtered out by generator. Users can overwrite this "obfuscated" attribute by Metadata.xml. --- JavaClass.java | 15 ++++++++++++++- JavaPackage.java | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/JavaClass.java b/JavaClass.java index 2b29499..54087f9 100644 --- a/JavaClass.java +++ b/JavaClass.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Xamarin Inc. + * Copyright (c) 2011-2012 Xamarin Inc. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -55,6 +55,7 @@ public class JavaClass implements Comparable { private Map asmFields; private List deprecatedFields; private List deprecatedMethods; + private boolean is_obfuscated; public JavaClass (Class jclass, ClassNode asm) { @@ -77,6 +78,16 @@ public String getName () { return asm.name.replace ('/', '.'); } + + public boolean isObfuscated () + { + return is_obfuscated; + } + + public void setObfuscated (boolean value) + { + is_obfuscated = value; + } String[] getParameterNames (String name, Type[] types, boolean isVarArgs) { @@ -478,6 +489,8 @@ void doAppendToDocument (Document doc, Element parent) e.setAttribute ("static", Modifier.isStatic (mods) ? "true" : "false"); e.setAttribute ("abstract", Modifier.isAbstract (mods) ? "true" : "false"); e.setAttribute ("visibility", Modifier.isPublic (mods) ? "public" : Modifier.isProtected (mods) ? "protected" : ""); + if (is_obfuscated) + e.setAttribute ("obfuscated", Boolean.toString (is_obfuscated)); Element typeParameters = getTypeParametersNode (doc, jclass.getTypeParameters ()); if (typeParameters != null) diff --git a/JavaPackage.java b/JavaPackage.java index 422002f..ebfa193 100644 --- a/JavaPackage.java +++ b/JavaPackage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Xamarin Inc. + * Copyright (c) 2011-2012 Xamarin Inc. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -62,8 +62,23 @@ public void appendToDocument (Document doc, Element parent) e.setAttribute ("name", name); parent.appendChild (e); Collections.sort (classes); + for (int i = 0; i < classes.size (); i++) { + String name = classes.get (i).getName (); + int idx = name.lastIndexOf ('.'); + String body = idx < 0 ? name : name.substring (idx + 1); + if (isObfuscatedName (body)) + classes.get (i).setObfuscated (true); + } for (JavaClass c : classes) c.appendToDocument (doc, e); } + + static boolean isObfuscatedName (String name) + { + for (char c : name.toCharArray ()) + if (c != '$' && (c < 'a' || 'z' < c)) + return false; + return true; + } }