2

Just want to mention that I am really new to PHP... So I need to extract android .apk files grab the AndroidManifest.xml and then extract package, android:versionCode and android:versionName.

I know that there are tools to get this information, but I need to do this using PHP.

Here's what I got so far:

$zip = new ZipArchive();
$filename = "BluetoothChat.apk";
$zip_file = $zip->open($filename);

if ($zip_file === TRUE){
    //print_r($zip->statName('AndroidManifest.xml'));
    $xml =  $zip->getFromName('AndroidManifest.xml');
    echo $xml;
    echo "\n";
    $zip->close();
} else {
    echo 'FAILED';
}

I can successfully unpack the apk file but cannot read the contents of the xml file itself. It's in android binary xml format.

Had anyone successfully done this? Or can point me into the right direction ? Thanks a lot!

t0x13
  • 351
  • 2
  • 10
  • 24

2 Answers2

3

There is a PHP library for extract .apk resources / xml files and also decompress the Android Binary XML files.

Php Apk Parser

0

One does not simply read an APK File. - Anonymous Android Developer

The XML files in the APK are not in the raw form, they are compressed and packed.

So you'll need to use the apktool. This thread will help

Community
  • 1
  • 1
st0le
  • 33,375
  • 8
  • 89
  • 89
  • Thanks for the reply. APK file is simply a ZIP file. APK needs to be first unpacked to get the xml file, that I understand. The thread you mentioned I have read before while doing research and I am trying to use PHP not android tools. What I really need to do is convert android binary xml file to a regular xml file. – t0x13 Feb 22 '12 at 06:49
  • If you noticed the last answer on the thread, there's a Perl script that unpacks the binary compressed format (partially)...And of course you can simply use the apk tool within the PHP application to decode the format. That was my intention. – st0le Feb 23 '12 at 04:20
  • I was trying to avoid using any tools.. but finding no other solution looks like I have no choice and will have to use the apktool :) – t0x13 Feb 24 '12 at 05:23