Permalink
Browse files

Implement more precise obfuscation name detection.

This fixes the issue that names like R.id or Manifest.permission were
regarded as obfuscated.
  • Loading branch information...
1 parent 360436f commit 3a7c404a3a2cb6489178cb415c5c4a217a35dba0 @atsushieno atsushieno committed Oct 18, 2012
Showing with 39 additions and 5 deletions.
  1. +39 −5 JavaPackage.java
View
@@ -64,22 +64,56 @@ public void appendToDocument (Document doc, Element parent)
Collections.sort (classes);
for (int i = 0; i < classes.size (); i++) {
String name = classes.get (i).getName ();
- int idx = name.lastIndexOf ('$');
- idx = idx < 0 ? name.lastIndexOf ('.') : idx;
- String body = idx < 0 ? name : name.substring (idx + 1);
+ String body = getLastNameComponent (name);
if (isObfuscatedName (body))
classes.get (i).setObfuscated (true);
}
for (JavaClass c : classes)
c.appendToDocument (doc, e);
}
- static boolean isObfuscatedName (String name)
+ static final String [] a_names = new String [] {
+ "a", "aa", "aaa", "aaaa", "aaaaa"};
+
+ boolean isObfuscatedName (String name)
{
+ boolean allA = true;
+ for (char c : name.toCharArray ())
+ if (c != 'a') {
+ allA = false;
+ break;
+ }
+ if (allA)
+ return true;
for (char c : name.toCharArray ())
if (c != '$' && (c < 'a' || 'z' < c) && (c < '0' || '9' < c))
return false;
- return true;
+
+ // There must be preceding 'a', 'aa' or {anything with only 'a' or '$' and matches the length}.
+ // If there isn't such a class in this package, then the argument name is not likely obfuscated.
+ //
+ // This will save R.anim, R.id, Manifest.permission etc.
+ //
+ // (Comparison limited up to "aaaaa", there wouldn't be more than that)
+
+ int length = name.length ();
+ String allAString = a_names [length < 5 ? length - 1 : 4];
+
+ for (int i = 0; i < classes.size (); i++) {
+ String cname = classes.get (i).getName ();
+ String body = getLastNameComponent (cname);
+ if (body.equals (allAString)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ static String getLastNameComponent (String name)
+ {
+ int idx = name.lastIndexOf ('$');
+ idx = idx < 0 ? name.lastIndexOf ('.') : idx;
+ return idx < 0 ? name : name.substring (idx + 1);
}
}

0 comments on commit 3a7c404

Please sign in to comment.