public Class<?> findClass(String name) throws ClassNotFoundException { return originClassLoader.loadClass(name); } else if (name != null && name.startsWith("com.tencent.tinker.loader.") && !name.equals(SystemClassLoaderAdder.CHECK_DEX_CLASS)) { return originClassLoader.loadClass(name); } else if (name != null && name.startsWith("org.apache.http.")) { return originClassLoader.loadClass(name); return originClassLoader.loadClass(name);
public static Class<?> service(Context context, String packageName, String className) { PathClassLoader classLoader = classLoaderFor(context, packageName); try { return classLoader.loadClass(className); } catch (Exception e) { throw new RuntimeException(e); } } }
// Before the secondary dex file can be processed by the DexClassLoader, // it has to be first copied from asset resource to a storage location. File dexInternalStoragePath = new File(getDir("dex", Context.MODE_PRIVATE), SECONDARY_DEX_NAME); try (BufferedInputStream bis = new BufferedInputStream(getAssets().open(SECONDARY_DEX_NAME)); OutputStream dexWriter = new BufferedOutputStream(new FileOutputStream(dexInternalStoragePath))) { byte[] buf = new byte[BUF_SIZE]; int len; while((len = bis.read(buf, 0, BUF_SIZE)) > 0) { dexWriter.write(buf, 0, len); } } catch (IOException e) { throw new RuntimeException(e); } try { PathClassLoader loader = new PathClassLoader(dexInternalStoragePath.getAbsolutePath(), getClassLoader()); Class<?> toasterClass = loader.loadClass("my.package.ToasterImpl"); Toaster toaster = (Toaster) toasterClass.newInstance(); toaster.show(this, "Success!"); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); }
public static Map<String, String> buildConfigFields(Context context, String packageName, @Nullable String className) { className = className == null ? packageName + ".BuildConfig" : className; PathClassLoader classLoader = classLoaderFor(context, packageName); try { Class<?> clazz = classLoader.loadClass(className); Field[] fields = clazz.getDeclaredFields(); Map<String, String> values = new LinkedHashMap<>(); for (Field field : fields) { if (Modifier.isStatic(field.getModifiers())) { values.put(field.getName(), String.valueOf(field.get(null))); } } return values; } catch (Exception e) { throw new RuntimeException(e); } }
public static void hook(Class clazz, XC_LoadPackage.LoadPackageParam lpparam) throws Exception { String packageName = clazz.getName().replace("."+clazz.getSimpleName(),""); File apkFile = getApkFile(packageName); if (!apkFile.exists()) { Log.e("error", "apk file not found"); return; } filterNotify(lpparam); PathClassLoader classLoader = new PathClassLoader(apkFile.getAbsolutePath(), lpparam.getClass().getClassLoader()); XposedHelpers.callMethod(classLoader.loadClass(clazz.getName()).newInstance(), "dispatch",lpparam); }
Class resCls = pcl.loadClass(packageName + ".R");
public List<Class<?>> scanForClasses(Location location, ClassFilter predicate) { try { String pkg = location.getPath().replace("/", "."); List<Class<?>> classes = new ArrayList<Class<?>>(); DexFile dex = new DexFile(context.getApplicationInfo().sourceDir); Enumeration<String> entries = dex.entries(); while (entries.hasMoreElements()) { String className = entries.nextElement(); if (className.startsWith(pkg)) { Class<?> clazz = classLoader.loadClass(className); if (predicate.isMatch(clazz)) { classes.add(clazz); LOG.trace("... found class: {}", className); } } } return classes; } catch (IOException e) { throw new ClassPathScanException(e); } catch (ClassNotFoundException e) { throw new ClassPathScanException(e); } } }
Class<?> aClass = classLoader.loadClass(className);//tested on 魅蓝Note(M463C)_Android4.4.4 and Mi2s_Android5.1.1 if (isTargetClass(aClass)) { onScanResult(aClass);
Class<?> aClass = classLoader.loadClass(className);//tested on 魅蓝Note(M463C)_Android4.4.4 and Mi2s_Android5.1.1 if (isTargetClass(aClass)) { onScanResult(aClass);