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 super.findClass(name); } catch (ClassNotFoundException e) { return originClassLoader.loadClass(name);
@Override public String findLibrary(String name) { return super.findLibrary(name); } }
dalvik.system.PathClassLoader myClassLoader = new dalvik.system.PathClassLoader("/Sdcard/MyJar.jar", ModuleLoader.class.getClassLoader());
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); }
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); } } }
dalvik.system.PathClassLoader myClassLoader = new dalvik.system.PathClassLoader(urls.get(index).toString(), ModuleLoader.class.getClassLoader()); Class<?> moduleClass = Class.forName(c, true, myClassLoader);
PathClassLoader pcl = new PathClassLoader(apkName, ClassLoader.getSystemClassLoader()); Class resCls = pcl.loadClass(packageName + ".R");
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); } }
private static PathClassLoader createClassLoader(ClassLoader parent, PackageInfo packageInfo) { if (classLoaderCache.containsKey(packageInfo.applicationInfo.sourceDir)) { return classLoaderCache.get(packageInfo.applicationInfo.sourceDir); } synchronized (XposedInit.class) { if (classLoaderCache.containsKey(packageInfo.applicationInfo.sourceDir)) { return classLoaderCache.get(packageInfo.applicationInfo.sourceDir); } // XposedBridge.log("create a new classloader for plugin with new apk path: " + packageInfo.applicationInfo.sourceDir); PathClassLoader hotClassLoader = new PathClassLoader(packageInfo.applicationInfo.sourceDir, parent); classLoaderCache.putIfAbsent(packageInfo.applicationInfo.sourceDir, hotClassLoader); return hotClassLoader; } } }
// 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); }
/** * * @param libName lib name * @param size the right size of lib * @return true for valid ; false for InValid */ static boolean checkSoIsValid(String libName, int size) { Context context = mContext; if (null == context) { return false; } try{ long start=System.currentTimeMillis(); if(WXSoInstallMgrSdk.class.getClassLoader() instanceof PathClassLoader ) { String path = ((PathClassLoader) (WXSoInstallMgrSdk.class.getClassLoader())).findLibrary(libName); File file = new File(path); if (!file.exists() || size == file.length()) { WXLogUtils.w("weex so size check path :" + path+" "+(System.currentTimeMillis() - start)); return true; } else { return false; } } }catch(Throwable e ){ WXLogUtils.e("weex so size check fail exception :"+e.getMessage()); } return true; }
private void invokeHandleHookMethod(Context context, String modulePackageName, String handleHookClass, String handleHookMethod, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable { //原来的两种方式不是很好,改用这种新的方式 File apkFile = findApkFile(context, modulePackageName); if (apkFile == null) { new RuntimeException("寻找模块apk失败").printStackTrace(); } //加载指定的hook逻辑处理类,并调用它的handleHook方法 PathClassLoader pathClassLoader = new PathClassLoader(apkFile.getAbsolutePath(), ClassLoader.getSystemClassLoader()); Class<?> cls = Class.forName(handleHookClass, true, pathClassLoader); Object instance = cls.newInstance(); Method method = cls.getDeclaredMethod(handleHookMethod, XC_LoadPackage.LoadPackageParam.class); method.invoke(instance, loadPackageParam); }
@Override public String findLibrary(String LibraryName) { String pathName = super.findLibrary(LibraryName); if (!TextUtils.isEmpty(pathName)) return pathName; if (!TextUtils.isEmpty(mNativeLibraryPath)) { String fileName = System.mapLibraryName(LibraryName); File libraryFile = new File(mNativeLibraryPath, fileName); if (libraryFile.exists()) { return libraryFile.getAbsolutePath(); } return null; } return null; } }
private void invokeHandleHookMethod( Context context, String modulePackageName, String handleHookClass, String handleHookMethod, XC_LoadPackage.LoadPackageParam loadPackageParam ) throws Throwable { // 原来的两种方式不是很好,改用这种新的方式 File apkFile = findApkFile(context, modulePackageName); if (apkFile == null) { throw new RuntimeException("Cannot find the module APK."); } // 加载指定的hook逻辑处理类,并调用它的handleHook方法 PathClassLoader pathClassLoader = new PathClassLoader(apkFile.getAbsolutePath(), ClassLoader.getSystemClassLoader()); Class<?> cls = Class.forName(handleHookClass, true, pathClassLoader); Object instance = cls.newInstance(); Method method = cls.getDeclaredMethod(handleHookMethod, Context.class, XC_LoadPackage.LoadPackageParam.class); method.invoke(instance, context, loadPackageParam); }
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); } } }
public static PathClassLoader classLoaderFor(Context context, String packageName) { String neighborLocation = Spies.location(context.getPackageManager(), packageName); return new PathClassLoader(neighborLocation, context.getClassLoader()); }
Class<?> aClass = classLoader.loadClass(className);//tested on 魅蓝Note(M463C)_Android4.4.4 and Mi2s_Android5.1.1 if (isTargetClass(aClass)) { onScanResult(aClass);
dexElementsField.setAccessible(true); Object dexElementsObject = dexElementsField.get(pathListObject); PathClassLoader newClassLoader = new PathClassLoader(apk.getPath(), null); Object newPathListObject = pathListField.get(newClassLoader); Object newDexElementsObject = dexElementsField.get(newPathListObject);
Class<?> aClass = classLoader.loadClass(className);//tested on 魅蓝Note(M463C)_Android4.4.4 and Mi2s_Android5.1.1 if (isTargetClass(aClass)) { onScanResult(aClass);