Git Product home page Git Product logo

php-apk-parser's Introduction

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.0+
PHP 7.3+ is in 2.x.x branch

Installation

  • Install composer
  • Run the following command in the folder where composer.json is: composer require tufanbarisyildirim/php-apk-parser

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.

Contributing

Fork the repo, make your changes, add your name to developers, and create a pull request with a comment that describe your changes. That's all! Thanks to all contributers

Thanks

Thanks JetBrains for the free open source license

Jetbrains

License

Apk Parser is MIT licensed.

php-apk-parser's People

Contributors

achretien avatar adriantnt avatar akki-io avatar apkdev99 avatar bigdub avatar gemorroj avatar javalaw avatar justmaku avatar jwriteclub avatar lionscribe avatar mariodantas avatar marmichalski avatar mcfedr avatar meathill avatar minakov avatar nexushoratio avatar nhzex avatar peter23 avatar phpbeginners avatar phudinsky avatar raiym avatar reasno avatar sander0542 avatar tai7sy avatar timriker avatar tufanbarisyildirim avatar tyildirim avatar ultima2876 avatar vdjagilev avatar x12a1f avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-apk-parser's Issues

Version Code not read

Hi, i've tried your great library, but in my test (with your app!) the versionCode and the minSdk is not shown.

I've modified the source code of XmlParser at line 108 with this:
if ($attrValue == null)
{
$attrValue = dechex($attrResId);
}

according to the fact that $attrResId is the attr value $attrValueSi repeated.
In your code, in some cases, the $attrValueSi was -1, but the $attrResId has the correct value.

Don't know if this is correct.
However thx for your work and sorry for my english.

Examples not working: all numbers read as versionCode and undefined offset notices

When running the example with :

$ php PrintManifestXml.php

I get the following notices. Also in the resulting XML, all numbers (versionCode, resource Ids) are replaced with the string "versionCode".

PHP Notice:  Undefined offset: 17179869219 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869218 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869217 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869216 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869219 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869218 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869217 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869216 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869219 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869218 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869217 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869216 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869219 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869218 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869217 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869216 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869219 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869218 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869217 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
PHP Notice:  Undefined offset: 17179869216 in /home/ralph/test/lib/apk-parser/lib/ApkXmlParser.php on line 159
<?xml version="1.0" encoding="UTF-8"?>
<manifest versionCode="versionCode" versionName="1.0" debuggable="true" package="com.cks.EBHS">
  <uses-sdk minSdkVersion="versionCode">
  </uses-sdk>
  <uses-permission name="android.permission.INTERNET">
  </uses-permission>
  <uses-permission name="android.permission.CAMERA">
  </uses-permission>
  <uses-permission name="android.permission.BLUETOOTH">
  </uses-permission>
  <uses-permission name="android.permission.BLUETOOTH_ADMIN">
  </uses-permission>
  <application label="versionCode" icon="versionCode">
    <activity label="versionCode" name=".EBHSMainActivity">
      <intent-filter>
        <action name="android.intent.action.MAIN">
        </action>
        <category name="android.intent.category.LAUNCHER">
        </category>
      </intent-filter>
    </activity>
    <activity name="EBHSPreferenceActivity">
    </activity>
    <activity name="ConferenceActivity">
    </activity>
  </application>
</manifest>

PHP 8.1 compatibility issue

The library (2.0.3) crashes with the following errors on PHP 8.1

PHP message: PHP Deprecated:  Return type of ApkParser\Archive::getFromName($name, $length = null, $flags = null) should either be compatible with ZipArchive::getFromName(string $name, int $len = 0, int $flags = 0): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/vendor/tufanbarisyildirim/php-apk-parser/lib/ApkParser/Archive.php on line 49
PHP message: PHP Deprecated:  Return type of ApkParser\Archive::extractTo($destination, $entries = null) should either be compatible with ZipArchive::extractTo(string $pathto, array|string|null $files = null): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/vendor/tufanbarisyildirim/php-apk-parser/lib/ApkParser/Archive.php on line 105

Adding #[\ReturnTypeWillChange] to these functions in ApkParser/Archive.php helps.

Android studio 3.0 apks

Hello I'm getting an error using apkParser since I have update to android studio 3.0 It seems that something has change in the apk compiler, maybe the encoding o something like that. The error is

ErrorException in XmlParser.php line 244:
Undefined offset: 4476

I looked the function and its trying to get a position greater of the array length
I tried with other versions of the same apk compiled with older android studio versions and it works

I make a test apk for you to test it
app-debug.apk.zip

Regards

Using script without composer ?

