Search in sources :

Example 31 with DexClassLoader

use of dalvik.system.DexClassLoader in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DimmableIZatIconPreference method load.

private static void load(Context context) {
    if (mLoader == null) {
        try {
            if (mXtProxyClz == null || mNotifierClz == null) {
                mLoader = new DexClassLoader("/system/framework/izat.xt.srv.jar", context.getFilesDir().getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
                mXtProxyClz = Class.forName("com.qti.izat.XTProxy", true, mLoader);
                mNotifierClz = Class.forName("com.qti.izat.XTProxy$Notifier", true, mLoader);
                mIzatPackage = (String) mXtProxyClz.getField("IZAT_XT_PACKAGE").get(null);
                mGetXtProxyMethod = mXtProxyClz.getMethod("getXTProxy", Context.class, mNotifierClz);
                mGetConsentMethod = mXtProxyClz.getMethod("getUserConsent");
                mShowIzatMethod = mXtProxyClz.getMethod("showIzat", Context.class, String.class);
            }
        } catch (NoSuchMethodException | NullPointerException | SecurityException | NoSuchFieldException | LinkageError | IllegalAccessException | ClassNotFoundException e) {
            mXtProxyClz = null;
            mNotifierClz = null;
            mIzatPackage = null;
            mGetXtProxyMethod = null;
            mGetConsentMethod = null;
            mShowIzatMethod = null;
            e.printStackTrace();
        }
    }
}
Also used : Context(android.content.Context) LinkageError(java.lang.LinkageError) NullPointerException(java.lang.NullPointerException) DexClassLoader(dalvik.system.DexClassLoader) SecurityException(java.lang.SecurityException) NoSuchFieldException(java.lang.NoSuchFieldException) ClassNotFoundException(java.lang.ClassNotFoundException) NoSuchMethodException(java.lang.NoSuchMethodException) IllegalAccessException(java.lang.IllegalAccessException)

Example 32 with DexClassLoader

use of dalvik.system.DexClassLoader in project dynamic-load-apk by singwhatiwanna.

the class DLPluginManager method preparePluginEnv.

/**
 * prepare plugin runtime env, has DexClassLoader, Resources, and so on.
 *
 * @param packageInfo
 * @param dexPath
 * @return
 */
private DLPluginPackage preparePluginEnv(PackageInfo packageInfo, String dexPath) {
    DLPluginPackage pluginPackage = mPackagesHolder.get(packageInfo.packageName);
    if (pluginPackage != null) {
        return pluginPackage;
    }
    DexClassLoader dexClassLoader = createDexClassLoader(dexPath);
    AssetManager assetManager = createAssetManager(dexPath);
    Resources resources = createResources(assetManager);
    // create pluginPackage
    pluginPackage = new DLPluginPackage(dexClassLoader, resources, packageInfo);
    mPackagesHolder.put(packageInfo.packageName, pluginPackage);
    return pluginPackage;
}
Also used : AssetManager(android.content.res.AssetManager) DexClassLoader(dalvik.system.DexClassLoader) Resources(android.content.res.Resources)

Example 33 with DexClassLoader

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

the class HotFix method injectAboveEqualApiLevel14.

/**
 * 大于 API 14 的插桩策略
 *
 * @param context context
 * @param str dex 的路径
 * @param str2 插件 dex 中要修复的类 name
 * @throws ClassNotFoundException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
private static void injectAboveEqualApiLevel14(Context context, String str, String str2) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    PathClassLoader pathClassLoader = (PathClassLoader) context.getClassLoader();
    Object a = combineArray(getDexElements(getPathList(pathClassLoader)), getDexElements(getPathList(new DexClassLoader(str, context.getDir("dex", 0).getAbsolutePath(), str, context.getClassLoader()))));
    Object a2 = getPathList(pathClassLoader);
    setField(a2, a2.getClass(), "dexElements", a);
    pathClassLoader.loadClass(str2);
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) DexClassLoader(dalvik.system.DexClassLoader)

Example 34 with DexClassLoader

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

the class HotFix method injectBelowApiLevel14.

/**
 * 小于 API 14 的插桩策略
 *
 * @param context context
 * @param str 插件 dex 的路径
 * @param str2 插件 dex 中要修复的类 name
 * @throws ClassNotFoundException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
@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)

Example 35 with DexClassLoader

use of dalvik.system.DexClassLoader in project My-MVP by REBOOTERS.

the class FixDexUtils method doDexInject.

private static void doDexInject(Context appContext, HashSet<File> loadedDex) {
    // data/data/包名/files/optimize_dex(这个必须是自己程序下的目录)
    String optimizeDir = appContext.getFilesDir().getAbsolutePath() + File.separator + OPTIMIZE_DEX_DIR;
    File fopt = new File(optimizeDir);
    if (!fopt.exists()) {
        fopt.mkdirs();
    }
    try {
        // 1.加载应用程序的dex
        PathClassLoader pathLoader = (PathClassLoader) appContext.getClassLoader();
        for (File dex : loadedDex) {
            // 2.加载指定的修复的dex文件
            DexClassLoader dexLoader = new DexClassLoader(// 修复好的dex(补丁)所在目录
            dex.getAbsolutePath(), // 存放dex的解压目录(用于jar、zip、apk格式的补丁)
            fopt.getAbsolutePath(), // 加载dex时需要的库
            null, // 父类加载器
            pathLoader);
            // 3.合并
            Object dexPathList = getPathList(dexLoader);
            Object pathPathList = getPathList(pathLoader);
            Object leftDexElements = getDexElements(dexPathList);
            Object rightDexElements = getDexElements(pathPathList);
            // 合并完成
            Object dexElements = combineArray(leftDexElements, rightDexElements);
            // 重写给PathList里面的Element[] dexElements;赋值
            Object pathList = getPathList(pathLoader);
            setField(pathList, pathList.getClass(), "dexElements", dexElements);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) DexClassLoader(dalvik.system.DexClassLoader) File(java.io.File)

Aggregations

DexClassLoader (dalvik.system.DexClassLoader)51 File (java.io.File)27 PathClassLoader (dalvik.system.PathClassLoader)13 DexFile (dalvik.system.DexFile)7 IOException (java.io.IOException)7 FileOutputStream (java.io.FileOutputStream)5 InputStream (java.io.InputStream)5 Field (java.lang.reflect.Field)5 ZipFile (java.util.zip.ZipFile)5 TargetApi (android.annotation.TargetApi)3 Intent (android.content.Intent)3 Resources (android.content.res.Resources)3 RemoteException (android.os.RemoteException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Context (android.content.Context)2 ContextWrapper (android.content.ContextWrapper)2 AssetManager (android.content.res.AssetManager)2 Handler (android.os.Handler)2 TextView (android.widget.TextView)2