private void loadThunk() throws ClassNotFoundException, IllegalAccessException, InstantiationException { DexClassLoader dcl= new DexClassLoader(apkPath.getAbsolutePath(), cachePath.getAbsolutePath(), null, getClass().getClassLoader()); Class<ThingsLoader> clazz= (Class<ThingsLoader>)dcl.loadClass(classname); extImpl=clazz.newInstance(); }
String jarFile = "path/to/jarfile.jar"; DexClassLoader classLoader = new DexClassLoader( jarFile, "/tmp", null, getClass().getClassLoader()); Class<?> myClass = classLoader.loadClass("MyClass");
public class Main extends Activity { @SuppressWarnings("unchecked") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { final String libPath = Environment.getExternalStorageDirectory() + "/shlublu.jar"; final File tmpDir = getDir("dex", 0); final DexClassLoader classloader = new DexClassLoader(libPath, tmpDir.getAbsolutePath(), null, this.getClass().getClassLoader()); final Class<Object> classToLoad = (Class<Object>) classloader.loadClass("org.shlublu.android.sandbox.MyClass"); final Object myInstance = classToLoad.newInstance(); final Method doSomething = classToLoad.getMethod("doSomething"); doSomething.invoke(myInstance); } catch (Exception e) { e.printStackTrace(); } } }
getApplicationContext().getClassLoader()); requiredClass = classLoader.loadClass(fullName);
hookClass = cl.loadClass(className);
try { Log.d("robust", "PatchsInfoImpl name:" + patch.getPatchesInfoImplClassFullName()); patchsInfoClass = classLoader.loadClass(patch.getPatchesInfoImplClassFullName()); patchesInfo = (PatchesInfo) patchsInfoClass.newInstance(); Log.d("robust", "PatchsInfoImpl ok"); oldClass = classLoader.loadClass(patchedClassName.trim()); Field[] fields = oldClass.getDeclaredFields(); Log.d("robust", "oldClass :" + oldClass + " fields " + fields.length); patchClass = classLoader.loadClass(patchClassName); Object patchObject = patchClass.newInstance(); changeQuickRedirectField.setAccessible(true);
return super.loadClass(className, resolve);
for(DexClassLoader dexLoader : multiDexClassLoaderList) { try { clazz = dexLoader.loadClass(className); } catch (ClassNotFoundException e) {
DexClassLoader loader = new DexClassLoader("/sdcard/com.example.test.apk", getApplicationInfo().dataDir, null, getClassLoader()); try { loader.loadClass("com.example.test.MainActivity"); } catch (ClassNotFoundException e) { Log.e(TAG, "Could not load class"); e.printStackTrace(); }
String jarFile = "path/to/jarfile.jar"; DexClassLoader classLoader = new DexClassLoader(jarFile, "/data/data/" + context.getPackageName() + "/", null, getClass().getClassLoader()); Class<?> myClass = classLoader.loadClass("MyClass");
DexClassLoader classLoader = new DexClassLoader( "/path/to/your/apk", getFilesDir().getAbsolutePath(), null, getClass().getClassLoader()); Class<?> loadedClass = classLoader.loadClass("full.package.and.class.name");
public Class getActivityClass(Context ctx) throws PackageManager.NameNotFoundException, ClassNotFoundException { ApplicationInfo pi = ctx.getPackageManager() .getApplicationInfo("my.application", 0); String apkPath = pi.sourceDir; DexClassLoader loader = new DexClassLoader(apkPath, ctx.getFilesDir().getAbsolutePath(), null, this.getClass().getClassLoader()); return loader.loadClass("my-application.MainActivity"); }
@Override public Class<?> getClassById(String keyName) { Class<?> aClass =null; try { String string = packageInfo.applicationInfo.metaData.getString(keyName); aClass = dexClassLoader.loadClass(string); } catch (Exception e) { e.printStackTrace(); Log.i(TAG,""+e.getMessage()); } return aClass; }
final String libPath = Environment.getExternalStorageDirectory() + "/test.jar"; final File tmpDir = getDir("dex", 0); final DexClassLoader classloader = new DexClassLoader(libPath, tmpDir.getAbsolutePath(), null, this.getClass().getClassLoader()); final Class<Object> classToLoad = (Class<Object>) classloader.loadClass("com.test.android.MainActivity"); final Object myInstance = classToLoad.newInstance(); final Method doSomething = classToLoad.getMethod("doSomething"); doSomething.invoke(myInstance);
final File tmpDir = getDir("dex", 0); final String libPath = Environment.getExternalStorageDirectory() + "/test.jar"; final DexClassLoader classloader = new DexClassLoader(libPath, tmpDir.getAbsolutePath(), null, this.getClass().getClassLoader()); try { final Class<Object> classToLoad = (Class<Object>) classloader.loadClass("org.shlublu.android.sandbox.MyClass"); // CHANGED: THIS STARTS PROPERLY YOUR ACTIVITY ONCE THE CLASS LOADED final Intent intent = new Intent(this, classToLoad); startActivity(intent); } catch (ClassNotFoundException e) { // handle that Exception properly here }
File f = new File(c.getFilesDir().getPath() + "/calculmobiledex.jar"); Log.i("File", "" + f.exists()); DexClassLoader u = new DexClassLoader(f.toURI().toURL() .toString(), c.getDir("libs", c.MODE_PRIVATE) .getAbsolutePath(), null, ClassLoader.getSystemClassLoader()); Class c = u.loadClass("perimetre.calcul"); Constructor constru = c .getConstructor(int.class, int.class); Object o = constru.newInstance(2, 2); Method m = c.getMethod("resultat", int.class, int.class); m.setAccessible(true); Log.i("method = ", "" + m.invoke(o, 1, 1)); m = null;
final File optimizedDexOutputPath = getDir("outdex", Context.MODE_PRIVATE); final File dexInternalStoragePath = new File(getDir("dex", Context.MODE_PRIVATE), SECONDARY_DEX_NAME); // Initialize the class loader with the secondary dex file. DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(), optimizedDexOutputPath.getAbsolutePath(), null, getClassLoader()); try { @SuppressWarnings("unchecked") final Class<Object> obj = (Class<Object>) cl.loadClass("com.packagename.Classname"); final Constructor<Object> constr = obj.getConstructor(Activity.class, String.class, Handler.class); myInstance = constr.newInstance(this, mString, mHandler); Method doSomething; try { doSomething = v.getMethod("YOURMETHOD"); doSomething.invoke(myInstance); } }
final File tmpDir = getDir("dex", 0); final String libPath = Environment.getExternalStorageDirectory() + "/test.jar"; final DexClassLoader classloader = new DexClassLoader(libPath, tmpDir.getAbsolutePath(), null, this.getClass().getClassLoader()); try { final Class<Object> classToLoad = (Class<Object>) classloader.loadClass("org.shlublu.android.sandbox.MyClass"); // CHANGED: LOADS THE METHOD doSomething(Context). EXECUTES IT WITH this AS AN ARGUMENT final Class[] args = new Class[1]; args[0] = Context.class; final Method doSomething = classToLoad.getMethod("doSomething", args); final Object myInstance = classToLoad.newInstance(); doSomething.invoke(myInstance, this); } catch (ClassNotFoundException e) { // handle that Exception properly here }
private Class<?> loadTargetActivity(@NonNull ComponentName componentName) throws Exception { if (!mPluginInfo.isStarted()) { boolean started = mPluginInfo.start(); if (!started) { throw new Exception( String.format("start bundle %s from ActivityHostProxy fault", mPluginInfo.packageName)); } } mClassLoader = mPluginInfo.getPluginClassLoader(); if (mClassLoader == null) { throw new Exception(String.format("classloader for bundle %s is null", mPluginInfo.packageName)); } return mClassLoader.loadClass(componentName.getClassName()); }
/** * 装载被代理的Activity * * @param mLoadedApk 插件的实例对象 * @param activityName 需要被代理的Activity 类名 * @return 成功则返回插件中被代理的Activity对象 */ private Activity loadPluginActivity(PluginLoadedApk mLoadedApk, String activityName) { try { Activity mActivity = (Activity) mLoadedApk.getPluginClassLoader() .loadClass(activityName).newInstance(); return mActivity; } catch (Exception e) { ErrorUtil.throwErrorIfNeed(e); } return null; }