當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。