From 3a7c404a3a2cb6489178cb415c5c4a217a35dba0 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Thu, 18 Oct 2012 20:32:59 +0900 Subject: [PATCH] Implement more precise obfuscation name detection. This fixes the issue that names like R.id or Manifest.permission were regarded as obfuscated. --- JavaPackage.java | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/JavaPackage.java b/JavaPackage.java index 0e52724..5852264 100644 --- a/JavaPackage.java +++ b/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); } }