チェンジセット 848

差分発生行の前後
無視リスト:
コミット日時:
2008/07/15 23:13:06 (4 ヶ月前)
コミッタ:
mzp
ログメッセージ:

イベントの配信に、EventDispatcher?を使うようにした。

org.libspark.dissassembleは、改行コードをLFにした。

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • air/ByteCodeDisassembler/Controller.as

    r844 r848  
    88    import flash.utils.ByteArray; 
    99    import org.libspark.disassemble.SwfStream; 
     10    import org.libspark.disassemble.ByteStream; 
     11    import org.libspark.disassemble.abc.ClassPrinter; 
     12    import flash.events.*; 
     13    public class Controller extends EventDispatcher { 
     14        // listener用の定数 
     15        static public var LOAD : String = 'LOAD'; 
     16        static public var INFO : String = 'INFO'; 
    1017 
    11     public class Controller{ 
    12         public var frame : Array  = []; 
    13         public var info  : Object = []; 
     18        private var frame_ : Array  = []; 
     19        private var info_  : Object; 
    1420 
    15         // listener 
    16         private var onLoad   : Array = []; 
    17         private var onInfo     : Array = []; 
    18         private var onProgress : Array = []; 
    19          
    20         private var total:uint = 0; 
    21         private var loaded: uint = 0; 
    22          
    23  
    24          
    2521        private var stream : URLStream; 
    2622 
    27         // -------------------- 
    28         // 進捗状況の取得 
    29         // -------------------- 
    30         public function get bytesLoaded():uint{ 
    31             return this.loaded; 
     23        public function get frame():Array{ 
     24            return frame_; 
    3225        } 
    3326 
    34         public function get bytesTotal():uint{ 
    35             return this.total
     27        public function get info():Object{ 
     28            return info_
    3629        } 
    3730         
    38  
    39         // -------------------- 
    40         //event handler 
    41         // -------------------- 
    42         /** 
    43          * SWFがロードされたときに呼び出されるリスナの追加。 
    44          * 削除はできない。 
    45          */ 
    46         public function addLoadListener(f : Function):void{ 
    47             this.onLoad.push(f); 
    48         } 
    49  
    50         /** 
    51          * 表示する情報が更新されたときに呼び出されるリスナの追加。 
    52          * 削除はできない。 
    53          */ 
    54         public function addInfoListener(f : Function):void{ 
    55             this.onInfo.push(f); 
    56         } 
    57  
    58         /** 
    59          * ロード等の進捗状況が更新されたときに呼び出されるリスナの追加。 
    60          * 削除はできない。 
    61          */ 
    62         public function addProgressListener(f : Function):void{ 
    63             this.onProgress.push(f); 
    64         } 
    65  
    6631         
    6732        // リスナの呼び出し 
    68         private function notify(xs : Array):void{ 
    69             for(var i:int = 0; i < xs.length; i++){ 
    70                 var f: Function = xs[i]; 
    71                 f(this); 
    72             } 
     33        private function notify(type : String):void{ 
     34            this.dispatchEvent(new Event(type)); 
    7335        } 
    7436 
     
    7739         */ 
    7840        public function disassemble(path : String) : void{ 
    79             this.loaded = 0; 
    80             this.total = 100; 
    81             notify(onProgress); 
     41            this.reset(); 
    8242            stream = new URLStream(); 
    8343            stream.addEventListener(Event.COMPLETE, onComplete); 
     
    8848 
    8949        private function onComplete(e : Event) : void { 
    90             frame = []; 
    9150            var bytes:ByteArray = new ByteArray(); 
    9251            stream.readBytes(bytes); 
     
    9453 
    9554            var swf:SwfStream = new SwfStream(bytes); 
    96             this.total = swf.length; 
    9755            swf.seekToBody(); 
    9856            try { 
    9957                for (;;) { 
    100                     this.loaded = swf.position; 
    101                     notify(onProgress); 
     58                    this.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, 
     59                                                         false,false, 
     60                                                         swf.position,swf.length)); 
    10261 
    10362                    var byte:uint = swf.readShort(); 
     
    10968                    switch (tag) { 
    11069                    case 82:  
    111                         frame.push({label:'abc',tag:'abc'}); 
     70                        var tagStart:uint = swf.position; 
     71                        swf.readUnsignedInt(); 
     72                        for (; swf.readByte() != 0x00; ) {} 
     73                        var abcBytes:ByteArray = new ByteArray(); 
     74                        swf.readBytes(abcBytes, 0, length - (swf.position - tagStart)); 
     75                        frame_.push({label:'abc',tag:'abc',data: new ClassPrinter(abcBytes).parse()}); 
    11276                        swf.seek(length); 
    11377                        break; 
    11478                         
    11579                    default: 
    116                         frame.push({label:'???',tag:tag,length:length}); 
     80                        frame_.push({label:'???',tag:tag,length:length}); 
    11781                        swf.seek(length); 
    11882                        break; 
     
    12488                trace(e); 
    12589            } 
    126             this.notify(this.onLoad); 
     90            this.notify(LOAD); 
     91        } 
     92 
     93        private function reset():void{ 
     94            this.frame_ = []; 
    12795        } 
    12896 
    12997        public function showInfo(item : Object):void{ 
    130             this.info = item; 
    131             this.notify(this.onInfo); 
     98            this.info_ = item; 
     99            this.notify(INFO); 
    132100        } 
    133101    } 
  • air/ByteCodeDisassembler/Main.mxml

    r843 r848  
    1111private function init() : void{ 
    1212    var self : Object = this; 
    13     controller.addLoadListener(function() : void{ 
     13    controller.addEventListener(Controller.LOAD,function(event : Event) : void{ 
    1414            self.tree.dataProvider = controller.frame; 
    1515        }); 
    1616 
    17     controller.addInfoListener(function() : void{ 
     17    controller.addEventListener(Controller.INFO,function(event : Event) : void{ 
    1818            switch(controller.info.tag){ 
    1919            case 'abc': 
     
    2929            } 
    3030        }); 
    31     controller.addProgressListener(function () : void{ 
    32             self.progress.setProgress(self.controller.bytesLoaded,self.controller.bytesTotal); 
    33         }); 
     31    this.progress.source = controller; 
    3432} 
    3533    ]]> 
     
    5048    </HBox> 
    5149  </HBox> 
    52   <ProgressBar width="100%" id="progress" mode="manual"/> 
     50  <ProgressBar width="100%" id="progress" /> 
    5351</Application>