Diffs
IO_SWF/tags/release-1.0.0-20100816164903/sample/swfcopy.php
@@ -0,0 +1,21 @@
+<?php
+
+require 'IO/SWF.php';
+
+if ($argc != 2) {
+ echo "Usage: php swfcopy.php <swf_file>\n";
+ echo "ex) php swfdopy.php test.swf\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF();
+
+$swf->parse($swfdata);
+
+echo $swf->build();
+
+exit(0);
IO_SWF/tags/release-1.0.0-20100816164903/sample/swfreplacejpeg.php
@@ -0,0 +1,29 @@
+<?php
+
+ //require 'IO/SWF.php';
+require 'IO/SWF/Editor.php';
+
+if ($argc != 3) {
+ echo "Usage: php swfreplacejpeg.php <swf_file> <jpeg_file>\n";
+ echo "ex) php swfreplacejpeg.php test.swf test.jpg\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(is_readable($argv[2]));
+
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+$swf->parse($swfdata);
+$swf->setCharacterId($swfdata);
+
+$erroreous_header = pack('CCCC', 0xFF, 0xD9, 0xFF, 0xD8);
+$jpegdata = file_get_contents($argv[2]);
+
+$swf->replaceTagContentByCharacterId(21, 1, $erroreous_header.$jpegdata);
+
+echo $swf->build();
+
+exit(0);
IO_SWF/tags/release-1.0.0-20100816164903/sample/swfsetbgcolor.php
@@ -0,0 +1,27 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if ($argc != 5) {
+ echo "Usage: php swfsetbgcolor.php <swf_file> <red> <green> <blue>\n";
+ echo "ex) php swfsetbgcolor.php test.swf 0 0 255\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(is_numeric($argv[2]));
+assert(is_numeric($argv[3]));
+assert(is_numeric($argv[4]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$color = pack('CCC', $argv[2], $argv[3], $argv[4]);
+$swf->replaceTagContent(9, $color);
+
+echo $swf->build();
+
+exit(0);
IO_SWF/tags/release-1.0.0-20100816164903/sample/swfdump.php
@@ -0,0 +1,21 @@
+<?php
+
+require 'IO/SWF/Dumper.php';
+
+if ($argc != 2) {
+ echo "Usage: php swfdump.php <swf_file>\n";
+ echo "ex) php swfdump.php test.swf\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Dumper();
+
+$swf->parse($swfdata);
+
+$swf->dump();
+
+exit(0);
IO_SWF/tags/release-1.0.0-20100816164903/IO/SWF/Former.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * 2010/8/12- (c) yoya@awm.jp
+ */
+
+require_once 'IO/SWF.php';
+
+class IO_SWF_Former extends IO_SWF {
+ // var $_headers = array(); // protected
+ // var $_tags = array(); // protected
+
+ function form() {
+ foreach ($this->_tags as $idx => $tag) {
+ switch ($tag['Code']) {
+ case 26: // PlaceObject2
+ $this->_form_26($tag);
+ break;
+ }
+ }
+ }
+ function _form_26($tag) { // PlaceObject2
+ $reader = new IO_Bit();
+ $reader->input($tab['Content']);
+ $placeFlag = $reader->getUI8();
+ $depth = $reader->getUI16LE();
+ if ($placeFlag & 0x02) {
+ $characterId = $reader->getUI16LE();
+ }
+ //
+ }
+}
IO_SWF/tags/release-1.0.0-20100816164903/IO/SWF/Dumper.php
@@ -0,0 +1,36 @@
+<?php
+
+/*
+ * 2010/8/12- (c) yoya@awm.jp
+ */
+
+require_once 'IO/SWF.php';
+
+class IO_SWF_Dumper extends IO_SWF {
+ // instance variable
+ // var $_headers = array(); // protected
+ // var $_tags = array(); // protected
+
+ function dump() {
+ /* SWF Header */
+ echo 'Signature: '.$this->_headers['Signature'].PHP_EOL;
+ echo 'Version: '.$this->_headers['Version'].PHP_EOL;
+ echo 'FileLength: '.$this->_headers['FileLength'].PHP_EOL;
+ echo 'FrameSize: '.PHP_EOL;
+ echo "\tXmin: ".($this->_headers['FrameSize']['Xmin'] / 20).PHP_EOL;
+ echo "\tXmax: ".($this->_headers['FrameSize']['Xmax'] / 20).PHP_EOL;
+ echo "\tYmin: ".($this->_headers['FrameSize']['Ymin'] / 20).PHP_EOL;
+ echo "\tYmax: ".($this->_headers['FrameSize']['Ymax'] / 20).PHP_EOL;
+ echo 'FrameRate: '.($this->_headers['FrameRate'] / 0x100).PHP_EOL;
+ echo 'FrameCount: '.$this->_headers['FrameCount'].PHP_EOL;
+
+ /* SWF Tags */
+
+ echo 'Tags:'.PHP_EOL;
+ foreach ($this->_tags as $tag) {
+ $code = $tag['Code'];
+ $length = $tag['Length'];
+ echo "\tCode: $code Length: $length".PHP_EOL;
+ }
+ }
+}
IO_SWF/tags/release-1.0.0-20100816164903/IO/SWF/Editor.php
@@ -0,0 +1,89 @@
+<?php
+
+/*
+ * 2010/8/12- (c) yoya@awm.jp
+ */
+
+require_once 'IO/SWF.php';
+
+class IO_SWF_Editor extends IO_SWF {
+ // var $_headers = array(); // protected
+ // var $_tags = array(); // protected
+
+ function setCharacterId() {
+ foreach ($this->_tags as &$tag) {
+ $content_reader = new IO_Bit();
+ $content_reader->input($tag['Content']);
+ switch ($tag['Code']) {
+ case 4: // PlaceObject
+ case 5: // RemoveObject
+ case 6: // DefineBits
+ case 21: // DefineBitsJPEG2
+ case 35: // DefineBitsJPEG3
+ case 20: // DefineBitsLossless
+ case 46: // DefineMorphShape
+ case 2: // DefineShape (ShapeId)
+ case 22: // DefineShape2 (ShapeId)
+ case 11: // DefineText
+ case 33: // DefineText
+ case 37: // DefineTextEdit
+ $tag['CharacterId'] = $content_reader->getUI16LE();
+ break;
+ case 26: // PlaceObject2 (PlaceFlagHasCharacter)
+ $tag['PlaceFlag'] = $content_reader->getUI8();
+ if ($tag['PlaceFlag'] & 0x02) {
+ $tag['CharacterId'] = $content_reader->getUI16LE();
+ }
+ break;
+ }
+ }
+ }
+
+ function replaceTagContent($tagCode, $content, $limit = 1) {
+ $count = 0;
+ foreach ($this->_tags as &$tag) {
+ if ($tag['Code'] == $tagCode) {
+ $tag['Length'] = strlen($content);
+ $tag['Content'] = $content;
+ $count += 1;
+ if ($limit <= $count) {
+ break;
+ }
+ }
+ }
+ return $count;
+ }
+ function getTagContent($tagCode) {
+ $count = 0;
+ foreach ($this->_tags as &$tag) {
+ if ($tag['Code'] == $tagCode) {
+ return $tag['Content'];
+ }
+ }
+ return null;
+ }
+
+ function replaceTagContentByCharacterId($tagCode, $characterId, $content_after_character_id) {
+ foreach ($this->_tags as &$tag) {
+ if (($tag['Code'] == $tagCode) && isset($tag['CharacterId'])) {
+
+ if ($tag['CharacterId'] == $characterId) {
+ $tag['Length'] = 2 + strlen($content_after_character_id);
+ $tag['Content'] = pack('v', $characterId).$content_after_character_id;
+ break;
+ }
+ }
+ }
+ }
+ function getTagContentByCharacterId($tagCode, $characterId) {
+ foreach ($this->_tags as $tag) {
+ if (($tag['Code'] == $tagCode) && isset($tag['CharacterId'])) {
+ if ($tag['CharacterId'] == $characterId) {
+ return $tag['Content'];
+ break;
+ }
+ }
+ }
+ return null;
+ }
+}
IO_SWF/tags/release-1.0.0-20100816164903/IO/SWF.php
@@ -0,0 +1,94 @@
+<?php
+
+/*
+ * 2010/8/11- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+
+class IO_SWF {
+ // instance variable
+ var $_headers = array(); // protected
+ var $_tags = array(); // protected
+
+ function parse($swfdata) {
+ $reader = new IO_Bit();
+ $reader->input($swfdata);
+
+ /* SWF Header */
+ $this->_headers['Signature'] = $reader->getData(3);
+ $this->_headers['Version'] = $reader->getUI8();
+ $this->_headers['FileLength'] = $reader->getUI32LE();
+ $this->_headers['FrameSize'] = array();
+ $frameSize = array();
+ $nBits = $reader->getUIBits(5);
+ $frameSize['NBits'] = $nBits;
+ $frameSize['Xmin'] = $reader->getSIBits($nBits);
+ $frameSize['Xmax'] = $reader->getSIBits($nBits);
+ $frameSize['Ymin'] = $reader->getSIBits($nBits);
+ $frameSize['Ymax'] = $reader->getSIBits($nBits) ;
+ $this->_headers['FrameSize'] = $frameSize;
+ $reader->byteAlign();
+ $this->_headers['FrameRate'] = $reader->getUI16LE();
+ $this->_headers['FrameCount'] = $reader->getUI16LE();
+
+ /* SWF Tags */
+ while (true) {
+ $tag = Array();
+ $tagAndLength = $reader->getUI16LE();
+ $code = $tagAndLength >> 6;
+ $length = $tagAndLength & 0x3f;
+ if ($length == 0x3f) { // long format
+ $length = $reader->getUI32LE();
+ $tag['LongFormat'] = true;
+ }
+ $tag['Code'] = $code;
+ $tag['Length'] = $length;
+ $tag['Content'] = $reader->getData($length);
+ $this->_tags[] = $tag;
+ if ($code == 0) { // END Tag
+ break;
+ }
+ }
+ }
+ // function dump() => IO_SWF_Dumper
+
+ function build() {
+ $writer = new IO_Bit();
+
+ /* SWF Header */
+ $writer->putData($this->_headers['Signature']);
+ $writer->putUI8($this->_headers['Version']);
+ $writer->putUI32LE($this->_headers['FileLength']);
+
+ $nBits = $this->_headers['FrameSize']['NBits'];
+ // nBits check
+ $writer->putUIBits($nBits, 5);
+ $writer->putSIBits($this->_headers['FrameSize']['Xmin'], $nBits);
+ $writer->putSIBits($this->_headers['FrameSize']['Xmax'], $nBits);
+ $writer->putSIBits($this->_headers['FrameSize']['Ymin'], $nBits);
+ $writer->putSIBits($this->_headers['FrameSize']['Ymax'], $nBits);
+ $writer->byteAlign();
+ $writer->putUI16LE($this->_headers['FrameRate']);
+ $writer->putUI16LE($this->_headers['FrameCount']);
+
+ /* SWF Tags */
+ foreach ($this->_tags as $tag) {
+ $code = $tag['Code'];
+ $length = $tag['Length'];
+ if (empty($tag['LongFormat']) && ($length < 0x3f)) {
+ $tagAndLength = ($code << 6) | $length;
+ $writer->putUI16LE($tagAndLength);
+ } else {
+ $tagAndLength = ($code << 6) | 0x3f;
+ $writer->putUI16LE($tagAndLength);
+ $writer->putUI32LE($length);
+ }
+ $writer->putData($tag['Content']);
+ }
+ list($fileLength, $bit_offset_dummy) = $writer->getOffset();
+ $this->_headers['FileLength'] = $fileLength;
+ $writer->setUI32LE($fileLength, 4);
+ return $writer->output();
+ }
+}