abaydullah/php-laravel-android-apk-parser

Read basic info about an application from android .apk file

v1.0.0 2024-11-16 06:59 UTC

This package is auto-updated.

Last update: 2024-11-16 07:03:32 UTC


README

This package can extract application package files in APK format used by devices running on Android OS. It can open an APK file and extract the contained manifest file to parse it and retrieve the meta-information it contains like the application name, description, device feature access permission it requires, etc.. The class can also extract the whole files contained in the APK file to a given directory.

Requirements

PHP 8.1+

Installation

Add abaydullah/php-laravel-android-apk-parser as a require dependency in your composer.json file:

$ composer require abaydullah/php-laravel-android-apk-parser

Usage

First create a Scraper instance.

use Abaydullah\ApkParser\Parser;

include 'autoload.php';
$apk = new Parser('APK URL');

$manifest = $apk->getManifest();
$permissions = $manifest->getPermissions();

echo '<pre>';
echo "Package Name      : " . $manifest->getPackageName() . "" . PHP_EOL;
echo "Version           : " . $manifest->getVersionName() . " (" . $manifest->getVersionCode() . ")" . PHP_EOL;
echo "Min Sdk Level     : " . $manifest->getMinSdkLevel() . "" . PHP_EOL;
echo "Min Sdk Platform  : " . $manifest->getMinSdk()->platform . "" . PHP_EOL;
echo "Target Sdk Level     : " . $manifest->getTargetSdkLevel() . "" . PHP_EOL;
echo "Target Sdk Platform  : " . $manifest->getTargetSdk()->platform . "" . PHP_EOL;
echo PHP_EOL;
echo "------------- Permssions List -------------" . PHP_EOL;

// find max length to print more pretty.
$perm_keys = array_keys($permissions);
$perm_key_lengths = array_map(
    function ($perm) {
        return strlen($perm);
    },
    $perm_keys
);
$max_length = max($perm_key_lengths);

foreach ($permissions as $perm => $detail) {
    echo str_pad($perm, $max_length + 4, ' ') . "=> " . $detail['description'] . " " . PHP_EOL;
    echo str_pad(
        '',
        $max_length - 5,
        ' '
    ) . ' cost    =>  ' . ($detail['flags']['cost'] ? 'true' : 'false') . " " . PHP_EOL;
    echo str_pad(
        '',
        $max_length - 5,
        ' '
    ) . ' warning =>  ' . ($detail['flags']['warning'] ? 'true' : 'false') . " " . PHP_EOL;
    echo str_pad(
        '',
        $max_length - 5,
        ' '
    ) . ' danger  =>  ' . ($detail['flags']['danger'] ? 'true' : 'false') . " " . PHP_EOL;
}


echo PHP_EOL;
echo "------------- Activities  -------------" . PHP_EOL;
foreach ($apk->getManifest()->getApplication()->activities as $activity) {
    echo $activity->name . ($activity->isLauncher ? ' (Launcher)' : null) . PHP_EOL;
}

Testing

Tests are powered by PHPUnit. You have several options.

  • Run phpunit if PHPUnit is installed globally.
  • Install dependencies (requires Composer). Run php composer.phar --dev install or composer --dev install. Then bin/vendor/phpunit to run version installed by Composer. This ensures that you are running a version compatible with the test suite.

Thanks

This Package Modified From Here https://github.com/tufanbarisyildirim/php-apk-parser Thanks JetBrains for the free open source license

Jetbrains

License

Apk Parser is MIT licensed.