Is it possible to use php-apk-parser without composer?
I tried uploading the zip contents on server and ran /test/ParserTest.php but got this error:

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /test/ParserTest.php on line 14

Any way around this or is composer a must ?

Read resources by key

Support for reading resources by their key, e.g @string/app_id or @integer/screen_count

Flexible parsing

Good afternoon.

Would it be possible to get a flexible manifest parsing.

For instance

a. <manifest versionCode="0x14" versionName="1.0.20" package="XXX" versionCode="20" versionName="1.0.20" platformBuildVersionCode="23" platformBuildVersionName="6.0-2704002">

duplicate versionCode and version name but package found for instance on apkpure

b. <meta-data name="du_keys" value="{"lockscreen":[{"pid":"14395"}],"list":[],"native":[{"pid":"10569"},{"pid":"10570"}]}">

seems to be parsed okay (on apkpure) but failed at value="{" .

Fatal Error 65: attributes construct error Line: 126 Column: 40 ----------------------------------------^ Fatal Error 73: Couldn't find end of Start Tag meta-data line 126 Line: 126 Column: 40 -----------------^

Warning ApkResource.php

Hello, when opening a file ApkResource.php returns an error Warning: Invalid argument supplied for foreach() on line 9, what to do?

Can not parse if AndroidManifest.xml file was encoded?

HI!

I found an error:
PHP Fatal error: Uncaught Exception: Unrecognized tag code '0' at offset 6176 in /home/vagrant/apk/vendor/tufanbarisyildirim/php-apk-parser/lib/ApkParser/XmlParser.php:213

and when i extract the apk, I found AndroidManifest.xml was encoded

License Agreement

I'd like to use this code, is it covered by any license agreement or freely available?

Check-in software license

There doesn't appear to be any information on what license this software is released under. Please decide and check it into the repository. Thanks!

Unrecognized tag code 0x00100104

hello Tufan,
first of all great work on the ApkParser.. it's the only realy solution i found on the web, so thanks for that.

after messing with it for a while and tried several files i tried to parse the astro.apk file (the application that parse apk on android) and it recived an exception of an Unrecognized tag code 0x00100104 in line 118 in the ApkXmlParser.php file.

and on some other apps i also got 0x00100105 tag issue..

do you know what that tag is and how can i fix it ?

regards,
Gilad.

Error in construct

Under PHP Version 5.5.9-1 I get following error:

Catchable fatal error: Argument 1 passed to ApkParser\Config::__construct() must be of the type array, null given, called in [**]/lib/ApkParser/Parser.php on line 29 and defined in [**]/lib/ApkParser/Config.php on line 20

Wrong minSdkVersion and targetSdkVersion

I am trying to get Android API version limit. But it not work.

minSdkVersion alway return 0.
targetSdkVersion return Android Undefined.

how can i fix it. Thanks !


Windows x64
PHP Version 5.4.16

Warning: in_array() expects parameter 2 to be array, null given

Try to parse apk and get warning: 'Warning: in_array() expects parameter 2 to be array, null given' in Activity.php in 44 line.
foreach ($this->filters as $filter) {
if (in_array('MAIN', $filter->actions) && in_array('LAUNCHER', $filter->categories))
$this->isLauncher = true;
}

Error Getting Version Code

If I try to read version code from my APK's manifest and I dump value that function return, this is always an int(0).

Application Label(Name) and Icon not being Extracted in Some .apk files

I am using the Following Code to Extract Icon and Application Name from .apk file , but for some apk it is generating properly and for some it is not

(SHORTNAMES)
Working Apk === Good Apk
Not Working Apk == faulty APk

$resourceId = $apk->getManifest()->getApplication()->getIcon();
$resources = $apk->getResources($resourceId);

header('Content-type: text/html');
foreach ($resources as $resource) {
echo '';
}

$labelResourceId = $apk->getManifest()->getApplication()->getLabel();
echo $labelResourceId;
$appLabel = $apk->getResources($labelResourceId);
echo "
Hello Application Name is :-";
echo $appLabel[0];

I just echo $labelResourceId;
and saw that Resource Id is being Generated for those faulty apk but resources are not being extracted for those
for Label it is giving null as return

and for Icon it is giving
Error ==stream_get_contents() expects parameter 1 to be resource

the faulty apk file is MainActivity.apk
which I have already mailed you sir

Parse error with non-latin symbols in attribute values

Hello. I have hardcoded activity label in Russian:

If I trying to open it in ApkParser, I get errors:

Warning: simplexml_load_string(): Entity: line 30: parser error : invalid character in attribute value in XmlParser.php on line 184
Warning: simplexml_load_string(): <activity theme="0x1030075" label="�1=>28BL ?@8;>65=85" icon="0x7f02000b" na in XmlParser.php on line 184

