jaredrummler / APKParser

APK parser for Android
Other
637 stars 107 forks source link

Request: allow to parse only needed things from the APK #6

Closed AndroidDeveloperLB closed 8 years ago

AndroidDeveloperLB commented 8 years ago

For example, if all I want to get from the APK is the intent-filters, if you remove the code of ApkParser.parseResourceTable() , it will save a lot of memory and time for parsing the APKs.

For example, to demonstrate the time difference, I've ran this code on each of the apps that are installed on my device:

                ApkParser apkParser = ApkParser.create(packageInfo.applicationInfo.publicSourceDir);
                try {
                    AndroidManifest androidManifest = apkParser.getAndroidManifest();
                    for (AndroidComponent component : androidManifest.getComponents()) {
                         //nothing
                    }

This took 115,992 seconds to run the code on 241 installed apps (both system and user apps), yet it took 22,864 seconds when removing the code I've written about.

This is about 5 times faster.

It might even be possible to avoid calling other pieces of code, if all I want to get is the intent filters.

AndroidDeveloperLB commented 8 years ago

Another thing I did to improve the speed, is to use SparseArray instead of HashMap, inside "ResourceLoader" class, and did some cleaning using Lint.

Now the parsing took only 22,113 seconds. Not much faster.

jaredrummler commented 8 years ago

PR are welcome.

AndroidDeveloperLB commented 8 years ago

@jaredrummler Removing the code as I did means it won't work for other operations you used there. This will ruin the code.

However, the moving to SparseArray is safe, so here for the minor stuff: https://github.com/jaredrummler/APKParser/pull/8