@Override protected Class<?> findClass(String className) throws ClassNotFoundException { Class<?> clazz = dexFile.loadClass(className, this); if (clazz == null && (className.startsWith("com.dodola.rocoofix") || className.startsWith("com.lody.legend") || className.startsWith("com.alipay.euler.andfix") )) { return Class.forName(className); } if (clazz == null) { throw new ClassNotFoundException(className); } return clazz; } };
String entry = entrys.nextElement(); clazz = dexFile.loadClass(entry, patchClassLoader); if (clazz != null) { fixClass(clazz, classLoader);
DexFile dexFile = DexFile.loadDex(jar.getAbsolutePath(), File.createTempFile("opt", "dex", context.getCacheDir()).getPath(), 0); .... Class<?> currClass = dexFile.loadClass(className, context.getClassLoader());
private Object loadClass(String packageName, String className){ Object plugin = null; try { PackageManager packageManager = getPackageManager(); ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName, 0); DexFile df = new DexFile(appInfo.sourceDir); ClassLoader cl = getClassLoader(); Class classToInvestigate = df.loadClass(className, cl); plugin = classToInvestigate.newInstance(); } catch (Exception e) { System.out.println("EXCEPTION"); } finally{ return plugin; } }
final File dexClasses = new File("/sdcard/dexcontainer.zip"); DexFile dexFile = DexFile.loadDex(dexClasses.getAbsolutePath(), getFilesDir().getAbsolutePath() + "/outputdexcontainer.dex", 0); Enumeration<String> classFileNames = dexFile.entries(); while (classFileNames.hasMoreElements()) { String className = classFileNames.nextElement(); dexFile.loadClass(className, classLoader); }
/** * {@inheritDoc} */ public Class<?> loadClass(dalvik.system.DexFile dexFile, ClassLoader classLoader, TypeDescription typeDescription) { return dexFile.loadClass(typeDescription.getName(), classLoader); } }
Class loadClass(String className, ClassLoader loader) { dalvik.system.DexFile dexFile = getDexFileFor(className); return dexFile == null ? null : dexFile.loadClass(className, loader); }
DexFile df = new DexFile(new File("/data/app/my_downloaded_lib.apk")); ClassLoader cl = getClassLoader(); Class clazz = df.loadClass("com/my/lib/MyClass", cl);
/*** * 每个插件里也可能有多个dex文件,挨个的查找dex文件 */ @Override protected Class<?> findClass(String name) throws ClassNotFoundException { ensureInit(); Class clazz; int length = mFiles.length; for (int i = 0; i < length; i++) { if (mDexs[i] != null) { String slashName = name.replace('.', '/'); clazz = mDexs[i].loadClass(slashName, mChild); if (clazz != null) { return clazz; } } } throw new ClassNotFoundException(name + " in loader " + this); }
/*** * 每个插件里也可能有多个dex文件,挨个的查找dex文件 */ @Override protected Class<?> findClass(String name) throws ClassNotFoundException { ensureInit(); Class clazz; int length = mFiles.length; for (int i = 0; i < length; i++) { if (mDexs[i] != null) { String slashName = name.replace('.', '/'); clazz = mDexs[i].loadClass(slashName, this); if (clazz != null) { return clazz; } } } throw new ClassNotFoundException(name + " in loader " + this); }
Class<?> entryClass = dex.loadClass(entry, classLoader); if (entryClass != null && entryClass.getAnnotation(theAnnotation) != null) { Log.d(TAG, "Found: " + entryClass.getName());
Class<?> entryClass = dex.loadClass(entry, classLoader); if (entryClass != null && entryClass.getSuperclass() == theClass) { Log.d(TAG, "Found: " + entryClass.getName());
Class<?> entryClass = dex.loadClass(entry, classLoader); if (entryClass != null) { Foo annotation = entryClass.getAnnotation(Foo.class);
dalvik.system.DexFile file = mock(dalvik.system.DexFile.class, withSettings().stubOnly()); given(file.loadClass(anyString(), eq(loader))).willReturn(MyClass.class); return file; }));