-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
381 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace PhpZip\Extra\Fields; | ||
|
||
use PhpZip\Exception\InvalidArgumentException; | ||
use PhpZip\Extra\ExtraField; | ||
|
||
/** | ||
* Apk Alignment Extra Field | ||
* | ||
* @author Ne-Lexa [email protected] | ||
* @license MIT | ||
*/ | ||
class ApkAlignmentExtraField implements ExtraField | ||
{ | ||
/** | ||
* Minimum size (in bytes) of the extensible data block/field used | ||
* for alignment of uncompressed entries. | ||
*/ | ||
const ALIGNMENT_ZIP_EXTRA_MIN_SIZE_BYTES = 6; | ||
|
||
const ANDROID_COMMON_PAGE_ALIGNMENT_BYTES = 4096; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $multiple; | ||
/** | ||
* @var int | ||
*/ | ||
private $padding; | ||
|
||
/** | ||
* Returns the Header ID (type) of this Extra Field. | ||
* The Header ID is an unsigned short integer (two bytes) | ||
* which must be constant during the life cycle of this object. | ||
* | ||
* @return int | ||
*/ | ||
public static function getHeaderId() | ||
{ | ||
return 0xD935; | ||
} | ||
|
||
/** | ||
* Serializes a Data Block. | ||
* @return string | ||
*/ | ||
public function serialize() | ||
{ | ||
if ($this->padding > 0) { | ||
$args = array_merge( | ||
['vc*', $this->multiple], | ||
array_fill(2, $this->padding, 0) | ||
); | ||
return call_user_func_array('pack', $args); | ||
} | ||
return pack('v', $this->multiple); | ||
} | ||
|
||
/** | ||
* Initializes this Extra Field by deserializing a Data Block. | ||
* @param string $data | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function deserialize($data) | ||
{ | ||
$length = strlen($data); | ||
if ($length < 2) { | ||
// This is APK alignment field. | ||
// FORMAT: | ||
// * uint16 alignment multiple (in bytes) | ||
// * remaining bytes -- padding to achieve alignment of data which starts after | ||
// the extra field | ||
throw new InvalidArgumentException("Minimum 6 bytes of the extensible data block/field used for alignment of uncompressed entries."); | ||
} | ||
$this->multiple = unpack('v', $data)[1]; | ||
$this->padding = $length - 2; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getMultiple() | ||
{ | ||
return $this->multiple; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getPadding() | ||
{ | ||
return $this->padding; | ||
} | ||
|
||
/** | ||
* @param int $multiple | ||
*/ | ||
public function setMultiple($multiple) | ||
{ | ||
$this->multiple = $multiple; | ||
} | ||
|
||
/** | ||
* @param int $padding | ||
*/ | ||
public function setPadding($padding) | ||
{ | ||
$this->padding = $padding; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace PhpZip\Extra\Fields; | ||
|
||
use PhpZip\Exception\ZipException; | ||
use PhpZip\Extra\ExtraField; | ||
|
||
/** | ||
* Jar Marker Extra Field | ||
* An executable Java program can be packaged in a JAR file with all the libraries it uses. | ||
* Executable JAR files can easily be distinguished from the files packed in the JAR file | ||
* by the extra field in the first file, which is hexadecimal in the 0xCAFE bytes series. | ||
* | ||
* @author Ne-Lexa [email protected] | ||
* @license MIT | ||
*/ | ||
class JarMarkerExtraField implements ExtraField | ||
{ | ||
/** | ||
* Returns the Header ID (type) of this Extra Field. | ||
* The Header ID is an unsigned short integer (two bytes) | ||
* which must be constant during the life cycle of this object. | ||
* | ||
* @return int | ||
*/ | ||
public static function getHeaderId() | ||
{ | ||
return 0xCAFE; | ||
} | ||
|
||
/** | ||
* Serializes a Data Block. | ||
* @return string | ||
*/ | ||
public function serialize() | ||
{ | ||
return ''; | ||
} | ||
|
||
/** | ||
* Initializes this Extra Field by deserializing a Data Block. | ||
* @param string $data | ||
* @throws ZipException | ||
*/ | ||
public function deserialize($data) | ||
{ | ||
if (0 !== strlen($data)) { | ||
throw new ZipException("JarMarker doesn't expect any data"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.