Wednesday, March 5, 2008

Tool to read Android binary XML files

I have successfully reverse engineered a good portion of the Android binary XML file format that is found inside of Android package files (.apk). With this tool, you can explore the XML layout, drawable, and animation files used in the applications distributed with the SDK (phone, browser, contacts, etc). My primary motivation for doing this was to simply observe some of the common practices and get a sense for what Google is doing internally that isn't necessarily available through their API demos and samples. Below you can find two links to download either the stand-alone convertor or the collected output as run over every APK file found in the phone's /system directory:

Download: axml2xml.pl
Download: android-xmldump.tar.gz

Please note that this tool was a very quick hack and some of the XML files I found failed to parse. Not many, and the only ones I found were raw XML documents (not Android resources) so I didn't bother to explore any further incompatibilities. If you find any resources that fail to parse or have any insight into the format, feel free to leave a comment and I will investigate when I have time.

EDIT 2012-08-22: Android's come a long way since this post.  It's now possible to use the aapt tool to read the contents of XML documents (and a whole lot more) of APK files.  For example:

android dump xmltree foo.apk AndroidManifest.xml

13 comments:

IntelliBitz Technologies said...

Fantastic! Looks interesting.. am downloading now. Thanks for sharing.

Selmi said...

works for me, but in my project i get strange runtime errors for which i can't find reason... error says: Runtime Exception: Binary XML file line #xxx, you must supply a layout_width attribute.

unfortunately it says that error on line 121 on xml which in text form has 70 lines.

so maybe you can add some mode when output xml would be formatted such way that it would have content on same line numbers as binary xml so i will be able to see what is exactly there?

dain said...

just wanted to say thanks, this dump is a life-saver :)

J said...

Josh, can you put a note on how to run the script on a layout xml file? I don't know Perl. =(

Unknown said...

As any other UNIX tool, it accepts either a file for input on the command-line as the first argument, or fed through stdin, so:

./axml2xml.pl foo.xml > foo.xml.txt

J said...

Thank you Josh. Your tool enabled me to learn how the animation xml files work (xml files within android.jar).

Very cool.

Unknown said...

For everyone: I've created similar tool in Java: AXMLPrinter. It is part of Android4ME project. Tool and its source is available on downloads tab.

For Josh: thank you for string table insight, though your assumption about how tags are encoded was not quite correct.

Amir said...

For Josh: Thanks for posting the Perl script. However (start n00b mode here), I can't run it - I get this error:

Can't locate loadable object for module Unicode::String in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at ./axml2xml.pl line 24
Compilation failed in require at ./axml2xml.pl line 24.

Any idea? I'm using Ubuntu 8.10.
Thanks,
Amir

Amir said...

Sorry about previous post - my bad - I have not installed the package properly. Now that I did, I get a different error:

Out of memory during array extend at /home/amir/bin/axml2xml.pl line 314, <> chunk 1.

J said...

I could run this script on Windows with ActivePerl with no problem but when I run on Mac OS X with ActivePerl, I got

Out of memory during array extend at axml2xml.pl line 314, <> chunk 1.

Any idea?

Amir Alagic said...

Hi

I am getting error message:

Out of memory during array extend at axml2xml.pl line 314, <> chunk 1

On Windows XP and ActivePerl. Any idea how to use your software on XP?

Thanks!

Unknown said...

Thanks, it's a lifesaver! Although most of apps have public source, I'm currently working on something that I'd like to look somewhat like google talk, and this isn't open source. Your tool makes it a lot easier, being able to look at the layouts... thanks a million!

Android app development said...

I am so happy to read your blog logic.This is one of the suitable post.Pretty post.
Android app developers