[Swfed-svn] swfed-svn [79] HTTP POST した SWF ファイルを解析するページ

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 10月 15日 (水) 20:02:41 JST


Revision: 79
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=swfed&view=rev&rev=79
Author:   yoya
Date:     2008-10-15 20:02:41 +0900 (Wed, 15 Oct 2008)

Log Message:
-----------
HTTP POST した SWF ファイルを解析するページ

Added Paths:
-----------
    trunk/sample/swfdump/
    trunk/sample/swfdump/define.php
    trunk/sample/swfdump/index.php
    trunk/sample/swfdump/swfimage.php
    trunk/sample/swfdump/swfimagelist.php


-------------- next part --------------
Added: trunk/sample/swfdump/define.php
===================================================================
--- trunk/sample/swfdump/define.php	                        (rev 0)
+++ trunk/sample/swfdump/define.php	2008-10-15 11:02:41 UTC (rev 79)
@@ -0,0 +1,3 @@
+<?php
+
+$tmp_prefix = '/tmp/swf-';

Added: trunk/sample/swfdump/index.php
===================================================================
--- trunk/sample/swfdump/index.php	                        (rev 0)
+++ trunk/sample/swfdump/index.php	2008-10-15 11:02:41 UTC (rev 79)
@@ -0,0 +1,102 @@
+<?php require_once('define.php') ?>
+
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+</head>
+<body>
+<form enctype="multipart/form-data" action="" method="POST">
+    <input type="hidden" name="MAX_FILE_SIZE" value="67108864" />
+    SWF ファイルをアップロード: <input name="swffile" type="file" />
+    <input type="submit" value="ファイルを送信" />
+</form>
+<?php
+
+if (@$argc > 1) {
+    if (! is_array($_FILES)) {
+        $_FILES = array();
+        $_FILES['swffile'] = array();
+    }
+    $_FILES['swffile']['tmp_name'] = $argv[1];
+}
+
+if (! empty($_FILES['swffile']['tmp_name'])) {
+    $filename = $_FILES['swffile']['tmp_name'];
+    $swfdata = file_get_contents($filename);
+    if ($swfdata > 67108864) {
+        echo ' 64M Bytes 以内のファイルしか受け付けません。'."\n";
+        exit(0);
+    }
+    $tmp_name = sha1($swfdata, false);
+    $id = substr($tmp_name, 0, 16); // XXX
+    $tmp_filename = "$tmp_prefix$id.swf";
+    if (! file_put_contents($tmp_filename, $swfdata)) {
+        echo 'ERROR: file_put_contents failed.  zero size ?'."\n";
+        unlink($tmp_filename);
+        exit(0);
+    }
+    header("Location: ./index.php?id=$id");
+    exit(0);
+} else {
+   if (empty($_REQUEST['id']))  {
+        echo "ファイルを指定してください。(64MBytes 以内に限定してます)";
+        exit(0);
+   }
+   $id = $_REQUEST['id'];
+   $tmp_filename = "$tmp_prefix$id.swf";
+   $swfdata = file_get_contents($tmp_filename);
+}
+
+echo "<a href=\"./swfimagelist.php?id=$id\"> 画像一覧 </a> <br />\n";
+
+$swf = new SWFEditor();
+$swf->input($swfdata);
+
+$header_info = $swf->getHeaderInfo();
+
+if ($header_info['compress']) {
+    $compress = 'true';
+} else {
+    $compress = 'false';
+
+}
+echo "<table border=1>\n";
+echo "<tr> <th> compress </th> </tr>\n";
+echo "<tr> <td> $compress </td> </tr>\n";
+echo "</table>\n";
+
+echo "<table border=1>\n";
+echo "<th> tag </th> <th> length </th> <th> detail </th>\n";
+foreach ($swf->getTagList() as $tag_seqno => $tagblock) {
+    $tag= $tagblock['tag'];
+    if (empty($tagblock['tagName'])) {
+        $name = "Unknown";
+    } else {
+        $name = $tagblock['tagName'];
+    }
+    $length = $tagblock['length'];
+    $detail = @$tagblock['detail'];
+    echo "<tr>\n";
+    echo "<td> $name($tag) </td> ";
+    echo "<td> $length </td>\n";
+    if ($detail) {
+        $detail_info = $swf->getTagDetail($tag_seqno);
+        $detail_str = '';
+        foreach ($detail_info as $key => $value) {
+            $detail_str .= "$key($value) ";
+        }
+
+        if (@$header_info['version'] < 6) { // for flash lite
+            $detail_str = mb_convert_encoding($detail_str, "UTF-8", "SJIS-win");
+        }
+        echo "<td> ".htmlspecialchars($detail_str)."</td>";
+    } else {
+        echo "<td> - </td>";
+    }
+    echo "</tr>\n";
+}
+echo "</table>\n";
+
+?>
+</body>
+</html>

