当前位置: 首页>>代码示例>>Java>>正文


Java DexClassLoader.loadClass方法代码示例

本文整理汇总了Java中dalvik.system.DexClassLoader.loadClass方法的典型用法代码示例。如果您正苦于以下问题:Java DexClassLoader.loadClass方法的具体用法?Java DexClassLoader.loadClass怎么用?Java DexClassLoader.loadClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dalvik.system.DexClassLoader的用法示例。


在下文中一共展示了DexClassLoader.loadClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
public boolean init(File path) {
	_path = path;

	try {
		File parentFile = path.getParentFile();
		_classLoader = new DexClassLoader(_path.getAbsolutePath(), parentFile.getAbsolutePath(), null, getClass().getClassLoader());

		_pluginPackage = new ZipFile(_path);
		ZipEntry entry = _pluginPackage.getEntry("plugin.txt");
		BufferedReader reader = new BufferedReader(new InputStreamReader(_pluginPackage.getInputStream(entry)));
		String pluginClassName = reader.readLine();
		reader.close();

		Class<?> pluginClass = _classLoader.loadClass(pluginClassName);
		_plugin = (XulPlugin) pluginClass.newInstance();
		return true;
	} catch (Throwable e) {
		e.printStackTrace();
	}
	return false;
}
 
开发者ID:starcor-company,项目名称:starcor.xul,代码行数:22,代码来源:XulPluginManager.java

示例2: injectBelowApiLevel14

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
@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);
}
 
开发者ID:devilWwj,项目名称:Android-Tech,代码行数:24,代码来源:HotFix.java

示例3: injectBelowApiLevel14

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
@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);
}
 
开发者ID:bihe0832,项目名称:SDKHoxFix,代码行数:24,代码来源:HotFix.java

示例4: useDexClassLoader2

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
public void useDexClassLoader2() {
    DexClassLoader cDexClassLoader =
            new DexClassLoader("/mnt/sdcard/Myplugdex.jar", "/data/data/com.example.icunqiu", null, this.getClass()
                    .getClassLoader());
   	Toast.makeText(getApplicationContext(), "ufiuhfu", 0).show();
    
    try {
        Class<?> class1 = cDexClassLoader.loadClass("com.plug.PlugImpl");
      
        Object interfacePlug =  class1.newInstance();
        Toast.makeText(getApplicationContext()," ret+", 0).show();
        //�ӿ��Dz���ʵ�����ģ�������������һ���ӿڵ����ñ���������ָ��һ�����ʵ������Ȼ�Ǹ���Ҫʵ�����Ǹ��ӿڵ�
    	InterfacePlug interfacePlug2=(InterfacePlug) interfacePlug;
        int ret = interfacePlug2.function_02(12, 13);
    	Toast.makeText(getApplicationContext(), ret+"", 0).show();
    } catch (Exception e) {
    }
}
 
开发者ID:tangsilian,项目名称:SecurityPage,代码行数:19,代码来源:DexclassloaderActivity.java

