Search in sources :

Example 26 with PathClassLoader

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

the class HotFix method injectAboveEqualApiLevel14.

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 27 with PathClassLoader

use of dalvik.system.PathClassLoader in project secondary-dex-gradle by creativepsyco.

the class SecondaryDex method appendOdexesToClassPath.

/**
 * Loads Dexes
 *
 * @param cxt    Application or Activity Context
 * @param dexDir The Dex Directory: Example: {@code /data/data/com.beetalk/app_dex/}
 * @param names
 * @return
 */
private static boolean appendOdexesToClassPath(Context cxt, File dexDir, String[] names) {
    // non-existing ZIP in classpath causes an exception on ICS
    // so filter out the non-existent
    String strDexDir = dexDir.getAbsolutePath();
    ArrayList<String> zipPaths = new ArrayList<String>();
    for (int i = 0; i < names.length; i++) {
        String zipPath = strDexDir + '/' + names[i];
        File f = new File(zipPath);
        if (f.isFile()) {
            zipPaths.add(zipPath);
        }
    }
    String[] zipsOfDex = new String[zipPaths.size()];
    zipPaths.toArray(zipsOfDex);
    PathClassLoader pcl = (PathClassLoader) cxt.getClassLoader();
    // do something dangerous
    try {
        if (Build.VERSION.SDK_INT < SDK_INT_ICS) {
            FrameworkHack.appendDexListImplUnderICS(zipsOfDex, pcl, dexDir);
        } else {
            // ICS+
            boolean kitkatPlus = Build.VERSION.SDK_INT >= SDK_INT_KITKAT;
            ArrayList<File> jarFiles = strings2Files(zipsOfDex);
            FrameworkHack.appendDexListImplICS(jarFiles, pcl, dexDir, kitkatPlus);
        }
        // update theAppended if succeeded to prevent duplicated classpath entry
        for (String jarName : names) {
            theAppended.add(jarName);
        }
        Log.d(LOG_TAG, "appendOdexesToClassPath completed : " + pcl);
        Log.d(LOG_TAG, "theAppended : " + theAppended);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return true;
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) ArrayList(java.util.ArrayList) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 28 with PathClassLoader

use of dalvik.system.PathClassLoader in project freeline by alibaba.

the class FreelineCore method init.

public static void init(Application app, IDynamic dynamicImpl) {
    Log.i(TAG, "freeline start initial process...");
    sApplication = app;
    setDynamicImpl(dynamicImpl);
    // if (AppUtils.isApkDebugable(app) && AppUtils.isMainProcess(app)) {
    if (AppUtils.isApkDebugable(app)) {
        Log.i(TAG, "freeline init application");
        ActivityManager.initApplication(app);
        MonkeyPatcher.monkeyPatchApplication(app, app, sRealApplication, null);
        try {
            Object mPackageInfo = getPackageInfo(app);
            Field field = mPackageInfo.getClass().getDeclaredField("mClassLoader");
            field.setAccessible(true);
            PathClassLoader origin = (PathClassLoader) field.get(mPackageInfo);
            if (checkVersionChange()) {
                Log.i(TAG, "the apk has recover, delete cache");
                clearDynamicCache();
                clearSyncCache();
            } else {
                Log.i(TAG, "start to inject dex...");
                injectDex(origin);
                Log.i(TAG, "start to inject resources...");
                injectResources();
            }
            Log.i(TAG, "start to load hackload.dex...");
            injectHackDex(app, origin);
            Log.i(TAG, "start to inject native lib...");
            injectHackNativeLib(app, origin);
        } catch (Exception e) {
            printStackTrace(e);
        }
        Log.i(TAG, "freeline init server");
        startLongLinkServer();
    }
}
Also used : Field(java.lang.reflect.Field) PathClassLoader(dalvik.system.PathClassLoader) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 29 with PathClassLoader

use of dalvik.system.PathClassLoader in project 360-Engine-for-Android by 360.

the class VersionUtils method isHtcSenseDevice.

/**
 * Checks if we are currently on a HTC device with HTC Sense enabled.
 * This method simply looks for a class that we know of.
 * However, this flawed as it uses hard-coded Strings.
 *
 * TODO: Use a non hard-coded way to detect these devices
 * TODO: This function leaks memory.
 *       The created class and loader instances are not removed by GC.
 *       After ~200 calls we get an OutOfMemoryException.
 *       Workaround: Test just once and remember outcome.
 *
 * @param context Context needed for fetching Class Loader
 */
public static boolean isHtcSenseDevice(Context context) {
    // We already know?
    if (!sWasHtcSenseTested) {
        sWasHtcSenseTested = true;
        try {
            // No we don't. Search for HTC Contacts Application class (HTC Sense)
            PathClassLoader classLoader = new PathClassLoader(HTC_CONTACTS_APK_PATH, context.getClassLoader());
            Class.forName(KNOWN_HTC_CONTACTS_CLASS, true, classLoader);
            sIsHtcSenseDevice = true;
        } catch (Exception ex) {
            sIsHtcSenseDevice = false;
        }
    }
    return sIsHtcSenseDevice;
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 30 with PathClassLoader

use of dalvik.system.PathClassLoader in project tinker by Tencent.

the class SystemClassLoaderAdder method installApk.

public static void installApk(PathClassLoader loader, List<File> files) throws Throwable {
    if (!files.isEmpty()) {
        files = createSortedAdditionalPathEntries(files);
        ClassLoader classLoader = loader;
        ArkHot.install(classLoader, files);
        sPatchDexCount = files.size();
        ShareTinkerLog.i(TAG, "after loaded classloader: " + classLoader + ", dex size:" + sPatchDexCount);
        if (!checkDexInstall(classLoader)) {
        // reset patch dex
        // SystemClassLoaderAdder.uninstallPatchDex(classLoader);
        // throw new TinkerRuntimeException(ShareConstants.CHECK_DEX_INSTALL_FAIL);
        }
    }
}
Also used : PathClassLoader(dalvik.system.PathClassLoader)

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