Added: trunk/sample/swfdump/swfimage.php
===================================================================
--- trunk/sample/swfdump/swfimage.php	                        (rev 0)
+++ trunk/sample/swfdump/swfimage.php	2008-10-15 11:02:41 UTC (rev 79)
@@ -0,0 +1,24 @@
+<?php
+
+require_once('define.php');
+
+if (@$argc > 3) {
+    $id = $argv[1];
+    $image_id = $argv[2];
+    $ext = $argv[3];
+} else {
+    $id = $_REQUEST['id'];
+    $image_id = $_REQUEST['image_id'];
+    $ext = $_REQUEST['ext'];
+}
+
+$image_filename = "$tmp_prefix$id-$image_id$ext";
+$image_data = file_get_contents($image_filename);
+
+if ($ext == '.jpg') {
+    header("Content-type: image/jpeg");
+} else {
+    header("Content-type: image/png");
+}
+
+echo $image_data;

Added: trunk/sample/swfdump/swfimagelist.php
===================================================================
--- trunk/sample/swfdump/swfimagelist.php	                        (rev 0)
+++ trunk/sample/swfdump/swfimagelist.php	2008-10-15 11:02:41 UTC (rev 79)
@@ -0,0 +1,52 @@
+<?php
+
+require_once('define.php');
+
+if (@$argc > 1) {
+    $id = $argv[1];
+} else {
+    $id = $_REQUEST['id'];
+}
+
+$filename = "$tmp_prefix$id.swf";
+$swfdata = file_get_contents($filename);
+
+$swf = new SWFEditor();
+$swf->input($swfdata);
+
+echo "<table border=1>\n";
+echo "<th> tag </th> <th> image_id </th> <th> image </th>\n";
+foreach ($swf->getTagList() as $tag_seqno => $tagblock) {
+    $tag= $tagblock['tag'];
+    $ext = '';
+    if (($tag == 6) || ($tag == 21) || ($tag == 35)) {
+        $ext = '.jpg';
+    }
+    if (($tag == 20) || ($tag == 36)) {
+        $ext = '.png';
+    }
+    if (empty($ext)) {
+        continue;
+    }
+    $name = $tagblock['tagName'];
+    $detail = $tagblock['detail'];
+    $detail_info = $swf->getTagDetail($tag_seqno);
+    $image_id = $detail_info['image_id'];
+    $image_filename = "$tmp_prefix$id-$image_id$ext";
+    if ($ext == '.jpg') {
+        $image_data = $swf->getJpegData(intval($image_id));
+    } else {
+        $image_data = $swf->getPNGData(intval($image_id));
+    }
+    file_put_contents($image_filename, $image_data);
+    echo "<tr>\n";
+    echo "<td> $name($tag) </td> ";
+    echo "<td> $image_id (ext=$ext)</td>\n";
+    echo "<td> <img src=\"./swfimage.php?id=$id&image_id=$image_id&ext=$ext\"> </td>";
+    echo "</tr>\n";
+}
+echo "</table>\n";
+
+?>
+</body>
+</html>


Swfed-svn メーリングリストの案内
Back to archive index