Diffs
File_AndroidManifest/trunk/File/AndroidManifest.class.php
@@ -1,4 +1,24 @@
<?php
+/**
+ * AndroidManifest class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
require_once 'File/AndroidManifest/ChunkHeader.class.php';
require_once 'File/AndroidManifest/StringPoolHeader.class.php';
require_once 'File/AndroidManifest/XMLHeader.class.php';
@@ -9,123 +29,124 @@
require_once 'File/AndroidManifest/XMLTreeAttributeValue.class.php';
require_once 'File/AndroidManifest/XMLTreeEndExt.class.php';
+/**
+ * AndroidManifest class
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class AndroidManifest
{
- private $chunk_header;
- private $string_pool_header;
- private $xml_header;
- private $xml_tree_node;
- private $xml_tree_namespace;
- private $xml_tree_node2;
- private $xml_tree_ext;
- private $xml_tree_attribute;
- private $xml_tree_attr_value;
+ /**
+ * parsed xml string
+ * @var string
+ * @access private
+ */
+ private $xml_string;
- private $xml_string;
+ /**
+ * constructor
+ *
+ * @param binary $binary binary string of AndroidManifest.xml
+ * @return void
+ * @access public
+ */
public function __construct($binary) {
- $output_namespace = false;
+ $this->xml_string = $this->parseManifest($binary);
+ }
- $this->chunk_header = new ChunkHeader($binary);
- $this->string_pool_header = new StringPoolHeader($binary);
- $string_pool = $this->string_pool_header->getStringPool();
+ /**
+ * parse binary string from AndroidManifest.xml and build into string
+ *
+ * @param binary $binary binary data of AndroidManifest.xml
+ * @return string a XML string of AndroidManifest.xml
+ * @access private
+ */
+ private function parseManifest($binary) {
+ $xml = null;
+ $output_ns = false;
- $offset = $this->chunk_header->getHeaderSize() + $this->string_pool_header->getSize();
+ $chunk_header = new ChunkHeader($binary);
+ $string_pool_header = new StringPoolHeader($binary);
+ $string_pool = $string_pool_header->getStringPool();
- $this->xml_header = new XMLHeader($binary, $offset);
+ $offset = $chunk_header->getHeaderSize() + $string_pool_header->getSize();
- $offset += $this->xml_header->getSize();
- $this->xml_tree_node = new XMLTreeNode($binary, $offset);
+ $xml_header = new XMLHeader($binary, $offset);
- $offset += $this->xml_tree_node->getHeaderSize();
- $this->xml_tree_namespace = new XMLTreeNamespace($binary, $offset);
-//var_dump($string_pool->getPoolString($this->xml_tree_namespace->getPrefixIndex()));
-//var_dump($string_pool->getPoolString($this->xml_tree_namespace->getUriIndex()));
- $namespaces[$string_pool->getPoolString($this->xml_tree_namespace->getUriIndex())] = $string_pool->getPoolString($this->xml_tree_namespace->getPrefixIndex());
+ $offset += $xml_header->getSize();
+ $xml_tree_node = new XMLTreeNode($binary, $offset);
- $offset += $this->xml_tree_namespace->getHeaderSize();
+ $offset += $xml_tree_node->getHeaderSize();
+ $xml_tree_ns = new XMLTreeNamespace($binary, $offset);
+ $namespaces[$string_pool->getPoolString($xml_tree_ns->getUriIndex())] = $string_pool->getPoolString($xml_tree_ns->getPrefixIndex());
+
+ $offset += $xml_tree_ns->getHeaderSize();
for (;;) {
$node = new XMLTreeNode($binary, $offset);
-//var_dump($node->getCommentIndex());
-//var_dump($node->getLineOfXML());
switch ($node->getType()) {
case XMLTreeNode::RES_XML_START_ELEMENT_TYPE:
$offset += $node->getHeaderSize();
$ext = new XMLTreeExt($binary, $offset);
-//var_dump($ext);
-//var_dump($ext->getNamespaceIndex());
-//var_dump($string_pool->getPoolString($ext->getNamespaceIndex()));
-//var_dump($string_pool->getPoolString($ext->getElementIndex()));
-//var_dump($string_pool->getPoolString($ext->getIdIndex()));
-//var_dump($string_pool->getPoolString($ext->getClassIndex()));
-//var_dump($string_pool->getPoolString($ext->getStyleIndex()));
$offset += $ext->getHeaderSize();
if ((int)$ext->getNamespaceIndex() === (int)0xFFFFFFFF) {
- $this->xml_string .=
- sprintf('<%s ', $string_pool->getPoolString($ext->getElementIndex()));
+ $xml .=
+ sprintf(
+ '<%s ',
+ $string_pool->getPoolString($ext->getElementIndex()));
} else {
- $this->xml_string .=
+ $xml .=
sprintf(
'<%s:%s ',
$string_pool->getPoolString($ext->getNamespaceIndex()),
$string_pool->getPoolString($ext->getElementIndex()));
}
- if (!$output_namespace && !is_null($string_pool->getPoolString($this->xml_tree_namespace->getPrefixIndex()))) {
- $output_namespace = true;
- $this->xml_string .=
+ if (!$output_ns && !is_null($string_pool->getPoolString($xml_tree_ns->getPrefixIndex()))) {
+ $output_ns = true;
+ $xml .=
sprintf(
'xmlns:%s="%s" ',
- $string_pool->getPoolString($this->xml_tree_namespace->getPrefixIndex()),
- $string_pool->getPoolString($this->xml_tree_namespace->getUriIndex()));
+ $string_pool->getPoolString($xml_tree_ns->getPrefixIndex()),
+ $string_pool->getPoolString($xml_tree_ns->getUriIndex()));
}
-//var_dump($string_pool->getPoolString($this->xml_tree_namespace->getPrefixIndex()));
-//var_dump($string_pool->getPoolString($this->xml_tree_namespace->getUriIndex()));
for ($i = 0; $i < $ext->getAttributeCount(); $i++) {
$attribute = new XMLTreeAttribute($binary, $offset);
-//var_dump($attribute);
-//var_dump($string_pool->getPoolString($attribute->getNamespaceIndex()));
-//var_dump($string_pool->getPoolString($attribute->getNameIndex()));
-//var_dump($attribute->getValueIndex());
-//var_dump($string_pool->getPoolString($attribute->getValueIndex()));
$offset += $attribute->getHeaderSize();
$attribute_value = new XMLTreeAttributeValue($binary, $offset);
-//var_dump($attribute_value);
$offset += $attribute_value->getHeaderSize();
$name = $string_pool->getPoolString($attribute->getNameIndex());
-//var_dump($attribute->getNamespaceIndex());
-//var_dump($this->xml_tree_namespace->getPrefixIndex());
-//var_dump($this->xml_tree_namespace->getUriIndex());
- if ($attribute->getNamespaceIndex() === $this->xml_tree_namespace->getUriIndex()) {
- $name = sprintf('%s:%s', $string_pool->getPoolString($this->xml_tree_namespace->getPrefixIndex()), $name);
+ if ($attribute->getNamespaceIndex() === $xml_tree_ns->getUriIndex()) {
+ $name = sprintf('%s:%s', $string_pool->getPoolString($xml_tree_ns->getPrefixIndex()), $name);
}
$value = null;
-//var_dump($attribute->getNamespaceIndex());
if ((int)$attribute->getValueIndex() === (int)0xFFFFFFFF) {
$value = self::formatAttribute($attribute_value->getType(), $attribute_value->getValue());
} else {
$value = $string_pool->getPoolString($attribute->getValueIndex());
}
- $this->xml_string .=
+ $xml .=
sprintf('%s="%s" ', $name, $value);
}
- $this->xml_string .= '>';
+ $xml .= '>';
break;
case XMLTreeNode::RES_XML_END_ELEMENT_TYPE:
$offset += $node->getHeaderSize();
$end_ext = new XMLTreeEndExt($binary, $offset);
-//var_dump($end_ext);
-//var_dump($string_pool->getPoolString($end_ext->getNamespaceIndex()));
-//var_dump($string_pool->getPoolString($end_ext->getNameIndex()));
-//var_dump((int)$end_ext->getNamespaceIndex() === (int)0xFFFFFFFF);
$offset += $end_ext->getHeaderSize();
if ((int)$end_ext->getNamespaceIndex() === (int)0xFFFFFFFF) {
- $this->xml_string .=
+ $xml .=
sprintf('</%s>', $string_pool->getPoolString($end_ext->getNameIndex()));
} else {
- $this->xml_string .=
+ $xml .=
sprintf(
'</%s:%s>',
$string_pool->getPoolString($end_ext->getNamespaceIndex()),
@@ -134,44 +155,26 @@
break;
case XMLTreeNode::RES_XML_END_NAMESPACE_TYPE:
$offset += $node->getHeaderSize();
- $xml_tree_namespace = new XMLTreeNamespace($binary, $offset);
- $offset += $xml_tree_namespace->getHeaderSize();
+ $end_ns = new XMLTreeNamespace($binary, $offset);
+ $offset += $end_ns->getHeaderSize();
break;
}
- if ($offset >= $this->chunk_header->getFileSize()) {
+ if ($offset >= $chunk_header->getFileSize()) {
break;
}
}
+ return $xml;
}
-/*
- public function getChunkHeader() {
- return $this->chunk_header;
- }
- public function getStringPoolHeader() {
- return $this->string_pool_header;
- }
- public function getXMLHeader() {
- return $this->xml_header;
- }
- public function getXMLTreeNode() {
- return $this->xml_tree_node;
- }
- public function getXMLTreeNamespace() {
- return $this->xml_tree_namespace;
- }
- public function getXMLTreeNode2() {
- return $this->xml_tree_node2;
- }
- public function getXMLTreeExt() {
- return $this->xml_tree_ext;
- }
- public function getXMLTreeAttribute() {
- return $this->xml_tree_attribute;
- }
- public function getXMLTreeAttributeValue() {
- return $this->xml_tree_attr_value;
- }
-*/
+
+ /**
+ * format an attribute value by its type
+ *
+ * @param integer $type an attribute value
+ * @param integer $value an attribute type
+ * @return string formatted value
+ * @access private
+ * @see http://bit.ly/AxtqRz
+ */
private function formatAttribute($type, $value) {
switch ($type) {
case XMLTreeAttributeValue::TYPE_NULL:
@@ -189,30 +192,29 @@
case XMLTreeAttributeValue::TYPE_INT_BOOLEAN:
return sprintf('%s', ($value === 0) ? 'false' : 'true');
break;
- default: // 他はとりあえず適当
+ default:
return sprintf('0x%08X', $value);
break;
}
}
+
+ /**
+ * return parsed xml
+ *
+ * @return string parsed xml
+ * @access public
+ */
+ public function getXML() {
+ return $this->xml_string;
+ }
+
+ /**
+ * return parsed xml into SimpleXMLElement
+ *
+ * @return SimpleXMLElement parsed xml into SimpleXMLElement
+ * @access public
+ */
public function getSimpleXMLElement() {
return simplexml_load_string($this->xml_string);
}
}
-if (isset($argv[0]) && __FILE__ === realpath($argv[0])) {
- if (!isset($argv[1])) {
- echo 'usage : php AndroidManifest.class.php [manifest_file]';
- exit;
- }
- $binary = file_get_contents($argv[1]);
- $xml = new AndroidManifest($binary);
-// var_dump($xml->getChunkHeader());
-// var_dump($xml->getStringPoolHeader());
-// var_dump($xml->getXMLHeader());
-// var_dump($xml->getXMLTreeNode());
-// var_dump($xml->getXMLTreeNamespace());
-// var_dump($xml->getXMLTreeNode2());
-// var_dump($xml->getXMLTreeExt());
-// var_dump($xml->getXMLTreeAttribute());
-// var_dump($xml->getXMLTreeAttributeValue());
- var_dump($xml->getSimpleXMLElement()->asXML());
-}
File_AndroidManifest/trunk/File/AndroidManifest/XMLTreeNode.class.php
@@ -1,35 +1,157 @@
<?php
+/**
+ * XMLTreeNode class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
require_once 'File/AndroidManifest/Util/BinaryUtil.class.php';
+
+/**
+ * XMLTreeNode class
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class XMLTreeNode
{
- // @see http://android.git.linaro.org/gitweb?p=platform/frameworks/base.git;a=blob;f=include/utils/ResourceTypes.h;h=10baa11a5114a4efd3ddb1d7fc4d870d8a2e8401;hb=HEAD#l179
+ /**
+ * this chunk type is NULL
+ */
const RES_NULL_TYPE = 0x0000;
+
+ /**
+ * this chunk type is string pool
+ */
const RES_STRING_POOL_TYPE = 0x0001;
+
+ /**
+ * this chunk type is resource table
+ */
const RES_TABLE_TYPE = 0x0002;
+
+ /**
+ * this chunk type is XML
+ */
const RES_XML_TYPE = 0x0003;
- // Chunk types in RES_XML_TYPE
+ /**
+ * first chunk
+ */
const RES_XML_FIRST_CHUNK_TYPE = 0x0100;
+
+ /**
+ * start namespace
+ */
const RES_XML_START_NAMESPACE_TYPE= 0x0100;
+
+ /**
+ * end namespace
+ */
const RES_XML_END_NAMESPACE_TYPE = 0x0101;
+
+ /**
+ * start element
+ */
const RES_XML_START_ELEMENT_TYPE = 0x0102;
+
+ /**
+ * end element
+ */
const RES_XML_END_ELEMENT_TYPE = 0x0103;
+
+ /**
+ * cdata
+ */
const RES_XML_CDATA_TYPE = 0x0104;
+
+ /**
+ * last chunk
+ */
const RES_XML_LAST_CHUNK_TYPE = 0x017f;
- // This contains a uint32_t array mapping strings in the string
- // pool back to resource identifiers. It is optional.
+
+ /**
+ * resource map
+ */
const RES_XML_RESOURCE_MAP_TYPE = 0x0180;
- // Chunk types in RES_TABLE_TYPE
+ /**
+ * package
+ */
const RES_TABLE_PACKAGE_TYPE = 0x0200;
+
+ /**
+ * type
+ */
const RES_TABLE_TYPE_TYPE = 0x0201;
+
+ /**
+ * type spec
+ */
const RES_TABLE_TYPE_SPEC_TYPE = 0x0202;
+ /**
+ * Type identifier for this chunk
+ * @var integer
+ * @access private
+ */
private $type;
+
+ /**
+ * Size of the chunk header
+ * @var integer
+ * @access private
+ */
private $header_size;
+
+ /**
+ * Size of the chunk header including namespace chunk
+ * @var integer
+ * @access private
+ */
private $size;
+
+ /**
+ * Line number in original source file at which this element appeared.
+ * @var integer
+ * @access private
+ */
private $lox;
+
+ /**
+ * Optional XML comment that was associated with this element; -1 if none.
+ * @var integer
+ * @access private
+ */
private $comment_no;
+
+ /**
+ * constructor
+ *
+ * @param binary $binary binary string from AndroidManifest.xml
+ * @param integer $offset starting offset for this chunk
+ * @return void
+ * @access public
+ */
public function __construct($binary, $offset) {
$this->type = BinaryUtil::unpackLE(substr($binary, $offset + 0));
$this->header_size = BinaryUtil::unpackLE(substr($binary, $offset + 2));
@@ -37,28 +159,54 @@
$this->lox = BinaryUtil::unpackLE32(substr($binary, $offset + 8));
$this->comment_no = BinaryUtil::unpackLE32(substr($binary, $offset + 12));
}
+
+ /**
+ * return type identifier for this chunk
+ *
+ * @return integer Type identifier for this chunk
+ * @access public
+ */
public function getType() {
return $this->type;
}
+
+ /**
+ * return size of the chunk header
+ *
+ * @return integer Size of the chunk header
+ * @access public
+ */
public function getHeaderSize() {
return $this->header_size;
}
+
+ /**
+ * return size of the chunk header including namespace chunk
+ *
+ * @return integer Size of the chunk header including namespace chunk
+ * @access public
+ */
public function getSize() {
return $this->size;
}
+
+ /**
+ * return line number in original source file at which this element appeared.
+ *
+ * @return integer Line number in original source file at which this element appeared.
+ * @access public
+ */
public function getLineOfXML() {
return $this->lox;
}
+
+ /**
+ * return optional XML comment that was associated with this element; -1 if none.
+ *
+ * @return integer Optional XML comment that was associated with this element; -1 if none.
+ * @access public
+ */
public function getCommentIndex() {
return $this->comment_no;
}
}
-if (isset($argv[0]) && __FILE__ === realpath($argv[0])) {
- $binary = file_get_contents('./MyApp_AndroidManifest.xml');
- $header = new XMLTreeNode($binary);
- var_dump($header->getType());
- var_dump($header->getHeaderSize());
- var_dump($header->getSize());
- var_dump($header->getLineOfXML());
- var_dump($header->getCommentIndex());
-}
File_AndroidManifest/trunk/File/AndroidManifest/XMLTreeEndExt.class.php
@@ -1,26 +1,94 @@
<?php
+/**
+ * XMLTreeEndExt class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
require_once 'File/AndroidManifest/Util/BinaryUtil.class.php';
+
+/**
+ * XMLTreeEndExt class
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class XMLTreeEndExt
{
+ /**
+ * index of the namespace of this element.
+ * @var integer
+ * @access private
+ */
private $namespace_no;
+
+ /**
+ * index of string name of this node if it is an ELEMENT; the raw
+ * character data if this is a CDATA node.
+ * @var integer
+ * @access private
+ */
private $name_no;
+
+ /**
+ * constructor
+ *
+ * @param binary $binary binary string from AndroidManifest.xml
+ * @param integer $offset starting offset for this chunk
+ * @return void
+ * @access public
+ */
public function __construct($binary, $offset) {
$this->namespace_no = BinaryUtil::unpackLE32(substr($binary, $offset + 0));
$this->name_no = BinaryUtil::unpackLE32(substr($binary, $offset + 4));
}
+
+ /**
+ * return index of the namespace of this element
+ *
+ * @return integer index of the namespace of this element
+ * @access public
+ */
public function getNamespaceIndex() {
return $this->namespace_no;
}
+
+ /**
+ * index of string name of this node
+ *
+ * @return integer index of string name of this node
+ * @access public
+ */
public function getNameIndex() {
return $this->name_no;
}
+
+ /**
+ * return this header size
+ *
+ * @return integer this header size
+ * @access public
+ */
public function getHeaderSize() {
return 8;
}
}
-if (isset($argv[0]) && __FILE__ === realpath($argv[0])) {
- $binary = file_get_contents('./MyApp_AndroidManifest.xml');
- $header = new XMLTreeEndExt($binary);
- var_dump($header->getNamespaceIndex());
- var_dump($header->getNameIndex());
-}
File_AndroidManifest/trunk/File/AndroidManifest/StringPoolHeader.class.php
@@ -1,24 +1,122 @@
<?php
+/**
+ * StringPoolHeader class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
require_once 'File/AndroidManifest/Util/BinaryUtil.class.php';
require_once 'File/AndroidManifest/StringPool.class.php';
+
+/**
+ * StringPoolHeader
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class StringPoolHeader
{
- const DATA_OFFSET = 8;
+ /**
+ * the string index is sorted by the string values (based on strcmp16()).
+ */
const SORTED_FLAG = 31; // 1<<0
+
+ /**
+ * String pool is encoded in UTF-8
+ */
const UTF8_FLAG = 323536; // 1<<8
+ /**
+ * Type identifier for this chunk
+ * @var integer
+ * @access private
+ */
private $type;
+
+ /**
+ * Size of the header
+ * @var integer
+ * @access private
+ */
private $header_size;
+
+ /**
+ * Size of the string pool
+ * @var integer
+ * @access private
+ */
private $size;
+
+ /**
+ * Number of strings in this pool
+ * @var integer
+ * @access private
+ */
private $strings_size;
+
+ /**
+ * Number of style span arrays in the pool
+ * @var integer
+ * @access private
+ */
private $styles_size;
+
+ /**
+ * Flag
+ * @var integer
+ * @access private
+ */
private $flag;
+
+ /**
+ * Index from header of the string data.
+ * @var integer
+ * @access private
+ */
private $strings_offset;
+
+ /**
+ * Index from header of the style data.
+ * @var integer
+ * @access private
+ */
private $styles_offset;
- private $strings;
- private $pool_strings;
+
+ /**
+ * StringPool object
+ * @var object
+ * @access private
+ */
private $string_pool;
- public function __construct($binary, $offset = self::DATA_OFFSET) {
+
+ /**
+ * constructor
+ *
+ * @param binary $binary binary string from AndroidManifest.xml
+ * @param integer $offset starting offset for this chunk
+ * @return void
+ * @access public
+ */
+ public function __construct($binary, $offset = 8) {
$this->type = BinaryUtil::unpackLE(substr($binary, $offset + 0));
$this->header_size = BinaryUtil::unpackLE(substr($binary, $offset + 2));
$this->size = BinaryUtil::unpackLE32(substr($binary, $offset + 4));
@@ -30,44 +128,95 @@
$this->string_pool = new StringPool($binary);
}
+
+ /**
+ * return type identifier for this chunk
+ *
+ * @return integer Type identifier for this chunk
+ * @access public
+ * @see http://bit.ly/xfjXFd
+ */
public function getType() {
return $this->type;
}
+
+ /**
+ * return size of the chunk header
+ *
+ * @return integer Size of the chunk header. always 8.
+ * @access public
+ */
public function getHeaderSize() {
return $this->size;
}
+
+ /**
+ * return size of the string pool
+ *
+ * @return integer size of the string pool
+ * @access public
+ */
public function getSize() {
return $this->size;
}
+
+ /**
+ * return number of strings in this pool
+ *
+ * @return integer number of strings in this pool
+ * @access public
+ */
public function getStringsSize() {
return $this->strings_size;
}
+
+ /**
+ * return number of style span arrays in the pool
+ *
+ * @return integer number of style span arrays in the pool
+ * @access public
+ */
public function getStyleSize() {
return $this->styles_size;
}
+
+ /**
+ * return flag
+ *
+ * @return integer flag value
+ * @access public
+ */
public function getFlag() {
return $this->flag;
}
+
+ /**
+ * return index from header of the string data
+ *
+ * @return index from header of the string data
+ * @access public
+ */
public function getStringsOffset() {
return $this->strings_offset;
}
+
+ /**
+ * return index from header of the style data
+ *
+ * @return integer index from header of the style data
+ * @access public
+ */
public function getStylesOffset() {
return $this->styles_offset;
}
+
+ /**
+ * return StringPool object
+ *
+ * @return object StringPool StringPool object
+ * @access public
+ */
public function getStringPool() {
return $this->string_pool;
}
}
-if (isset($argv[0]) && __FILE__ === realpath($argv[0])) {
- $binary = file_get_contents('./MyApp_AndroidManifest.xml');
- $header = new StringPoolHeader($binary);
- var_dump($header->getType());
- var_dump($header->getHeaderSize());
- var_dump($header->getSize());
- var_dump($header->getStringsSize());
- var_dump($header->getStyleSize());
- var_dump($header->getFlag());
- var_dump($header->getStringsOffset());
- var_dump($header->getStylesOffset());
- var_dump($header->getStringPool());
-}
File_AndroidManifest/trunk/File/AndroidManifest/XMLHeader.class.php
@@ -1,11 +1,75 @@
<?php
+/**
+ * XMLHeader class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
require_once 'File/AndroidManifest/Util/BinaryUtil.class.php';
+
+/**
+ * XMLHeader class
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class XMLHeader
{
+ /**
+ * Type identifier for this chunk
+ * @var integer
+ * @access private
+ */
private $type;
+
+ /**
+ * Size of the chunk header
+ * @var integer
+ * @access private
+ */
private $header_size;
+
+ /**
+ * Total size of this chunk
+ * @var integer
+ * @access private
+ */
private $size;
+
+ /**
+ * attribute table
+ * @var array
+ * @access private
+ */
private $attributes;
+
+ /**
+ * constructor
+ *
+ * @param binary $binary binary string from AndroidManifest.xml
+ * @param integer $offset starting offset for this chunk
+ * @return void
+ * @access public
+ */
public function __construct($binary, $offset) {
$this->type = BinaryUtil::unpackLE(substr($binary, $offset + 0));
$this->header_size = BinaryUtil::unpackLE(substr($binary, $offset + 2));
@@ -15,24 +79,44 @@
$this->attributes[] = sprintf('0x%08X', BinaryUtil::unpackLE32(substr($binary, $offset + $of, 4)));
}
}
+
+ /**
+ * return type identifier for this chunk
+ *
+ * @return integer Type identifier for this chunk
+ * @access public
+ */
public function getType() {
return $this->type;
}
+
+ /**
+ * return size of the chunk header
+ *
+ * @return integer Size of the chunk header. always 8.
+ * @access public
+ */
public function getHeaderSize() {
return $this->header_size;
}
+
+ /**
+ * return total size of this chunk
+ *
+ * @return integer total size of this chunk
+ * @access public
+ */
public function getSize() {
return $this->size;
}
+
+ /**
+ * return array of unique attributes
+ *
+ * @return array array of unique attributes
+ * @access public
+ */
public function getAttributes() {
return $this->attributes;
}
}
-if (isset($argv[0]) && __FILE__ === realpath($argv[0])) {
- $binary = file_get_contents('./MyApp_AndroidManifest.xml');
- $header = new XMLHeader($binary);
- var_dump($header->getType());
- var_dump($header->getHeaderSize());
- var_dump($header->getSize());
- var_dump($header->getAttributes());
-}
File_AndroidManifest/trunk/File/AndroidManifest/XMLTreeNamespace.class.php
@@ -1,27 +1,94 @@
<?php
+/**
+ * XMLTreeNamespace class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
require_once 'File/AndroidManifest/Util/BinaryUtil.class.php';
+
+/**
+ * XMLTreeNamespace class
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class XMLTreeNamespace
{
+
+ /**
+ * Index of the prefix of the namespace.
+ * @var string
+ * @access private
+ */
private $prefix;
+
+ /**
+ * The URI of the namespace.
+ * @var integer
+ * @access private
+ */
private $uri;
+
+ /**
+ * constructor
+ *
+ * @param binary $binary binary string from AndroidManifest.xml
+ * @param integer $offset starting offset for this chunk
+ * @return void
+ * @access public
+ */
public function __construct($binary, $offset) {
$this->prefix = BinaryUtil::unpackLE32(substr($binary, $offset + 0));
$this->uri = BinaryUtil::unpackLE32(substr($binary, $offset + 4));
}
+
+ /**
+ * return Index of the prefix of the namespace.
+ *
+ * @return string Index of the prefix of the namespace.
+ * @access public
+ */
public function getPrefixIndex() {
return $this->prefix;
}
+
+ /**
+ * return Index of the URI of the namespace.
+ *
+ * @return integer Index of the URI of the namespace.
+ * @access public
+ */
public function getUriIndex() {
return $this->uri;
}
+
+ /**
+ * return size of the chunk header
+ *
+ * @return integer Size of the chunk header. always 8.
+ * @access public
+ */
public function getHeaderSize() {
return 8;
}
}
-if (isset($argv[0]) && __FILE__ === realpath($argv[0])) {
- $binary = file_get_contents('./MyApp_AndroidManifest.xml');
- $header = new XMLTreeNamespace($binary);
- var_dump($header->getPrefixIndex());
- var_dump($header->getUriIndex());
- var_dump($header->getHeaderSize());
-}
File_AndroidManifest/trunk/File/AndroidManifest/StringPool.class.php
@@ -1,18 +1,100 @@
<?php
+/**
+ * StringPool class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
require_once 'File/AndroidManifest/Util/BinaryUtil.class.php';
+
+/**
+ * StringPool class
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class StringPool
{
- const DATA_OFFSET = 8;
+ /**
+ * the string index is sorted by the string values (based on strcmp16()).
+ */
const SORTED_FLAG = 31; // 1<<0
+
+ /**
+ * String pool is encoded in UTF-8
+ */
const UTF8_FLAG = 323536; // 1<<8
+ /**
+ * Size of the chunk
+ * @var integer
+ * @access private
+ */
private $header_size;
+
+ /**
+ * Number of strings in this pool
+ * @var integer
+ * @access private
+ */
private $strings_size;
+
+ /**
+ * Flag
+ * @var integer
+ * @access private
+ */
private $flag;
+
+ /**
+ * Index from header of the string data.
+ * @var integer
+ * @access private
+ */
private $strings_offset;
+
+ /**
+ * array of offset to unique strings
+ * @var array
+ * @access private
+ */
private $strings;
+
+ /**
+ * Raw array of unique strings
+ * @var array
+ * @access private
+ */
private $pool_strings;
- public function __construct($binary, $offset = self::DATA_OFFSET) {
+
+ /**
+ * constructor
+ *
+ * @param binary $binary binary string from AndroidManifest.xml
+ * @param integer $offset starting offset for this chunk
+ * @return void
+ * @access public
+ */
+ public function __construct($binary, $offset = 8) {
$this->header_size = BinaryUtil::unpackLE(substr($binary, $offset + 2)); // 28
$this->strings_size = BinaryUtil::unpackLE32(substr($binary, $offset + 8));
$this->flag = BinaryUtil::unpackLE32(substr($binary, $offset + 16));
@@ -24,7 +106,7 @@
$this->pool_strings = array();
foreach ($this->strings as $index => $pool_offset) {
- $offset = self::DATA_OFFSET + $this->strings_offset + $pool_offset;
+ $offset = 8 + $this->strings_offset + $pool_offset;
$size = BinaryUtil::unpackLE(substr($binary, $offset));
$this->pool_strings[$index] = null;
foreach ((array)BinaryUtil::unpackLE(substr($binary, $offset + 2, $size * 2), $size) as $char) {
@@ -32,32 +114,45 @@
}
}
}
+
+ /**
+ * return number of strings in this pool
+ *
+ * @return integer number of strings in this pool
+ * @access public
+ */
public function getStringsSize() {
return $this->strings_size;
}
+
+ /**
+ * return flag
+ *
+ * @return integer flag value
+ * @access public
+ */
public function getFlag() {
return $this->flag;
}
-// public function getStringsOffset() {
-// return $this->strings_offset;
-// }
-// public function getStrings() {
-// return $this->strings;
-// }
+
+ /**
+ * return array of unique strings
+ *
+ * @return array array of unique strings
+ * @access public
+ */
public function getPoolStrings() {
return $this->pool_strings;
}
+
+ /**
+ * return pooled string
+ *
+ * @param integer $index index of array
+ * @return array pooled string
+ * @access public
+ */
public function getPoolString($index) {
return isset($this->pool_strings[$index]) ? $this->pool_strings[$index] : null;
}
}
-if (isset($argv[0]) && __FILE__ === realpath($argv[0])) {
- $binary = file_get_contents('./MyApp_AndroidManifest.xml');
- $header = new StringPool($binary);
- var_dump($header->getStringsSize());
- var_dump($header->getFlag());
-// var_dump($header->getStringsOffset());
-// var_dump($header->getStrings());
- var_dump($header->getPoolStrings());
- var_dump($header->getPoolString(1));
-}
File_AndroidManifest/trunk/File/AndroidManifest/ChunkHeader.class.php
@@ -1,32 +1,101 @@
<?php
+/**
+ * ChunkHeader class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
require_once 'File/AndroidManifest/Util/BinaryUtil.class.php';
+
+/**
+ * ChunkHeader class
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class ChunkHeader
{
- const DATA_OFFSET = 0;
+ /**
+ * Type identifier for this chunk
+ * @var integer
+ * @access private
+ */
+ private $type;
- private $type;
+ /**
+ * Size of the chunk header
+ * @var integer
+ * @access private
+ */
private $header_size;
+
+ /**
+ * Total size of this chunk
+ * @var integer
+ * @access private
+ */
private $file_size;
+
+ /**
+ * constructor
+ *
+ * @param binary $binary binary string from AndroidManifest.xml
+ * @return void
+ * @access public
+ */
public function __construct($binary) {
- $offset = self::DATA_OFFSET;
+ $offset = 0;
$this->type = BinaryUtil::unpackLE(substr($binary, $offset + 0));
$this->header_size = BinaryUtil::unpackLE(substr($binary, $offset + 2));
$this->file_size = BinaryUtil::unpackLE32(substr($binary, $offset + 4));
}
+
+ /**
+ * return type identifier for this chunk
+ *
+ * @return integer Type identifier for this chunk
+ * @access public
+ */
public function getType() {
return $this->type;
}
+
+ /**
+ * return size of the chunk header
+ *
+ * @return integer Size of the chunk header. always 8.
+ * @access public
+ */
public function getHeaderSize() {
return $this->header_size;
}
+
+ /**
+ * return Total size of this chunk
+ *
+ * @return integer Total size of this chunk
+ * @access public
+ */
public function getFileSize() {
return $this->file_size;
}
}
-if (isset($argv[0]) && __FILE__ === realpath($argv[0])) {
- $binary = file_get_contents('./MyApp_AndroidManifest.xml');
- $header = new ChunkHeader($binary);
- var_dump($header->getType());
- var_dump($header->getHeaderSize());
- var_dump($header->getFileSize());
-}
File_AndroidManifest/trunk/File/AndroidManifest/XMLTreeAttributeValue.class.php
@@ -1,78 +1,196 @@
<?php
+/**
+ * XMLTreeAttributeValue class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
require_once 'File/AndroidManifest/Util/BinaryUtil.class.php';
+
+/**
+ * XMLTreeAttributeValue class
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class XMLTreeAttributeValue
{
- // @see http://android.git.linaro.org/gitweb?p=platform/frameworks/base.git;a=blob;f=include/utils/ResourceTypes.h;h=10baa11a5114a4efd3ddb1d7fc4d870d8a2e8401;hb=HEAD#l233
- // Contains no data.
+ /**
+ * Contains no data.
+ */
const TYPE_NULL = 0x00;
- // The 'data' holds a ResTable_ref, a reference to another resource
- // table entry.
+
+ /**
+ * The 'data' holds a ResTable_ref, a reference to another resource
+ * table entry.
+ */
const TYPE_REFERENCE = 0x01;
- // The 'data' holds an attribute resource identifier.
+
+ /**
+ * The 'data' holds an attribute resource identifier.
+ */
const TYPE_ATTRIBUTE = 0x02;
- // The 'data' holds an index into the containing resource table's
- // global value string pool.
+
+ /**
+ * The 'data' holds an index into the containing resource table's
+ * global value string pool.
+ */
const TYPE_STRING = 0x03;
- // The 'data' holds a single-precision floating point number.
+
+ /**
+ * The 'data' holds a single-precision floating point number.
+ */
const TYPE_FLOAT = 0x04;
- // The 'data' holds a complex number encoding a dimension value,
- // such as "100in".
+
+ /**
+ * The 'data' holds a complex number encoding a dimension value,
+ * such as "100in".
+ */
const TYPE_DIMENSION = 0x05;
- // The 'data' holds a complex number encoding a fraction of a
- // container.
+
+ /**
+ * The 'data' holds a complex number encoding a fraction of a
+ * container.
+ */
const TYPE_FRACTION = 0x06;
- // Beginning of integer flavors...
+ /**
+ * Beginning of integer flavors...
+ */
const TYPE_FIRST_INT = 0x10;
- // The 'data' is a raw integer value of the form n..n.
+ /**
+ * The 'data' is a raw integer value of the form n..n.
+ */
const TYPE_INT_DEC = 0x10;
- // The 'data' is a raw integer value of the form 0xn..n.
+
+ /**
+ * The 'data' is a raw integer value of the form 0xn..n.
+ */
const TYPE_INT_HEX = 0x11;
- // The 'data' is either 0 or 1, for input "false" or "true" respectively.
+
+ /**
+ * The 'data' is either 0 or 1, for input "false" or "true" respectively.
+ */
const TYPE_INT_BOOLEAN = 0x12;
- // Beginning of color integer flavors...
+ /**
+ * Beginning of color integer flavors...
+ */
const TYPE_FIRST_COLOR_INT = 0x1c;
- // The 'data' is a raw integer value of the form #aarrggbb.
+ /**
+ * The 'data' is a raw integer value of the form #aarrggbb.
+ */
const TYPE_INT_COLOR_ARGB8 = 0x1c;
- // The 'data' is a raw integer value of the form #rrggbb.
+
+ /**
+ * The 'data' is a raw integer value of the form #rrggbb.
+ */
const TYPE_INT_COLOR_RGB8 = 0x1d;
- // The 'data' is a raw integer value of the form #argb.
+
+ /**
+ * The 'data' is a raw integer value of the form #argb.
+ */
const TYPE_INT_COLOR_ARGB4 = 0x1e;
- // The 'data' is a raw integer value of the form #rgb.
+
+ /**
+ * The 'data' is a raw integer value of the form #rgb.
+ */
const TYPE_INT_COLOR_RGB4 = 0x1f;
- // ...end of integer flavors.
+ /**
+ * ...end of integer flavors.
+ */
const TYPE_LAST_COLOR_INT = 0x1f;
- // ...end of integer flavors.
+ /**
+ * ...end of integer flavors.
+ */
const TYPE_LAST_INT = 0x1;
+ /**
+ * Number of bytes in this structure
+ * @var integer
+ * @access private
+ */
private $size;
+
+ /**
+ * Type of the data value
+ * @var integer
+ * @access private
+ */
private $type;
+
+ /**
+ * The data for this item
+ * @var integer
+ * @access private
+ */
private $value;
+
+ /**
+ * constructor
+ *
+ * @param binary $binary binary string from AndroidManifest.xml
+ * @param integer $offset starting offset for this chunk
+ * @return void
+ * @access public
+ */
public function __construct($binary, $offset) {
$this->size = BinaryUtil::unpackLE(substr($binary, $offset + 0));
$padding = BinaryUtil::unpack('C', substr($binary, $offset + 2, 1));
$this->type = BinaryUtil::unpack('C', substr($binary, $offset + 3, 1));
$this->value = BinaryUtil::unpackLE32(substr($binary, $offset + 4));
}
+
+ /**
+ * return number of bytes in this structure
+ *
+ * @return integer Number of bytes in this structure
+ * @access public
+ */
public function getHeaderSize() {
return $this->size;
}
+
+ /**
+ * return type of the data value
+ *
+ * @return integer Type of the data value.
+ * @access public
+ */
public function getType() {
return $this->type;
}
+
+ /**
+ * return the data for this item
+ *
+ * @return integer The data for this item
+ * @access public
+ */
public function getValue() {
return $this->value;
}
}
-if (isset($argv[0]) && __FILE__ === realpath($argv[0])) {
- $binary = file_get_contents('./MyApp_AndroidManifest.xml');
- $header = new XMLTreeAttributeValue($binary, 1068);
- var_dump($header->getHeaderSize());
- var_dump($header->getType());
- var_dump($header->getValue());
-}
File_AndroidManifest/trunk/File/AndroidManifest/XMLTreeExt.class.php
@@ -1,15 +1,104 @@
<?php
+/**
+ * XMLTreeExt class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
require_once 'File/AndroidManifest/Util/BinaryUtil.class.php';
+
+/**
+ * XMLTreeExt class
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class XMLTreeExt
{
+ /**
+ * index of the namespace of this element.
+ * @var integer
+ * @access private
+ */
private $namespace_no;
+
+ /**
+ * index of string name of this node if it is an ELEMENT; the raw
+ * character data if this is a CDATA node.
+ * @var integer
+ * @access private
+ */
private $element_no;
+
+ /**
+ * Byte offset from the start of this structure where the attributes start.
+ * @var integer
+ * @access private
+ */
private $attr_offset;
+
+ /**
+ * Size of the ResXMLTree_attribute structures that follow.
+ * @var integer
+ * @access private
+ */
private $attr_size;
+
+ /**
+ * Number of attributes associated with an ELEMENT
+ * @var integer
+ * @access private
+ */
private $attr_count;
+
+ /**
+ * Index (1-based) of the "id" attribute. 0 if none.
+ * @var integer
+ * @access private
+ */
private $id_no;
+
+ /**
+ * Index (1-based) of the "class" attribute. 0 if none.
+ * @var integer
+ * @access private
+ */
private $class_no;
+
+ /**
+ * Index (1-based) of the "style" attribute. 0 if none.
+ * @var integer
+ * @access private
+ */
private $style_no;
+
+ /**
+ * constructor
+ *
+ * @param binary $binary binary string from AndroidManifest.xml
+ * @param integer $offset starting offset for this chunk
+ * @return void
+ * @access public
+ */
public function __construct($binary, $offset) {
$this->namespace_no = BinaryUtil::unpackLE32(substr($binary, $offset + 0));
$this->element_no = BinaryUtil::unpackLE32(substr($binary, $offset + 4));
@@ -20,43 +109,94 @@
$this->class_no = BinaryUtil::unpackLE(substr($binary, $offset + 16));
$this->style_no = BinaryUtil::unpackLE(substr($binary, $offset + 18));
}
+
+ /**
+ * return index of the namespace of this element.
+ *
+ * @return integer index of the namespace of this element.
+ * @access public
+ */
public function getNamespaceIndex() {
return $this->namespace_no;
}
+
+ /**
+ * return index of string name of this node if it is an ELEMENT
+ *
+ * @return integer index of string name of this node if it is an ELEMENT
+ * @access public
+ */
public function getElementIndex() {
return $this->element_no;
}
+
+ /**
+ * return byte offset from the start of this structure where the attributes start.
+ *
+ * @return integer Byte offset from the start of this structure where the attributes start.
+ * @access public
+ */
public function getAttributeOffset() {
return $this->attr_offset;
}
+
+ /**
+ * return size of the ResXMLTree_attribute structures that follow.
+ *
+ * @return integer Size of the ResXMLTree_attribute structures that follow.
+ * @access public
+ */
public function getAttributeSize() {
return $this->attr_size;
}
+
+ /**
+ * return number of attributes associated with an ELEMENT
+ *
+ * @return integer Number of attributes associated with an ELEMENT
+ * @access public
+ */
public function getAttributeCount() {
return $this->attr_count;
}
+
+ /**
+ * return index (1-based) of the "id" attribute
+ *
+ * @return integer Index (1-based) of the "id" attribute. 0 if none.
+ * @access public
+ */
public function getIdIndex() {
return $this->id_no;
}
+
+ /**
+ * return index (1-based) of the "class" attribute
+ *
+ * @return integer Index (1-based) of the "class" attribute. 0 if none.
+ * @access public
+ */
public function getClassIndex() {
return $this->class_no;
}
+
+ /**
+ * return index (1-based) of the "style" attribute
+ *
+ * @return integer Index (1-based) of the "style" attribute. 0 if none.
+ * @access public
+ */
public function getStyleIndex() {
return $this->style_no;
}
+
+ /**
+ * return size of the chunk header
+ *
+ * @return integer Size of the chunk header. always 20.
+ * @access public
+ */
public function getHeaderSize() {
return 20;
}
}
-if (isset($argv[0]) && __FILE__ === realpath($argv[0])) {
- $binary = file_get_contents('./MyApp_AndroidManifest.xml');
- $header = new XMLTreeExt($binary);
- var_dump($header->getNamespaceIndex());
- var_dump($header->getElementIndex());
- var_dump($header->getAttributeOffset());
- var_dump($header->getAttributeSize());
- var_dump($header->getAttributeCount());
- var_dump($header->getIdIndex());
- var_dump($header->getClassIndex());
- var_dump($header->getStyleIndex());
-}
File_AndroidManifest/trunk/File/AndroidManifest/Util/BinaryUtil.class.php
@@ -1,12 +1,73 @@
<?php
+/**
+ * BinaryUtil class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
+/**
+ * BinaryUtil class
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class BinaryUtil
{
+
+ /**
+ * unpack binary string with little endian (16bit)
+ *
+ * @param binary $data binary data
+ * @param integer $length a length of unpacked array. default is 1.
+ * @return mixed unpacked array. if $length = 1, return into string
+ * @access public
+ * @static
+ */
public static function unpackLE($data, $length = 1) {
return self::unpack('v*', $data, $length);
}
+
+ /**
+ * unpack binary string with little endian (32bit)
+ *
+ * @param binary $data binary data
+ * @param integer $length a length of unpacked array. default is 1.
+ * @return mixed unpacked array. if $length = 1, return into string
+ * @access public
+ * @static
+ */
public static function unpackLE32($data, $length = 1) {
return self::unpack('V*', $data, $length);
}
+
+ /**
+ * unpack binary string with given format
+ *
+ * @param binary $data binary data
+ * @param integer $length a length of unpacked array. default is 1.
+ * @return mixed unpacked array. if $length = 1, return into string
+ * @access public
+ * @static
+ */
public static function unpack($format, $data, $length = 1) {
$unpacked_data = unpack($format, $data);
if ($length < 1) {
File_AndroidManifest/trunk/File/AndroidManifest/XMLTreeAttribute.class.php
@@ -1,32 +1,111 @@
<?php
+/**
+ * XMLTreeAttribute class
+ *
+ * PHP version 5
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version 0.1.0
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
+
require_once 'File/AndroidManifest/Util/BinaryUtil.class.php';
+
+/**
+ * XMLTreeAttribute class
+ *
+ * @category File Formats
+ * @package File_AndroidManifest
+ * @author Hideyuki Shimooka <shimooka@doyouphp.jp>
+ * @copyright 2012 Hideyuki Shimooka
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version Release: @package_version@
+ * @link http://openpear.org/package/File_AndroidManifest
+ */
class XMLTreeAttribute
{
+ /**
+ * index of the namespace of this element.
+ * @var integer
+ * @access private
+ */
private $namespace_no;
+
+ /**
+ * index of name of this attribute.
+ * @var integer
+ * @access private
+ */
private $name_no;
+
+ /**
+ * index of value of this attribute.
+ * @var integer
+ * @access private
+ */
private $value_no;
+
+ /**
+ * constructor
+ *
+ * @param binary $binary binary string from AndroidManifest.xml
+ * @param integer $offset starting offset for this chunk
+ * @return void
+ * @access public
+ */
public function __construct($binary, $offset) {
$this->namespace_no = BinaryUtil::unpackLE32(substr($binary, $offset + 0));
$this->name_no = BinaryUtil::unpackLE32(substr($binary, $offset + 4));
$this->value_no = BinaryUtil::unpackLE32(substr($binary, $offset + 8));
}
+
+ /**
+ * return index of namespace of this attribute
+ *
+ * @return integer index of namespace of this attribute.
+ * @access public
+ */
public function getNamespaceIndex() {
return $this->namespace_no;
}
+
+ /**
+ * return index of name of this attribute.
+ *
+ * @return integer index of name of this attribute.
+ * @access public
+ */
public function getNameIndex() {
return $this->name_no;
}
+
+ /**
+ * return index of value of this attribute.
+ *
+ * @return integer index of value of this attribute.
+ * @access public
+ */
public function getValueIndex() {
return $this->value_no;
}
+
+ /**
+ * return size of the chunk header
+ *
+ * @return integer Size of the chunk header. always 12.
+ * @access public
+ */
public function getHeaderSize() {
return 12;
}
}
-if (isset($argv[0]) && __FILE__ === realpath($argv[0])) {
- $binary = file_get_contents('./MyApp_AndroidManifest.xml');
- $header = new XMLTreeAttribute($binary);
- var_dump($header->getNamespaceIndex());
- var_dump($header->getNameIndex());
- var_dump($header->getValueIndex());
-}