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