Search in sources :

Example 16 with DexFile

use of dalvik.system.DexFile in project Auto.js by hyb1996.

the class AndroidClassLoader method dexJar.

private DexFile dexJar() throws IOException {
    if (!classFile.exists()) {
        classFile.createNewFile();
    }
    final Main.Arguments arguments = new Main.Arguments();
    arguments.fileNames = new String[] { classFile.getPath() };
    arguments.outName = dexFile.getPath();
    arguments.jarOutput = true;
    Main.run(arguments);
    DexFile dex = DexFile.loadDex(dexFile.getPath(), odexOatFile.getPath(), 0);
    dx.add(dex);
    return dex;
}
Also used : Main(com.android.dx.command.dexer.Main) DexFile(dalvik.system.DexFile)

Example 17 with DexFile

use of dalvik.system.DexFile in project AndroidLife by CaMnter.

the class ClassUtils method getFileNameByPackageName.

public static List<String> getFileNameByPackageName(Context context, String packageName) throws PackageManager.NameNotFoundException, IOException {
    List<String> classNames = new ArrayList<>();
    for (String path : getSourcePaths(context)) {
        DexFile dexfile = null;
        try {
            if (path.endsWith(EXTRACTED_SUFFIX)) {
                // NOT use new DexFile(path), because it will throw "permission error in /data/dalvik-cache"
                dexfile = DexFile.loadDex(path, path + ".tmp", 0);
            } else {
                dexfile = new DexFile(path);
            }
            Enumeration<String> dexEntries = dexfile.entries();
            while (dexEntries.hasMoreElements()) {
                String className = dexEntries.nextElement();
                if (className.contains(packageName)) {
                    classNames.add(className);
                }
            }
        } catch (Throwable ignore) {
            Log.e("ARouter", "Scan map file in dex files made error.", ignore);
        } finally {
            if (null != dexfile) {
                try {
                    dexfile.close();
                } catch (Throwable ignore) {
                }
            }
        }
    }
    Log.d("ClassUtils", "Filter " + classNames.size() + " classes by packageName <" + packageName + ">");
    return classNames;
}
Also used : ArrayList(java.util.ArrayList) DexFile(dalvik.system.DexFile)

Example 18 with DexFile

use of dalvik.system.DexFile in project ARouter by alibaba.

the class ClassUtils method tryLoadInstantRunDexFile.

/**
 * Get instant run dex path, used to catch the branch usingApkSplits=false.
 */
private static List<String> tryLoadInstantRunDexFile(ApplicationInfo applicationInfo) {
    List<String> instantRunSourcePaths = new ArrayList<>();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && null != applicationInfo.splitSourceDirs) {
        // add the split apk, normally for InstantRun, and newest version.
        instantRunSourcePaths.addAll(Arrays.asList(applicationInfo.splitSourceDirs));
        Log.d(Consts.TAG, "Found InstantRun support");
    } else {
        try {
            // This man is reflection from Google instant run sdk, he will tell me where the dex files go.
            Class pathsByInstantRun = Class.forName("com.android.tools.fd.runtime.Paths");
            Method getDexFileDirectory = pathsByInstantRun.getMethod("getDexFileDirectory", String.class);
            String instantRunDexPath = (String) getDexFileDirectory.invoke(null, applicationInfo.packageName);
            File instantRunFilePath = new File(instantRunDexPath);
            if (instantRunFilePath.exists() && instantRunFilePath.isDirectory()) {
                File[] dexFile = instantRunFilePath.listFiles();
                for (File file : dexFile) {
                    if (null != file && file.exists() && file.isFile() && file.getName().endsWith(".dex")) {
                        instantRunSourcePaths.add(file.getAbsolutePath());
                    }
                }
                Log.d(Consts.TAG, "Found InstantRun support");
            }
        } catch (Exception e) {
            Log.e(Consts.TAG, "InstantRun support error, " + e.getMessage());
        }
    }
    return instantRunSourcePaths;
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) DexFile(dalvik.system.DexFile) File(java.io.File) IOException(java.io.IOException)

Example 19 with DexFile

use of dalvik.system.DexFile in project QuantumFlux by himanshu-soni.

the class ReflectionHelper method getAllClasses.

private static List<String> getAllClasses(Context context) throws PackageManager.NameNotFoundException, IOException {
    String packageName = ManifestHelper.getPackageName(context);
    String path = getSourcePath(context);
    List<String> classNames = new ArrayList<String>();
    DexFile dexfile = null;
    try {
        dexfile = new DexFile(path);
        Enumeration<String> dexEntries = dexfile.entries();
        while (dexEntries.hasMoreElements()) {
            String className = dexEntries.nextElement();
            if (className.startsWith(packageName))
                classNames.add(className);
        }
    } catch (NullPointerException e) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Enumeration<URL> urls = classLoader.getResources("");
        while (urls.hasMoreElements()) {
            List<String> fileNames = new ArrayList<String>();
            String classDirectoryName = urls.nextElement().getFile();
            if (classDirectoryName.contains("bin") || classDirectoryName.contains("classes")) {
                File classDirectory = new File(classDirectoryName);
                for (File filePath : classDirectory.listFiles()) {
                    populateFiles(filePath, fileNames, "");
                }
                for (String fileName : fileNames) {
                    if (fileName.startsWith(packageName))
                        classNames.add(fileName);
                }
            }
        }
    } finally {
        if (null != dexfile)
            dexfile.close();
    }
    return classNames;
}
Also used : Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) DexFile(dalvik.system.DexFile) File(java.io.File) DexFile(dalvik.system.DexFile)

Example 20 with DexFile

use of dalvik.system.DexFile in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class SystemPropertiesReflection method set.

/**
 * Set the value for the given key.
 *
 * @throws IllegalArgumentException if the key exceeds 32 characters
 *                          OR      if the value exceeds 92 characters
 */
public static void set(Context context, String key, String val) throws IllegalArgumentException {
    try {
        @SuppressWarnings("unused") DexFile df = new DexFile(new File("/system/app/Settings.apk"));
        @SuppressWarnings("unused") ClassLoader cl = context.getClassLoader();
        @SuppressWarnings("rawtypes") Class SystemProperties = Class.forName("android.os.SystemProperties");
        // Parameters Types
        @SuppressWarnings("rawtypes") Class[] paramTypes = new Class[2];
        paramTypes[0] = String.class;
        paramTypes[1] = String.class;
        Method set = SystemProperties.getMethod("set", paramTypes);
        // Parameters
        Object[] params = new Object[2];
        params[0] = key;
        params[1] = val;
        set.invoke(SystemProperties, params);
    } catch (IllegalArgumentException iae) {
        log.error(iae.getMessage(), iae);
        throw iae;
    } catch (Exception ignored) {
        log.debug(ignored.getMessage(), ignored);
    }
}
Also used : Method(java.lang.reflect.Method) DexFile(dalvik.system.DexFile) File(java.io.File) DexFile(dalvik.system.DexFile)

Aggregations

DexFile (dalvik.system.DexFile)59 File (java.io.File)32 IOException (java.io.IOException)28 ArrayList (java.util.ArrayList)17 Field (java.lang.reflect.Field)13 ZipFile (java.util.zip.ZipFile)13 Method (java.lang.reflect.Method)11 DexClassLoader (dalvik.system.DexClassLoader)9 Enumeration (java.util.Enumeration)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ApplicationInfo (android.content.pm.ApplicationInfo)3 NClassLoader (android.taobao.atlas.startup.NClassLoader)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 Application (android.app.Application)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Context (android.content.Context)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Main (com.android.dx.command.dexer.Main)1 Action (com.jia.base.annotation.Action)1