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);
}
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;
}
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();
}
}
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;
}
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);
}
}
}
Aggregations