How to access classes.dex application for Android?

When the action starts, the classes.dex file is loaded by the system and starts executing the instructions. I need read-only access to the .dex class of the same application in which the current activity is running.

After searching for a watch on the network, I could only conclude that the Android Security system does not allow access to the application sandbox.

However, to complete my task, I need read-only access to the classes.dex file.

Does anyone have an understanding of this?

Thanks in advance!

+3
source share
2 answers

Depends on what you are trying to do, but you can access DexFile:

String sourceDir = context.getApplicationInfo().sourceDir;
DexFile dexFile = new DexFile(sourceDir);

http://developer.android.com/reference/dalvik/system/DexFile.html, , .

+4

InputStream "classes.dex" :

  • apk .
  • "classes.dex" apk JarFile.
  • .

:

        // Get the path to the apk container.
        String apkPath = getApplicationInfo().sourceDir;
        JarFile containerJar = null;

        try {

            // Open the apk container as a jar..
            containerJar = new JarFile(apkPath);

            // Look for the "classes.dex" entry inside the container.
            ZipEntry ze = containerJar.getEntry("classes.dex");

            // If this entry is present in the jar container 
            if (ze != null) {

                 // Get an Input Stream for the "classes.dex" entry
                 InputStream in = containerJar.getInputStream(ze);

                 // Perform read operations on the stream like in.read();
                 // Notice that you reach this part of the code
                 // only if the InputStream was properly created;
                 // otherwise an IOException is raised
            }   

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (containerJar != null)
                try {
                    containerJar.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }

, !

+2

All Articles