use of dalvik.system.DexClassLoader in project xposed_module_loader by WindySha.
the class XposedModuleLoader method loadModule.
public static boolean loadModule(final String moduleApkPath, String moduleOdexDir, String moduleLibPath, final ApplicationInfo currentApplicationInfo, ClassLoader appClassLoader) {
XLog.i(TAG, "Loading modules from " + moduleApkPath);
if (!new File(moduleApkPath).exists()) {
Log.e(TAG, moduleApkPath + " does not exist");
return false;
}
// use system classloader to load asset to avoid the app has file assets/xposed_init
ClassLoader assetLoader = new DexClassLoader(moduleApkPath, moduleOdexDir, moduleLibPath, ClassLoader.getSystemClassLoader());
InputStream is = assetLoader.getResourceAsStream("assets/xposed_init");
if (is == null) {
Log.i(TAG, "assets/xposed_init not found in the APK");
return false;
}
ClassLoader mcl = new DexClassLoader(moduleApkPath, moduleOdexDir, moduleLibPath, appClassLoader);
BufferedReader moduleClassesReader = new BufferedReader(new InputStreamReader(is));
try {
String moduleClassName;
while ((moduleClassName = moduleClassesReader.readLine()) != null) {
moduleClassName = moduleClassName.trim();
if (moduleClassName.isEmpty() || moduleClassName.startsWith("#"))
continue;
try {
XLog.i(TAG, " Loading class " + moduleClassName);
Class<?> moduleClass = mcl.loadClass(moduleClassName);
if (!XposedHelper.isIXposedMod(moduleClass)) {
Log.i(TAG, " This class doesn't implement any sub-interface of IXposedMod, skipping it");
continue;
} else if (IXposedHookInitPackageResources.class.isAssignableFrom(moduleClass)) {
Log.i(TAG, " This class requires resource-related hooks (which are disabled), skipping it.");
continue;
}
final Object moduleInstance = moduleClass.newInstance();
if (moduleInstance instanceof IXposedHookZygoteInit) {
XposedHelper.callInitZygote(moduleApkPath, moduleInstance);
}
if (moduleInstance instanceof IXposedHookLoadPackage) {
// hookLoadPackage(new IXposedHookLoadPackage.Wrapper((IXposedHookLoadPackage) moduleInstance));
IXposedHookLoadPackage.Wrapper wrapper = new IXposedHookLoadPackage.Wrapper((IXposedHookLoadPackage) moduleInstance);
XposedBridge.CopyOnWriteSortedSet<XC_LoadPackage> xc_loadPackageCopyOnWriteSortedSet = new XposedBridge.CopyOnWriteSortedSet<>();
xc_loadPackageCopyOnWriteSortedSet.add(wrapper);
XC_LoadPackage.LoadPackageParam lpparam = new XC_LoadPackage.LoadPackageParam(xc_loadPackageCopyOnWriteSortedSet);
lpparam.packageName = currentApplicationInfo.packageName;
lpparam.processName = getCurrentProcessName(currentApplicationInfo);
;
lpparam.classLoader = appClassLoader;
lpparam.appInfo = currentApplicationInfo;
lpparam.isFirstApplication = true;
XC_LoadPackage.callAll(lpparam);
}
if (moduleInstance instanceof IXposedHookInitPackageResources) {
// hookInitPackageResources(new IXposedHookInitPackageResources.Wrapper((IXposedHookInitPackageResources) moduleInstance));
// TODO: Support Resource hook
}
} catch (Throwable t) {
Log.e(TAG, " error ", t);
}
}
} catch (IOException e) {
Log.e(TAG, " error ", e);
} finally {
try {
is.close();
} catch (IOException ignored) {
}
}
return true;
}
Aggregations