function parseContent($tagCode, $content, $opts = array()) { $reader = new IO_Bit(); $reader->input($content); if ($tagCode == 59) { // DoInitAction $this->_spriteId = $reader->getUI16LE(); } $i = 0; while ($reader->hasNextData(1)) { list($byteOffset, $dummy) = $reader->getOffset(); $action = IO_SWF_Type_Action::parse($reader); list($nextByteOffset, $dummy) = $reader->getOffset(); // $this->_byteOffsetTable[$i] = $byteOffset; $this->_byteSizeTable[$i] = $nextByteOffset - $byteOffset; $recordOffsetToByteOffset[$i] = $byteOffset; $byteOffsetToRecordOffset[$byteOffset] = $i; // $this->_actions[] = $action; $i++; } if ($i > 0) { $recordOffsetToByteOffset[$i] = $nextByteOffset; $byteOffsetToRecordOffset[$nextByteOffset] = $i; $byteOffsetToRecordOffset[$nextByteOffset] = $i; } $label_num = 0; foreach ($this->_actions as $i => $action) { if ($action['Code'] == 0x99) { // Jump $branch_offset = $action['BranchOffset']; } else { if ($action['Code'] == 0x9d) { // If $branch_offset = $action['Offset']; } else { continue; } } $targetByteOffset = $recordOffsetToByteOffset[$i + 1] + $branch_offset; if (isset($byteOffsetToRecordOffset[$targetByteOffset])) { $targetRecordOffset = $byteOffsetToRecordOffset[$targetByteOffset]; if (isset($this->_labels[$targetRecordOffset]) === false) { $this->_labels[$targetRecordOffset] = $targetRecordOffset; } $this->_branches[$i] = $this->_labels[$targetRecordOffset]; } } }
function parse($swfdata) { $reader = new IO_Bit(); $reader->input($swfdata); $this->_swfdata = $swfdata; /* SWF Header */ $this->_headers['Signature'] = $reader->getData(3); $this->_headers['Version'] = $reader->getUI8(); $this->_headers['FileLength'] = $reader->getUI32LE(); if ($this->_headers['Signature'][0] == 'C') { // CWS の場合、FileLength の後ろが zlib 圧縮されている $uncompressed_data = gzuncompress(substr($swfdata, 8)); if ($uncompressed_data === false) { return false; } list($byte_offset, $dummy) = $reader->getOffset(); $reader->setOffset(0, 0); $swfdata = $reader->getData($byte_offset) . $uncompressed_data; $reader = new IO_Bit(); $reader->input($swfdata); $this->_swfdata = $swfdata; $reader->setOffset($byte_offset, 0); } /* SWF Movie Header */ $this->_headers['FrameSize'] = IO_SWF_Type_RECT::parse($reader); $reader->byteAlign(); $this->_headers['FrameRate'] = $reader->getUI16LE(); $this->_headers['FrameCount'] = $reader->getUI16LE(); list($this->_header_size, $dummy) = $reader->getOffset(); /* SWF Tags */ while (true) { $swfInfo = array('Version' => $this->_headers['Version']); $tag = new IO_SWF_Tag($swfInfo); $tag->parse($reader); $this->_tags[] = $tag; if ($tag->code == 0) { // END Tag break; } } return true; }
function buildContent($tagCode, $opts = array()) { $writer = new IO_Bit(); $writer->putUI16LE($this->_buttonId); $opts['tagCode'] = $tagCode; if ($tagCode == 34) { // DefineButton2 $writer->putUIBits($this->_reservedFlags, 7); $writer->putUIBit($this->_trackAsMenu); list($offset_actionOffset, $dummy) = $writer->getOffset(); $writer->putUI16LE(0); // dummy; } foreach ($this->_characters as $character) { IO_SWF_Type_BUTTONRECORD::build($writer, $character, $opts); } $writer->putUI8(0); // terminater of button record if ($tagCode == 34) { // DefineButton2 $actions = array(); if (is_null($this->_actions) === false) { list($offset_buttonCondition, $dummy) = $writer->getOffset(); $writer->setUI16LE($offset_buttonCondition - $offset_actionOffset, $offset_actionOffset); foreach ($this->_actions as $idx => $action) { if (isset($this->_actions[$idx + 1]) === false) { $opts['lastAction'] = true; } else { $opts['lastAction'] = false; } IO_SWF_Type_BUTTONCONDACTION::build($writer, $action, $opts); } } } else { foreach ($this->_actions as $action) { IO_SWF_Type_Action::build($writer, $action); } $writer->putUI8(0); // terminator of actions } return $writer->output(); }
function _splitChunk($eoiFinish = true, $sosScan = true) { $bitin = new IO_Bit(); $bitin->input($this->_jpegdata); while ($bitin->hasNextData()) { $marker1 = $bitin->getUI8(); if ($marker1 != 0xff) { fprintf(STDERR, "dumpChunk: marker1=0x%02X", $marker1); return false; } $marker2 = $bitin->getUI8(); switch ($marker2) { case 0xd8: // SOI (Start of Image) $this->_jpegChunk[] = array('marker' => $marker2, 'data' => null, 'length' => null); continue; case 0xd9: // EOI (End of Image) $this->_jpegChunk[] = array('marker' => $marker2, 'data' => null, 'length' => null); if ($eoiFinish) { break 2; // while break; } continue; case 0xda: // SOS if ($sosScan === false) { $remainData = $bitin->getDataUntil(false); $this->_jpegChunk[] = array('marker' => $marker2, 'data' => $remainData, 'length' => null); break 2; // while break; } case 0xd0: case 0xd1: case 0xd2: case 0xd3: // RST // RST case 0xd4: case 0xd5: case 0xd6: case 0xd7: // RST list($chunk_data_offset, $dummy) = $bitin->getOffset(); while (true) { $next_marker1 = $bitin->getUI8(); if ($next_marker1 != 0xff) { continue; } $next_marker2 = $bitin->getUI8(); if ($next_marker2 == 0x0) { continue; } $bitin->incrementOffset(-2, 0); // back from next marker list($next_chunk_offset, $dummy) = $bitin->getOffset(); $length = $next_chunk_offset - $chunk_data_offset; $bitin->setOffset($chunk_data_offset, 0); $this->_jpegChunk[] = array('marker' => $marker2, 'data' => $bitin->getData($length), 'length' => null); break; } break; default: $length = $bitin->getUI16BE(); $this->_jpegChunk[] = array('marker' => $marker2, 'data' => $bitin->getData($length - 2), 'length' => $length); continue; } } }