Skip to content

Commit

Permalink
Add obfuscation detector.
Browse files Browse the repository at this point in the history
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 <class> element.

obfuscated types are later filtered out by generator.

Users can overwrite this "obfuscated" attribute by Metadata.xml.
  • Loading branch information
Atsushi Eno committed Aug 8, 2012
1 parent b3a7563 commit b70ff9a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
15 changes: 14 additions & 1 deletion JavaClass.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -55,6 +55,7 @@ public class JavaClass implements Comparable<JavaClass> {
private Map<String,FieldNode> asmFields;
private List<String> deprecatedFields;
private List<String> deprecatedMethods;
private boolean is_obfuscated;

public JavaClass (Class jclass, ClassNode asm)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion JavaPackage.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
}

0 comments on commit b70ff9a

Please sign in to comment.