From c0993ab538a5a1ea817fa256d0446fb2bd553d00 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Sun, 10 Jun 2018 09:08:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=205.0=E4=BB=A5=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E6=89=8B=E6=9C=BA=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=88=B0=E4=BB=A3=E7=90=86=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../arialyy/aria/core/common/ProxyHelper.java | 3 - .../com/arialyy/aria/util/CommonUtil.java | 59 +++++++++++-------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java b/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java index b4ca1814..c5e59eb4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java @@ -50,9 +50,6 @@ public class ProxyHelper { List classes = CommonUtil.getClassName(AriaManager.APP, "com.arialyy.aria.ProxyClassCounter"); for (String className : classes) { - if (!className.startsWith("com.arialyy.aria.ProxyClassCounter")) { - continue; - } count(className); } } diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index 47446a22..8337a134 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -40,7 +40,6 @@ import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.orm.DbEntity; import dalvik.system.DexFile; -import dalvik.system.PathClassLoader; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; @@ -80,42 +79,50 @@ public class CommonUtil { */ public static List getClassName(Context context, String className) { List classNameList = new ArrayList<>(); - try { - String pPath = context.getPackageCodePath(); - File dir = new File(pPath).getParentFile(); - //PathClassLoader classLoader = (PathClassLoader) context.getClassLoader(); + String pPath = context.getPackageCodePath(); + File dir = new File(pPath).getParentFile(); + String[] paths = dir.list(); + if (paths == null) { + classNameList.addAll(getPkgClassName(pPath, className)); + } else { String dPath = dir.getPath(); for (String path : dir.list()) { String fPath = dPath + "/" + path; - Log.d(TAG, fPath); if (!fPath.endsWith(".apk")) { continue; } - DexFile df = new DexFile(fPath);//通过DexFile查找当前的APK中可执行文件 - Enumeration enumeration = df.entries();//获取df中的元素 这里包含了所有可执行的类名 该类名包含了包名+类名的方式 - while (enumeration.hasMoreElements()) { - String _className = enumeration.nextElement(); - if (!_className.contains(className)) { - continue; - } - //Class clazz = classLoader.loadClass(_className); // 处理4.4手机无法获取到类的问题 - //String cn = clazz.getName(); - //if (clazz.getName().contains(className)) {//在当前所有可执行的类里面查找包含有该包名的所有类 - // classNameList.add(_className); - //} - if (_className.contains(className)){ - classNameList.add(_className); - } + classNameList.addAll(getPkgClassName(fPath, className)); + } + } + return classNameList; + } + + /** + * 获取指定包名下的所有类 + * + * @param path dex路径 + * @param filterClass 需要过滤的类 + */ + public static List getPkgClassName(String path, String filterClass) { + List list = new ArrayList<>(); + try { + + DexFile df = new DexFile(path);//通过DexFile查找当前的APK中可执行文件 + Enumeration enumeration = df.entries();//获取df中的元素 这里包含了所有可执行的类名 该类名包含了包名+类名的方式 + while (enumeration.hasMoreElements()) { + String _className = enumeration.nextElement(); + if (!_className.contains(filterClass)) { + continue; + } + if (_className.contains(filterClass)) { + list.add(_className); } - df.close(); } + df.close(); } catch (IOException e) { e.printStackTrace(); } - //catch (ClassNotFoundException e) { - // e.printStackTrace(); - //} - return classNameList; + return list; } /**