APK Parser


Source link: https://github.com/jaredrummler/APKParser

APK Parser

Features

  • Retrieve basic apk metas, such as title, icon, package name, version, etc.
  • Parse and convert binary xml file to text
  • Classes from dex file
  • Get certificate metas and verify apk signature

Get apk-parser

Download the latest AAR or grab via Gradle:

compile 'com.jaredrummler:apk-parser:1.0.2'

Usage

The easiest way is to use the ApkParser class, which contains convenient methods to get AndroidManifest.xml, apk meta infos, etc. #####1. Apk meta info ApkMeta contains name(label), packageName, version, sdk, used features, etc.

PackageManager pm = getPackageManager();
 ApplicationInfo appInfo = pm.getApplicationInfo("com.facebook.katana", 0);
 ApkParser apkParser = ApkParser.create(appInfo);
 ApkMeta meta = apkParser.getApkMeta();
 String packageName = meta.packageName; long versionCode = meta.versionCode; List<UseFeature> usesFeatures = meta.usesFeatures; List<String> requestedPermissions = meta.usesPermissions;

#####2. Get binary xml and manifest xml file

ApplicationInfo appInfo = getPackageManager().getApplicationInfo("some.package.name", 0);
 ApkParser apkParser = ApkParser.create(appInfo);
 String readableAndroidManifest = apkParser.getManifestXml();
 String xml = apkParser.transBinaryXml("res/layout/activity_main.xml");

#####3. Get dex classes

ApplicationInfo appInfo = getPackageManager().getApplicationInfo("com.instagram.android", 0);
 ApkParser apkParser = ApkParser.create(appInfo);
 List<DexInfo> dexFiles = apkParser.getDexInfos();
 // if size > 1 then app is using multidex for (DexInfo dexInfo : dexFiles) {

DexClass[] dexClasses = dexInfo.classes;
DexHeader dexHeader = dexInfo.header; 
}

#####4. Get certificate and verify apk signature

ApplicationInfo appInfo = getPackageManager().getApplicationInfo("com.instagram.android", 0);
 ApkParser apkParser = ApkParser.create(appInfo);
 if (apkParser.verifyApk() == ApkParser.ApkSignStatus.SIGNED) {

System.out.println(apkParser.getCertificateMeta().signAlgorithm);
 
}

#####5. Get intent-filters from apk manifest:

ApkParser parser = ApkParser.create(getPackageManager(), "com.android.settings");
 AndroidManifest androidManifest = parser.getAndroidManifest();
 for (AndroidComponent component : androidManifest.getComponents()) {

if (!component.intentFilters.isEmpty()) {

  for (IntentFilter intentFilter : component.intentFilters) {

 // Got an intent filter for activity/service/provider/receiver.
  
}

}
 
}

#####6. Locales Apk may return different infos(title, icon, etc.) for different region and language, which is determined by Locales. If the locale is not set, the "en_US" locale( Locale.US) is used. You can set the locale like this:

ApkParser apkParser = ApkParser.create(filePath);
 apkParser.setPreferredLocale(Locale.SIMPLIFIED_CHINESE);
 ApkMeta apkMeta = apkParser.getApkMeta();

The PreferredLocale parameter work for getApkMeta, getManifestXml, and other binary xmls. Apk parser will find best match languages with locale you specified.

If locale is set to null, ApkParser will not translate resource tag, just give the resource id. For example, apk title will be '@string/app_name' instead of 'WeChat'.


APK Parser is based on CaoQianLi's apk-parser

Resources

KAM

KAM is an apk manager, backup, restore and more.

A comprehensive list of string-arrays that you may need on a daily basis when developing an Android app.

A dead simple way to to add tooltips for your Android app.

This is an alternative for android default CheckedTextView widget.

A pretty loading indicator.

FreeView allows to create a floating view that you can use and move inside your app and also when your app is in background.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes