Thursday, March 8, 2012

Android APK Extractor

I have been working on Android since last couple of years and its really amazing to watch how SDK takes care of few brilliant stuff, like XML based resource mapping, Delvik class generator (.dex or .odex file). So, thought lets explore internals of APK file structured and create a APK parser. Somehow any Hex Dump fascinates me enough to explore its real meaning, crazy? this is how it is :-)
I did google and found few solutions which require Android SDK AAPT (Android Asset Packaging Tool) to decode APK resource. So, I thought to create an alternate parser (independent of Android SDK) which developer community can use to extract content of APK.
 Android APK is a zip file, any ZIP parser/program can parse and extract its content. But this is the easy part, the tricky part is to convert resource files stored inside the APK (i.e. Manifest, Layouts, String.xml etc.) to plain text and convert Dex/ODex file to readable JAR. To speedup the run time processing of these resource files, AAPT encodes XMLs to Binary format. This binary format is not WBXML, it has its own structure and it took me a while to understand the same.

To hide all these complexity of parsing Android binary XML structure, I have created a simple Parser interface, which you can use in any kind of project- an Web Service which can extract uploaded APK file and show its content or an APK analyzer. 

There are few known limitations and I'm continuously working on the same, so you'll be getting updates pretty soon. Please download  APK Extractor and share your comments.