Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 3a7c404a3a2cb6489178cb415c5c4a217a35dba0 1 parent 360436f
@atsushieno atsushieno authored
Showing with 39 additions and 5 deletions.
  1. +39 −5 JavaPackage.java
View
44 JavaPackage.java
@@ -64,9 +64,7 @@ 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);
}
@@ -74,12 +72,48 @@ public void appendToDocument (Document doc, Element parent)
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);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.