#!/usr/bin/perl # ---- subroutines sub h32{ return pack("V",$_[0]); } sub h16{ return pack("v",$_[0]); } sub calctaglen{ %datahash = @_; $ret = 0; while(($key,$value) = each(%datahash)){ $ret += length($key)+length($value) + 11; } return $ret+1; } sub maketag{ %datahash = @_; $taglen = &calctaglen(%datahash); $tag = "\x3f\x03".&h32($taglen); while(($key,$value) = each(%datahash)){ $tag .= "\x96".&h16(length($key)+2)."\x00".$key."\x00"; $tag .= "\x96".&h16(length($value)+2)."\x00".$value."\x00"; $tag .= "\x1d"; } $tag .= "\x00"; return $tag; } # ---- main # %datahash に変数名と値を指定 # 自分で指定 %datahash = ("jumpsound"=>"ぼいんっ", "serif"=>"ちんぽっぽ"); # web から # %datahach = (); # $buffer = $ENV{'QUERY_STRING'}; # @pairs = split(/&/,$buffer); # foreach $pair (@pairs) { # ($name, $value) = split(/=/, $pair); # $value =~ tr/+/ /; # $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # $datahach{$name} = $value; # } # タグ生成 $doactiontag = &maketag(%datahash); $srcswf = "base.swf"; # basefile 読み込み open(FR, $srcswf); read(FR,$headtmp, 9); $rb = ord(substr($headtmp, 8,1)) >> 3; $headlen = int(((( 8 - (($rb*4+5)&7) )&7)+ $rb*4 + 5 )/8) + 12 + 5; read(FR,$headtmp2, $headlen-9); $head = $headtmp.$headtmp2; $oldsize = (stat $srcswf)[7]; $newsize = $oldsize+length($doactiontag); $newhead = substr($head,0,4).&h32($newsize).substr($head,8); read(FR, $tail, $oldsize-$headlen); close(FR); # 書き出し # $outfile = "perl.swf"; # open(FW, ">$outfile"); # print FW $newhead.$doactiontag.$tail; # close(FW); print "Content-Type: application/x-shockwave-flash\n\n"; print $newhead.$doactiontag.$tail; exit(0);