Looks like XML parser works with file in plain ASCII, not UTF-8.

Url Parse

Thank you for the script, it's a great work. How can we parse url addresses in the application.

error when parsing google earth apk

Hi i have a error when i try to parse google earth apk

Fatal error: Uncaught exception 'Exception' with message 'Unrecognized tag code '100' at offset 6300' in /var/www/includes/ApkParser/XmlParser.php:189 Stack trace: #0 /var/www/includes/ApkParser/XmlParser.php(295): ApkParser\XmlParser->decompress() #1 /var/www/includes/ApkParser/XmlParser.php(310): ApkParser\XmlParser->getXmlString() #2 /var/www/includes/ApkParser/Manifest.php(152): ApkParser\XmlParser->getXmlObject('\ApkParser\Mani...') #3 /var/www/includes/ApkParser/Manifest.php(104): ApkParser\Manifest->getXmlObject() #4 /var/www/includes/ApkParser/Manifest.php(61): ApkParser\Manifest->getAttribute('package') #5 /var/www/includes/applications.class.php(66): ApkParser\Manifest->getPackageName() #6 /var/www/debug_apk.php(16): Applications->apkGetInformations('temp/98760/goog...') #7 {main} thrown in /var/www/includes/ApkParser/XmlParser.php on line 189

Could you help me please :)

Attribute name redefined for some apk

Hello,

I got an error with parsing my apk.
I did check with some of others of my apk that did work successfully, but for only one app i made, i'm getting :

Warning: simplexml_load_string(): Entity: line 63: parser error : Attribute name redefined in /home/taf-services.fr/public_html/lib/ApkParser/XmlParser.php on line 211

Warning: simplexml_load_string(): ffffff" allowBackup="0xffffffff" name="fr.ceat_electronique.taf.TAFApplication_" in /home/taf-services.fr/public_html/lib/ApkParser/XmlParser.php on line 211

Warning: simplexml_load_string(): ^ in /home/taf-services.fr/public_html/lib/ApkParser/XmlParser.php on line 211

Fatal error: Call to a member function getApplication() on boolean in /home/taf-services.fr/public_html/lib/ApkParser/Manifest.php on line 32

Does someone get an idea ?
Many thx

version code and sdk level is always int(0)

Hi,
i have been tested apk parser on windows and linux server, but both of them return int(0) as sdk level and version code.
even tough in PrintManifestXml.php there's no sdk level and etc.

** note:
it has been fixed by installing composer
Thanks

Composer not working?

Perhaps just don't understand but when I tried to use the Composer to install, the class fails to load.

I notice in the composer.json , i see this, is this correct? Should it not be ApkParser? I tried to change this but it doesn't work either for when I do, \ApkParser\Parser, the end results is ../lib/ApkParser/ApkParser/Parser.php

"autoload": {
    "psr-0": {
        "ApParser": "lib/ApkParser"
    }

Manifest versionName

in ApkManifest.php the function getVersion() should be getVersionName(). A new function sould be added to read the version from the manifest.

redundent utf8_encode in XML parser

In my case the original manifest.xml from apk is already UTF-8 encoded, and the redundant utf8_encode() yields garbled charactes. Commented out this line then everything works fine.

    /**
     * @return mixed|string
     * @throws \Exception
     */
    public function getXmlString()
    {
        if (!$this->ready) {
            $this->decompress();
        }
        //$xml = utf8_encode($this->XML); <----here is the problem
        $xml = $this->xml;
        $xml = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\x9F]/u', '', $xml);
        return $xml;
    }

Problem with version code extraction

$manifest->getVersionCode() is returning a "". Could it be a bug or maybe it's because I'm running on a vagrant precise32 server in windows 7 prem.?

function.simplexml-load-string

Hi, I have an issue and don't know how to fix it
I'm using wamp-server to run the script, but doesn't work. here is the echo of main_test.php:

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 2: parser error : Start tag expected, '<' not found in C:\wamp\www\apk\lib\ApkXmlParser.php on line 177

Warning: simplexml_load_string() [function.simplexml-load-string]: in C:\wamp\www\apk\lib\ApkXmlParser.php on line 177

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\wamp\www\apk\lib\ApkXmlParser.php on line 177

Fatal error: Call to a member function getPermissions() on a non-object in C:\wamp\www\apk\lib\ApkManifest.php on line 44

incorrenct version code

Hi,
Thanks for you useful library, but your codes don't return the correct Version code. I used SDK AAPT in terminal to get the version code, by the way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.