示例5: injectAboveEqualApiLevel14

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
private static synchronized Boolean injectAboveEqualApiLevel14(
        String dexPath, String defaultDexOptPath, String nativeLibPath, String dummyClassName) {
    Log.i(TAG, "--> injectAboveEqualApiLevel14");
    PathClassLoader pathClassLoader = (PathClassLoader) DexInjector.class.getClassLoader();
    DexClassLoader dexClassLoader = new DexClassLoader(dexPath, defaultDexOptPath, nativeLibPath, pathClassLoader);
    try {
        dexClassLoader.loadClass(dummyClassName);
        Object dexElements = combineArray(
                getDexElements(getPathList(pathClassLoader)),
                getDexElements(getPathList(dexClassLoader)));

        Object pathList = getPathList(pathClassLoader);
        setField(pathList, pathList.getClass(), "dexElements", dexElements);
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
    Log.i(TAG, "<-- injectAboveEqualApiLevel14 End.");
    return true;
}
 
开发者ID:kevinross,项目名称:android_debuggable_tool,代码行数:21,代码来源:DexInjector.java

示例6: initSnsReader

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
public void initSnsReader() {
    File outputAPKFile = new File(Config.EXT_DIR + "/wechat.apk");
    if (!outputAPKFile.exists())
        copyAPKFromAssets();

    try {

        Config.initWeChatVersion("6.3.13.64_r4488992");
        DexClassLoader cl = new DexClassLoader(
                outputAPKFile.getAbsolutePath(),
                context.getDir("outdex", 0).getAbsolutePath(),
                null,
                ClassLoader.getSystemClassLoader());

        Class SnsDetailParser = null;
        Class SnsDetail = null;
        Class SnsObject = null;
        SnsDetailParser = cl.loadClass(Config.SNS_XML_GENERATOR_CLASS);
        SnsDetail = cl.loadClass(Config.PROTOCAL_SNS_DETAIL_CLASS);
        SnsObject = cl.loadClass(Config.PROTOCAL_SNS_OBJECT_CLASS);
        snsReader = new SnsReader(SnsDetail, SnsDetailParser, SnsObject);
    } catch (Throwable e) {
        Log.e("wechatmomentstat", "exception", e);
    }
}
 
开发者ID:Chion82,项目名称:WeChatMomentStat-Android,代码行数:26,代码来源:Task.java

示例7: addEntityFromString

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
/**
 * Instanciates a serialized entity using reflection
 * @param attrs the attributes of the entity
 */
private void addEntityFromString(String[] attrs) {
	GameEntity entity = null;
	try {
		DexClassLoader classLoader = PygmyLoader.getClassLoader();
		Class<?> clazz = classLoader.loadClass(attrs[0]);
		Constructor<?> constructor = clazz.getConstructor(
				GameLevel.class, String.class, EntityType.class, Point.class);
		
		entity = (GameEntity) constructor.newInstance(
						this.level, 
						attrs[1], 
						EntityType.valueOf(attrs[2]), 
						new Point(Integer.parseInt(attrs[3]), Integer.parseInt(attrs[4])));
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	if (entity != null) {
		addGameEntity(entity);
	}
}
 
开发者ID:elyas-bhy,项目名称:pygmy,代码行数:26,代码来源:PygmyGameUniverse.java

示例8: loadEntryPoint

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
/**
    * Load the entry point method
    * @param apkPath
    * @return
    */
   @SuppressLint("NewApi")
public static Method loadEntryPoint(String apkPath) throws IOException, 
                                                              ClassNotFoundException, 
                                                              NoSuchMethodException
   {
	  if (!FileSys.fileExists(apkPath, true))
		 throw new IOException(apkPath + " is not a file or does not exist");
	  
	  deleteCachedDex(apkPath);
	   
	  String entryPointClassName = readEntryPointClass(apkPath);
	  if (entryPointClassName == null)
		  throw new IOException("Read entry point class error.");
	  
	  DexClassLoader classLoader = new DexClassLoader(apkPath, getDexCacheDir(), 
                                                      null, ApkLoader.class.getClassLoader());
	  
	  Class<?> myClass = classLoader.loadClass(entryPointClassName);
	  HashMap<Integer, Object> dummy = new HashMap<Integer, Object>();
	  Method m = myClass.getDeclaredMethod(MAINMETHODNAME, 
			                               dummy.getClass());
	  
	  return m;
   }
 
开发者ID:morristech,项目名称:LOLCode,代码行数:30,代码来源:ApkLoader.java

示例9: loadDexClass

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
/**
 * 加载dex文件中的class,并调用其中的sayHello方法
 */
private void loadDexClass() {
    //下面开始加载dex class
    DexClassLoader dexClassLoader = FileUtils.getDexClassLoader( this ) ;
    try {
        Class libClazz = dexClassLoader.loadClass("com.dynamic.lib.DynamicImpl");
        Dynamic dynamic = (Dynamic) libClazz.newInstance();
        if (dynamic != null)
            Toast.makeText(this, dynamic.sayHello() , Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:zyj1609wz,项目名称:Dynamic,代码行数:16,代码来源:MainActivity.java

示例10: useDexclassloader

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
public void useDexclassloader() throws InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException{
  /**
   *   ���ҵ�Ҫ���d��jar��
   *   jar���
   *   ���
   */
	Toast.makeText(getApplicationContext(), "111", 0).show();
	DexClassLoader dexClassLoader=new DexClassLoader("/mnt/sdcard/Myplugdex.jar", "/data/data/com.example.icunqiu", null,this.getClass()
            .getClassLoader());

	/**
	 * java�����{��jar���e��ķ���
	 */
	try {
		//�õ�jar���e��uziclass����
		Class<?> class1=dexClassLoader.loadClass("com.plug.PlugImpl");
	    //ʩ���A�@��Č���
		Object object =class1.newInstance();
		   Class[] param = new Class[2];  
	        param[0] = Integer.TYPE;  
	        param[1] = Integer.TYPE;
	        //�ҵ�Ҫ�ӑB���d�ķ������������
		Method method=class1.getMethod("function_02", param);
		int uzi=(int) method.invoke(object, 1,2);  
		Log.Log("uzi");
		Toast.makeText(getApplicationContext(), uzi+"", 0).show();
	} catch (ClassNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:tangsilian,项目名称:SecurityPage,代码行数:32,代码来源:DexclassloaderActivity.java

示例11: dxWithoutMetaInfo

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
/**
	 * @param srcFile
	 * @param outputFileName
	 * @return
	 * @throws Exception
	 */
	private static boolean dxWithoutMetaInfo(File srcFile, File outputFileName) throws Exception{
		File baseDir = PlatformManager.getService().getBaseDir();
		
		//重要:dx.dex在Starter也出现,请注意同步
		File dex = new File(baseDir, "dx.dex");//如果此包发生升级,由HCAndroidStarter负责维持升级及optDir
		if(dex.canRead() == false){
			throw new Error("dx.dex is NOT exists!");
		}
		
		String dexerMain = "com.android.dx.command.dexer.Main";

		String absolutePath = dex.getAbsolutePath();
		
		//File.pathSeparator
		File dxCacheFile = new File(baseDir, "dxCache");
		dxCacheFile.mkdirs();//因为升级SDK有可能导致这些目录被删除,所以要重建
		DexClassLoader dexFileClassLoader = new DexClassLoader(absolutePath, dxCacheFile.getAbsolutePath(), null, ActivityManager
				.getActivity().getClassLoader());
		Class cd = dexFileClassLoader.loadClass(dexerMain);
		
		Class[] paraTypes = {String[].class};
		
//		测试通过
//		String[] dexparas = {"--core-library", "--output=" + outputFileName.getAbsolutePath(), srcFile.getAbsolutePath()};
		
		String[] dexparas = {"--output=" + outputFileName.getAbsolutePath(), srcFile.getAbsolutePath()};
		Object[] paras = {dexparas};
		//--dex --output=dexed.jar hello.jar
		outputFileName.delete();
		
		ClassUtil.invokeWithExceptionOut(cd, cd, "main", paraTypes, paras, false);
		
		if(outputFileName.exists()){
			return true;
		}
		return false;
	}
 
开发者ID:javalovercn,项目名称:j2se_for_android,代码行数:44,代码来源:AndroidDX.java

示例12: loadClass

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
public static Class loadClass(String className, String baseDir, String libFileName, Activity activity){
//		final String baseDir = Environment.getExternalStorageDirectory().toString();
		final File dexLibPath = new File(ResourceUtil.getBaseDir(), baseDir + File.separator + libFileName);//"test.jar"
		
		//这个可以加载jar/apk/dex,也可以从SD卡中加载,也是本文的重点。
		DexClassLoader cl = new DexClassLoader(dexLibPath.getAbsolutePath(), baseDir, null, activity.getClassLoader());
		Class clazz = null;
		try {
		    clazz = cl.loadClass(className);
		    return clazz;
		} catch (Exception exception) {
		    exception.printStackTrace();
		}
		return null;
	}
 
开发者ID:javalovercn,项目名称:j2se_for_android,代码行数:16,代码来源:AndroidClassUtil.java

示例13: defineClass

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
public Class<?> defineClass(String className, byte[] classData) throws ClassFormatError {
    byte[] dexData = dex(className, classData);

    File tempDir = null;
    File apkFile = null;
    try {
        tempDir = File.createTempFile("bridj.", ".tmp", cacheDir).getAbsoluteFile();
        tempDir.delete();
        tempDir.mkdir();

        apkFile = File.createTempFile("dynamic.", ".apk", tempDir).getAbsoluteFile();
        apkFile.getParentFile().mkdirs();

        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(apkFile));
        out.putNextEntry(new ZipEntry("classes.dex"));
        out.write(dexData);
        out.closeEntry();
        out.close();

        // http://stackoverflow.com/questions/2903260/android-using-dexclassloader-to-load-apk-file
        //PathClassLoader classLoader = new PathClassLoader(apkFile.toString(), getClass().getClassLoader());
        DexClassLoader classLoader = new DexClassLoader(apkFile.toString(), tempDir.toString(), null, parentClassLoader);
        return classLoader.loadClass(className);
    } catch (Throwable th) {
        throw new RuntimeException("Failed with tempFile = " + apkFile + " : " + th, th);
    } finally {
        if (apkFile != null) {
            delete(apkFile);
        }

        if (tempDir != null) {
            delete(tempDir);
        }
    }

}
 
开发者ID:nativelibs4java,项目名称:BridJ,代码行数:37,代码来源:AndroidClassDefiner.java

示例14: injectBelowApiLevel14

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
/**
 * 小于 API 14 的插桩策略
 *
 * @param context context
 * @param str 插件 dex 的路径
 * @param str2 插件 dex 中要修复的类 name
 * @throws ClassNotFoundException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
@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);
}
 
开发者ID:CaMnter,项目名称:AndroidLife,代码行数:39,代码来源:HotFix.java

示例15: registerNewInstance

import dalvik.system.DexClassLoader; //导入方法依赖的package包/类
protected synchronized EventDispatcherImpl registerNewInstance(String classname, String filename)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException {
    Log.d(LOGTAG, "Attempting to instantiate " + classname + "from filename " + filename);

    // It's important to maintain the extension, either .dex, .apk, .jar.
    final String extension = getExtension(filename);
    final File dexFile = GeckoJarReader.extractStream(mApplicationContext, filename, mApplicationContext.getCacheDir(), "." + extension);
    try {
        if (dexFile == null) {
            throw new IOException("Could not find file " + filename);
        }
        final File tmpDir = mApplicationContext.getDir("dex", 0); // We'd prefer getCodeCacheDir but it's API 21+.
        final DexClassLoader loader = new DexClassLoader(dexFile.getAbsolutePath(), tmpDir.getAbsolutePath(), null, mApplicationContext.getClassLoader());
        final Class<?> c = loader.loadClass(classname);
        final Constructor<?> constructor = c.getDeclaredConstructor(Context.class, JavaAddonInterfaceV1.EventDispatcher.class);
        final String guid = Utils.generateGuid();
        final EventDispatcherImpl dispatcher = new EventDispatcherImpl(guid, filename);
        final Object instance = constructor.newInstance(mApplicationContext, dispatcher);
        mGUIDToDispatcherMap.put(guid, dispatcher);
        return dispatcher;
    } finally {
        // DexClassLoader writes an optimized version, so we can get rid of our temporary extracted version.
        if (dexFile != null) {
            dexFile.delete();
        }
    }
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:28,代码来源:JavaAddonManagerV1.java


注:本文中的dalvik.system.DexClassLoader.loadClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。