Changeset 6463 for lang/ruby/asc3to2

Show
Ignore:
Timestamp:
02/10/08 04:19:25 (5 years ago)
Author:
gyuque
Message:

3to2: extracted SWF parser

Location:
lang/ruby/asc3to2
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/asc3to2/AsConverter.rb

    r6451 r6463  
    77 
    88require 'zlib' 
     9require 'swf' 
    910 
    1011# AsConverter 
     
    160161  # Param:: 読み込むファイル名 
    161162  def readSwfFile(filename) 
    162     org = open(filename, "rb").read 
    163     swf = org.unpack("B*").to_s 
    164     h = 0 
    165     # ヘッダ部 
    166     ## CWS形式だったらswfを読み込み直す 
    167     if swf[h,8].to_i(2).chr == "C" then 
    168       swf = org[0,8].unpack("B*").to_s 
    169       swf << Zlib::Inflate.inflate(org[8,org.length-8]).unpack("B*").to_s 
    170     end 
    171     ## 最初の64ビットを無視 
    172     h += 64 
    173     ## RECT構造体 
    174     ### 構造体各要素長さ 
    175     rl = swf[h,5].to_i(2) 
    176     ### RECT構造体を無視 
    177     h += 5 + (4*rl) 
    178     ### padding 
    179     h += (8 - h%8) 
    180     ## ヘッダの残り32ビットを無視 
    181     h += 32 
    182  
    183     # タグの読み取り開始 
    184     begin 
    185       # タグタイプ&長さ取得 
    186       tag_and_length = swf[h+8,8] + swf[h,8] 
    187       # EndTagだったら終了 
    188       if (0 == tagid = tag_and_length[0,10].to_i(2)) then break end 
    189  
    190       # longタグ対応 
    191       if (63 == l = tag_and_length[10,6].to_i(2)) then 
    192         htemp = h + 16 
    193         lstr = "" 
    194         4.times do 
    195           lstr = swf[htemp,8] + lstr 
    196           htemp += 8 
    197         end 
    198         l = lstr.to_i(2) 
    199         h += 32 
    200       end 
    201       h += 16 
    202        
    203       # タグIDが0x52(DoABC)であればABCとしてインスタンス変数へ格納 
    204       # それ以外は無視 
    205       # DoABCは1回しか出てこないことを期待 
    206       if tagid == 82 then 
    207         @abc = swf[h,8*l] 
    208         break 
    209       end 
    210       h += (8*l) 
    211     end until h > swf.length 
     163    swf = SWF::SWF.new 
     164     
     165    def swf.tagDOABC(bs, tag_len) 
     166      @abc = bs.read(8*tag_len) 
     167 
     168      def self.abc 
     169        @abc 
     170      end 
     171    end 
     172     
     173    swf.load(filename) 
     174    @abc = swf.abc 
    212175  end 
    213176