Search in sources :

Example 21 with PathClassLoader

use of dalvik.system.PathClassLoader in project AndroidLife by CaMnter.

the class HotFix method injectInAliyunOs.

/**
 * 阿里云 OS 上的 插桩策略
 *
 * @param context context
 * @param patchDexFile 插件 dex 的地址
 * @param patchClassName 插件 dex 中要修复的类 name
 * @throws ClassNotFoundException
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws InstantiationException
 * @throws NoSuchFieldException
 */
private static void injectInAliyunOs(Context context, String patchDexFile, String patchClassName) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
    PathClassLoader obj = (PathClassLoader) context.getClassLoader();
    String replaceAll = new File(patchDexFile).getName().replaceAll("\\.[a-zA-Z0-9]+", ".lex");
    Class cls = Class.forName("dalvik.system.LexClassLoader");
    Object newInstance = cls.getConstructor(new Class[] { String.class, String.class, String.class, ClassLoader.class }).newInstance(new Object[] { context.getDir("dex", 0).getAbsolutePath() + File.separator + replaceAll, context.getDir("dex", 0).getAbsolutePath(), patchDexFile, obj });
    cls.getMethod("loadClass", new Class[] { String.class }).invoke(newInstance, new Object[] { patchClassName });
    setField(obj, PathClassLoader.class, "mPaths", appendArray(getField(obj, PathClassLoader.class, "mPaths"), getField(newInstance, cls, "mRawDexPath")));
    setField(obj, PathClassLoader.class, "mFiles", combineArray(getField(obj, PathClassLoader.class, "mFiles"), getField(newInstance, cls, "mFiles")));
    setField(obj, PathClassLoader.class, "mZips", combineArray(getField(obj, PathClassLoader.class, "mZips"), getField(newInstance, cls, "mZips")));
    setField(obj, PathClassLoader.class, "mLexs", combineArray(getField(obj, PathClassLoader.class, "mLexs"), getField(newInstance, cls, "mDexs")));
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) PathClassLoader(dalvik.system.PathClassLoader) DexClassLoader(dalvik.system.DexClassLoader) File(java.io.File)

Example 22 with PathClassLoader

use of dalvik.system.PathClassLoader in project AndroidLife by CaMnter.

the class SmartApplication method injectAboveEqualApiLevel14.

