Skip to content

Commit

Permalink
Implement more precise obfuscation name detection.
Browse files Browse the repository at this point in the history
This fixes the issue that names like R.id or Manifest.permission were
regarded as obfuscated.
  • Loading branch information
Atsushi Eno committed Oct 18, 2012
1 parent 360436f commit 3a7c404
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions JavaPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.