Skip to content

Commit

Permalink
added magic get/set methods to config.
Browse files Browse the repository at this point in the history
  • Loading branch information
tufanbarisyildirim committed Nov 25, 2015
1 parent 9b34b51 commit 520f6f8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
37 changes: 33 additions & 4 deletions lib/ApkParser/Config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
namespace ApkParser;

/**
* This file is part of the Apk Parser package.
*
Expand All @@ -9,9 +7,19 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ApkParser;
/**
* Class Config
* @package ApkParser
* @property $tmp_path string
* @property $jar_path string
* @property $manifest_only boolean
*/
class Config
{
/**
* @var array
*/
private $config;

/**
Expand All @@ -21,7 +29,8 @@ public function __construct(array $config = array())
{
$this->config = array_merge(array(
'tmp_path' => sys_get_temp_dir(),
'jar_path' => __DIR__ . '/Dex/dedexer.jar'
'jar_path' => __DIR__ . '/Dex/dedexer.jar',
'manifest_only' => false
), $config);
}

Expand All @@ -33,4 +42,24 @@ public function get($key)
{
return $this->config[$key];
}

/**
* @param $key
* @return mixed
*/
public function __get($key)
{
return $this->config[$key];
}

/**
* @param $name
* @param $value
* @return mixed
* @internal param $key
*/
public function __set($name, $value)
{
return $this->config[$name] = $value;
}
}
17 changes: 11 additions & 6 deletions lib/ApkParser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Parser
{
private $apk;
private $manifest;
/**
* @var ResourcesParser|null
*/
private $resources;
private $config;

Expand All @@ -23,13 +26,15 @@ class Parser
*/
public function __construct($apkFile, array $config = array())
{
$this->config = new Config($config);
$this->apk = new Archive($apkFile);
$this->manifest = new Manifest(new XmlParser($this->apk->getManifestStream()));
if (empty($config["manifest_only"]))

if (!$this->config->manifest_only)
$this->resources = new ResourcesParser($this->apk->getResourcesStream());
else
$this->resources = NULL;
$this->config = new Config($config);

}

/**
Expand Down Expand Up @@ -82,7 +87,7 @@ public function getClasses()
$dexStream = $this->apk->getClassesDexStream();
$apkName = $this->apk->getApkName();

$cache_folder = $this->config->get('tmp_path') . '/' . str_replace('.', '_', $apkName) . '/';
$cache_folder = $this->config->tmp_path . '/' . str_replace('.', '_', $apkName) . '/';

// No folder means no cached data.
if (!is_dir($cache_folder))
Expand All @@ -93,13 +98,13 @@ public function getClasses()

// run shell command to extract dalvik compiled codes to the cache folder.
// Template : java -jar dedexer.jar -d {destination_folder} {source_dex_file}
$command = "java -jar {$this->config->get('jar_path')} -d {$cache_folder} {$dex_file}";
$command = "java -jar {$this->config->jar_path} -d {$cache_folder} {$dex_file}";
$returns = shell_exec($command);

if (!$returns) //TODO : check if it not contains any error. $returns will always contain some output.
throw new \Exception("Couldn't decompile .dex file");

$file_list = \ApkParser\Utils::globRecursive($cache_folder . '*.ddx');
$file_list = Utils::globRecursive($cache_folder . '*.ddx');

//Make classnames more readable.
foreach ($file_list as &$file) {
Expand All @@ -111,6 +116,6 @@ public function getClasses()


return $file_list;

}
}

0 comments on commit 520f6f8

Please sign in to comment.