private synchronized void injectAboveEqualApiLevel14() {
    final PathClassLoader pathClassLoader = (PathClassLoader) SmartApplication.class.getClassLoader();
    try {
        // 插桩
        final Object dexElements = combineArray(getDexElements(getPathList(pathClassLoader)), getDexElements(getPathList(this.dexClassLoader)));
        final Object pathList = getPathList(pathClassLoader);
        setField(pathList, pathList.getClass(), "dexElements", dexElements);
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : PathClassLoader(dalvik.system.PathClassLoader)

Example 23 with PathClassLoader

use of dalvik.system.PathClassLoader in project Unblock163MusicClient-Xposed by bin456789.

the class HotXposed method hook.

public static void hook(Class clazz, XC_LoadPackage.LoadPackageParam lpparam) throws Exception {
    String packageName = clazz.getName().replace("." + clazz.getSimpleName(), "");
    File apkFile = getApkFile(packageName, lpparam);
    if (!apkFile.exists()) {
        Log.e("error", "apk file not found");
        return;
    }
    // filterNotify(lpparam);
    PathClassLoader classLoader = new PathClassLoader(apkFile.getAbsolutePath(), lpparam.getClass().getClassLoader());
    Class cls = classLoader.loadClass(clazz.getName());
    if (cls != null) {
        Method method = cls.getDeclaredMethod("dispatch", XC_LoadPackage.LoadPackageParam.class);
        method.setAccessible(true);
        method.invoke(cls.newInstance(), lpparam);
    }
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) Method(java.lang.reflect.Method) File(java.io.File) XC_LoadPackage(de.robv.android.xposed.callbacks.XC_LoadPackage)

Example 24 with PathClassLoader

use of dalvik.system.PathClassLoader in project HotFix by dodola.

the class HotFix method injectInAliyunOs.

private static void injectInAliyunOs(Context context, String patchDexFile, String patchClassName) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
    PathClassLoader obj = (PathClassLoader) context.getClassLoader();
    String replaceAll = new File(patchDexFile).getName().replaceAll("\\.[a-zA-Z0-9]+", ".lex");
    Class cls = Class.forName("dalvik.system.LexClassLoader");
    Object newInstance = cls.getConstructor(new Class[] { String.class, String.class, String.class, ClassLoader.class }).newInstance(new Object[] { context.getDir("dex", 0).getAbsolutePath() + File.separator + replaceAll, context.getDir("dex", 0).getAbsolutePath(), patchDexFile, obj });
    cls.getMethod("loadClass", new Class[] { String.class }).invoke(newInstance, new Object[] { patchClassName });
    setField(obj, PathClassLoader.class, "mPaths", appendArray(getField(obj, PathClassLoader.class, "mPaths"), getField(newInstance, cls, "mRawDexPath")));
    setField(obj, PathClassLoader.class, "mFiles", combineArray(getField(obj, PathClassLoader.class, "mFiles"), getField(newInstance, cls, "mFiles")));
    setField(obj, PathClassLoader.class, "mZips", combineArray(getField(obj, PathClassLoader.class, "mZips"), getField(newInstance, cls, "mZips")));
    setField(obj, PathClassLoader.class, "mLexs", combineArray(getField(obj, PathClassLoader.class, "mLexs"), getField(newInstance, cls, "mDexs")));
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) PathClassLoader(dalvik.system.PathClassLoader) DexClassLoader(dalvik.system.DexClassLoader) File(java.io.File)

Example 25 with PathClassLoader

use of dalvik.system.PathClassLoader in project HotFix by dodola.

the class HotFix method injectBelowApiLevel14.

@TargetApi(14)
private static void injectBelowApiLevel14(Context context, String str, String str2) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    PathClassLoader obj = (PathClassLoader) context.getClassLoader();
    DexClassLoader dexClassLoader = new DexClassLoader(str, context.getDir("dex", 0).getAbsolutePath(), str, context.getClassLoader());
    dexClassLoader.loadClass(str2);
    setField(obj, PathClassLoader.class, "mPaths", appendArray(getField(obj, PathClassLoader.class, "mPaths"), getField(dexClassLoader, DexClassLoader.class, "mRawDexPath")));
    setField(obj, PathClassLoader.class, "mFiles", combineArray(getField(obj, PathClassLoader.class, "mFiles"), getField(dexClassLoader, DexClassLoader.class, "mFiles")));
    setField(obj, PathClassLoader.class, "mZips", combineArray(getField(obj, PathClassLoader.class, "mZips"), getField(dexClassLoader, DexClassLoader.class, "mZips")));
    setField(obj, PathClassLoader.class, "mDexs", combineArray(getField(obj, PathClassLoader.class, "mDexs"), getField(dexClassLoader, DexClassLoader.class, "mDexs")));
    obj.loadClass(str2);
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) DexClassLoader(dalvik.system.DexClassLoader) TargetApi(android.annotation.TargetApi)

Aggregations

PathClassLoader (dalvik.system.PathClassLoader)57 File (java.io.File)14 DexClassLoader (dalvik.system.DexClassLoader)8 IOException (java.io.IOException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 TargetApi (android.annotation.TargetApi)4 Context (android.content.Context)4 RemoteException (android.os.RemoteException)4 Method (java.lang.reflect.Method)3 ZipFile (java.util.zip.ZipFile)3 ActivityManagerInternal (android.app.ActivityManagerInternal)2 INotificationManager (android.app.INotificationManager)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 Configuration (android.content.res.Configuration)2 Resources (android.content.res.Resources)2 Theme (android.content.res.Resources.Theme)2 CameraAccessException (android.hardware.camera2.CameraAccessException)2 InputManagerInternal (android.hardware.input.InputManagerInternal)2