Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tufanbarisyildirim committed May 13, 2014
2 parents 3836884 + 1a30529 commit 4899765
Show file tree
Hide file tree
Showing 9 changed files with 583 additions and 3 deletions.
11 changes: 11 additions & 0 deletions examples/ApkResource.php
@@ -0,0 +1,11 @@
<?php

include 'autoload.php';
$apk = new \ApkParser\Parser('EBHS.apk');
$resourceId = $apk->getManifest()->getApplication()->getIcon();
$resources = $apk->getResources($resourceId);

header('Content-type: text/html');
foreach ($resources as $resource) {
echo '<img src="data:image/png;base64,', base64_encode(stream_get_contents($apk->getStream($resource))), '" />';
}
22 changes: 22 additions & 0 deletions lib/ApkParser/ApplicationXmlElement.php
@@ -0,0 +1,22 @@
<?php

namespace ApkParser;

class ApplicationXmlElement {
/**
* @var \SimpleXMLElement
*/
private $xml;

function __construct(\SimpleXMLElement $xml) {
$this->xml = $xml;
}

public function getIcon() {
return (string) $this->xml['icon'];
}

public function getLabel() {
return (string) $this->xml['label'];
}
}
10 changes: 9 additions & 1 deletion lib/ApkParser/Archive.php
Expand Up @@ -52,13 +52,21 @@ public function getFromName($name,$length = NULL,$flags = NULL)

/**
* Returns an ApkStream which contains AndroidManifest.xml
* @return ApkStream
* @return Stream
*/
public function getManifestStream()
{
return new Stream($this->getStream('AndroidManifest.xml'));
}

/**
* @return SeekableStream
*/
public function getResourcesStream()
{
return new SeekableStream($this->getStream('resources.arsc'));
}

/**
* Apk file path.
* @return string
Expand Down
8 changes: 8 additions & 0 deletions lib/ApkParser/Manifest.php
Expand Up @@ -79,6 +79,14 @@ public function getMinSdkLevel()
return hexdec($usesSdk['@attributes']['minSdkVersion']);
}

/**
* @return ApplicationXmlElement
*/
public function getApplication()
{
return new ApplicationXmlElement($this->getXmlObject()->{'application'}[0]);
}

private function getAttribute($attributeName)
{
if($this->attrs === NULL)
Expand Down
17 changes: 15 additions & 2 deletions lib/ApkParser/Parser.php
Expand Up @@ -14,16 +14,19 @@
*
* @property $apk \ApkParser\Archive
* @property $manifest \ApkParser\Manifest
* @property $resources \ApkParser\ResourcesParser
*/
class Parser
{
private $apk;
private $manifest;
private $resources;

public function __construct($apkFile)
{
$this->apk = new \ApkParser\Archive($apkFile);
$this->manifest = new \ApkParser\Manifest(new \ApkParser\XmlParser($this->apk->getManifestStream()));
$this->apk = new Archive($apkFile);
$this->manifest = new Manifest(new XmlParser($this->apk->getManifestStream()));
$this->resources = new ResourcesParser($this->apk->getResourcesStream());
}

/**
Expand All @@ -49,6 +52,16 @@ public function getApkArchive()
return $this->apk;
}

public function getResources($key)
{
return $this->resources->getResources($key);
}

public function getStream($name)
{
return $this->apk->getStream($name);
}

/**
* Extract apk content directly
*
Expand Down

0 comments on commit 4899765

Please sign in to comment.