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

15 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...

Sell MMORPG Gold And Money to us to get real money!
Dear player,
OGDEAL is buying mmorpg virtual currency. We will offer high price to buy your game gold. Hot games: sell WOW gold, sell warhammer gold, sell eve online isk: www.eve-online-isk.com , sell silkroad gold, sell maple story mesos, sell lotro gold, sell lotro europe gold, sell aoc gold, sell Lineage 2 adena, sell EverQuest 2 platinum, sell FFXI gil, sell SWG credits, sell gaia gold, sell 2moons dil, sell cabal online alz, sell kalonline geons to : www.ogdeal.com .
Any questions please Contact our site’s live support chat or MSN: ogdeal@hotmail.com Thanks !

Unknown said...

sell wow goldsell wow gold to ustrade wow goldsell wow gold to ussell your wow gold
sell world warcraft goldsell maplestory mesossell maple story mesossell eve isk
sell eve online isk
sell isk
sell maplestory mesos
sell maple story mesos
sell mesos
sell silkroad gold
sell sro gold
Sell Final Fantasy XI Gil
sell ffxi gil
sell gaia gold
sell gaia online gold
sell lotro gold
sell lotro europe gold
sell lord of the rings online gold
Sell Lineage 2 Adena
Sell Age Of Conan gold
sell aoc gold
Sell EverQuest 2 platinum
Sell EQ2 platinum
sell GW gold
sell swg credits
sell warhammer gold
sell warhammer online gold

sell wow goldsell maple story mesossell wow gold us server
sell wow gols eu serversell maplestory mesossell guild war goldSell EverQuest 2 PlatinumSell ffxi gilSell eve online iskSell aoc goldSell aoc goldSell silkroad goldsell lineage2 Adenasell anarchy Creditssell warhammer goldsell lotro goldsell lotro gold eusell perfect world goldsell gaia goldrunescaperunescape goldbuy runescape goldrunescape moneyrs goldrunescape powerlevelingrunescape itemeve online
eve Isk
buy eve online isk
silkroad gold
buy silkroad goldsilkroad online
Anarchy Online Credits
Anarchy OnlineWarhammer GoldWarhammer OnlineFFXI GilGaia Goldperfect worldperfect world goldguild wars goldaoc goldlineage2 adenaeq2 platswg credit2moons dillotro goldeve online iskeve iskbuy eve iskbuy eve online iskcheap eve iskcheap eve online iskrunescape goldbuy runescape goldrunescape moneybuy runescape moneyrunescape goldrunescape powerlevelingrunescape moneybuy runescape moneybuying runescape moneybuying runescape goldbuying runescape moneyrunescape powerlevelingmaplestory mesosmaple story mesosbuy maplestory mesosbuy maple story mesosbuy ms mesosms mesoswow goldbuy wow goldworld of warcraft goldbuy world of warcraft goldbuying wow goldwow gold for sale

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