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


Java DexClassLoader类代码示例

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


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

示例1: 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

示例2: getDexClassLoader

import dalvik.system.DexClassLoader; //导入依赖的package包/类
public static DexClassLoader getDexClassLoader( Context context ){
    File cacheFile = FileUtils.getCacheDir(context.getApplicationContext());
    String internalPath = cacheFile.getAbsolutePath() + File.separator + "dynamic_dex.jar";
    File desFile = new File(internalPath);
    try {
        if (!desFile.exists()) {
            desFile.createNewFile();
            FileUtils.copyFiles( context , "dynamic_dex.jar", desFile);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    //下面开始加载dex class
    DexClassLoader dexClassLoader = new DexClassLoader(internalPath, cacheFile.getAbsolutePath(), null,context.getClassLoader() );

    return dexClassLoader ;
}
 
开发者ID:zyj1609wz,项目名称:Dynamic,代码行数:19,代码来源:FileUtils.java

示例3: loadLibrary

import dalvik.system.DexClassLoader; //导入依赖的package包/类
public void loadLibrary(String jarpath, Context context) {
    this.context = context;

    File jarfile = new File(jarpath);
    if(!jarfile.exists())
        throw new IllegalArgumentException("Could not find library: " + jarpath);


    this.jarpath = jarpath;

    File optimizedLibrarypath = context.getDir("dex", 0);

    File cachedDex = new File(optimizedLibrarypath.getPath() + "/" + jarpath.replace("jar", "dex"));
    Log.d(TAG, "Checking for cached version in " + optimizedLibrarypath.getAbsolutePath());

    File files[] = optimizedLibrarypath.listFiles();
    for (int i = 0;i < files.length; i++) {
        Log.d(TAG, "File: " + files[i].getName());

        if (files[i].getName().equals(jarfile.getName().replace("jar", "dex"))) {
            Log.d(TAG, "A cached " + files[i].getName() + " exists in " + optimizedLibrarypath.getAbsolutePath() + ". Removing it");
            files[i].delete();
        }
    }

    dexClassLoader = new DexClassLoader(jarpath, optimizedLibrarypath.getAbsolutePath(),
            null, context.getClassLoader());

}
 
开发者ID:charslab,项目名称:Android-Hotpatch,代码行数:30,代码来源:Hotpatch.java

示例4: createClassLoader

import dalvik.system.DexClassLoader; //导入依赖的package包/类
public ClassLoader createClassLoader() throws TGResourceException {
	Context context = this.activity.getApplicationContext();
	
	String optimizedDirectory = context.getDir("dex", Context.MODE_PRIVATE).getAbsolutePath();
	
	List<String> fileNames = this.unpackPlugins(optimizedDirectory);
	if(!fileNames.isEmpty()) {
		return new DexClassLoader(this.createPath(fileNames), optimizedDirectory, this.createLibraryPath(), context.getClassLoader());
	}
	return null;
}
 
开发者ID:axlecho,项目名称:tuxguitar,代码行数:12,代码来源:TGResourceLoaderImpl.java

示例5: injectDexElements

import dalvik.system.DexClassLoader; //导入依赖的package包/类
/**
 * 合并注入
 *
 * @param context
 * @param patchFilePath 补丁所在文件夹(尽量是SD卡的路径, 否则会打开文件失败)
 * @throws Exception
 */
public static void injectDexElements(Context context, String patchFilePath) throws Exception {
    ClassLoader pathClassLoader = context.getClassLoader();

    /**dex, 优化后的路径, 必须在要App data目录下, 否则会没有权限*/
    File oDexFile = new File(context.getDir("odex", Context.MODE_PRIVATE).getAbsolutePath());
    /**dex 补丁文件路径(文件夹)*/
    File patchFile = new File(patchFilePath);

    if (!patchFile.exists()) {
        patchFile.mkdirs();
    }

    // 合并成一个数组
    Object applicationDexElement = getDexElementByClassLoader(pathClassLoader);

    for (File dexFile : patchFile.listFiles()) {
        ClassLoader classLoader = new DexClassLoader(dexFile.getAbsolutePath(),// dexPath
                oDexFile.getAbsolutePath(),// optimizedDirectory
                null,
                pathClassLoader
        );
        // 获取这个classLoader中的Element
        Object classElement = getDexElementByClassLoader(classLoader);
        //Log.e("TAG", classElement.toString());
        applicationDexElement = combineArray(classElement, applicationDexElement);
    }

    // 注入到pathClassLoader中
    injectDexElements(pathClassLoader, applicationDexElement);
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:38,代码来源:Fix.java

示例6: 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

示例7: DexLoader

import dalvik.system.DexClassLoader; //导入依赖的package包/类
public DexLoader(Context var1, String[] var2, String var3, String var4) {
    Object var5 = var1.getClassLoader();
    String var6 = var1.getApplicationInfo().nativeLibraryDir;
    if(!TextUtils.isEmpty(var4)) {
        var6 = var6 + File.pathSeparator + var4;
    }

    for(int var7 = 0; var7 < var2.length; ++var7) {
        var5 = this.mClassLoader = new DexClassLoader(var2[var7], var3, var6, (ClassLoader)var5);
    }

}
 
开发者ID:LightSun,项目名称:android-util2,代码行数:13,代码来源:DexLoader.java

示例8: allMethods

import dalvik.system.DexClassLoader; //导入依赖的package包/类
/***
     * hack all defined methods
     **/
    private static void allMethods() throws HackAssertionException {
        ActivityThread_currentActivityThread = ActivityThread.method(
                "currentActivityThread");
//        ActivityThread_currentProcessName = ActivityThread.method(
//                "currentProcessName");
        AssetManager_addAssetPath = AssetManager.method("addAssetPath",
                String.class);
        Application_attach = Application.method("attach", Context.class);
        ClassLoader_findLibrary = ClassLoader.method("findLibrary",
                String.class);
        if (LexFile != null && LexFile.getmClass() != null) {
            LexFile_loadLex = LexFile.method("loadLex", String.class,
                    Integer.TYPE);
            LexFile_loadClass = LexFile.method("loadClass", String.class,
                    ClassLoader.class);
            LexFile_close = LexFile.method("close");
            DexClassLoader_findClass = DexClassLoader.method("findClass",
                    String.class);
        }
        PackageParser$Component_getComponentName = PackageParser$Component.method("getComponentName", new Class[0]);
    }
 
开发者ID:bunnyblue,项目名称:ACDD,代码行数:25,代码来源:ACDDHacks.java

示例9: 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

示例10: 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

示例11: installInitPlugins

import dalvik.system.DexClassLoader; //导入依赖的package包/类
/**
 * 安装初始的内置插件
 */
private static void installInitPlugins() {
    HashMap<String, PluginManifest> installedList = getInstalledPlugin();
    HashMap<String, Integer> defaultList = getDefaultPlugin();
    for (String key : defaultList.keySet()) {
        int installVersion = -1;
        int defaultVersion = defaultList.get(key);

        if (installedList.containsKey(key)) {
            installVersion = installedList.get(key).getVersion();
        }

        ZeusPlugin plugin = getPlugin(key);
        if (defaultVersion > installVersion) {
            boolean ret = plugin.installAssetPlugin();
            //提前将dex文件优化为odex或者opt文件
            if (ret) {
                try {
                    new DexClassLoader(PluginUtil.getAPKPath(key), PluginUtil.getDexCacheParentDirectPath(key), null, mBaseClassLoader.getParent());
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
 
开发者ID:iReaderAndroid,项目名称:ZeusPlugin,代码行数:29,代码来源:PluginManager.java

示例12: loadDexClasses

import dalvik.system.DexClassLoader; //导入依赖的package包/类
private void loadDexClasses() {
    cl = new DexClassLoader(getDexInternalStoragePath().getAbsolutePath(),
            getOptimizedDexOutputPath().getAbsolutePath(),
            null,
            mContext.getClassLoader());

    initialized = true;

    Handler handler = new Handler(mContext.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            mDexLoadListener.onLoadSuccess();
        }
    });
}
 
开发者ID:aphexyuri,项目名称:dexter,代码行数:17,代码来源:Dexter.java

示例13: getDex

import dalvik.system.DexClassLoader; //导入依赖的package包/类
public static DexClassLoader getDex(Context apps) {
	ApplicationInfo info = apps.getApplicationInfo();
	String dexPath=info.sourceDir;
	String dexOutputDir=info.dataDir;
	String libPath=info.nativeLibraryDir;
	DexClassLoader dl= new DexClassLoader(dexPath, dexOutputDir, 
			libPath, apps.getClass().getClassLoader());
	try {
		Enumeration<URL> gaga = dl.getResources("com.example.mylib_test");
		System.out.println(1);
	} catch (IOException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	try {
		DexFile df = new DexFile(dexOutputDir);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	return dl;
}
 
开发者ID:luhaoaimama1,项目名称:zone-sdk,代码行数:24,代码来源:DexUtils.java

示例14: 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

示例15: 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


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