チェンジセット 848
- コミット日時:
- 2008/07/15 23:13:06 (4 ヶ月前)
- ファイル:
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
air/ByteCodeDisassembler/Controller.as
r844 r848 8 8 import flash.utils.ByteArray; 9 9 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'; 10 17 11 public class Controller{ 12 public var frame : Array = []; 13 public var info : Object = []; 18 private var frame_ : Array = []; 19 private var info_ : Object; 14 20 15 // listener16 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 25 21 private var stream : URLStream; 26 22 27 // -------------------- 28 // 進捗状況の取得 29 // -------------------- 30 public function get bytesLoaded():uint{ 31 return this.loaded; 23 public function get frame():Array{ 24 return frame_; 32 25 } 33 26 34 public function get bytesTotal():uint{35 return this.total;27 public function get info():Object{ 28 return info_; 36 29 } 37 30 38 39 // --------------------40 //event handler41 // --------------------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 66 31 67 32 // リスナの呼び出し 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)); 73 35 } 74 36 … … 77 39 */ 78 40 public function disassemble(path : String) : void{ 79 this.loaded = 0; 80 this.total = 100; 81 notify(onProgress); 41 this.reset(); 82 42 stream = new URLStream(); 83 43 stream.addEventListener(Event.COMPLETE, onComplete); … … 88 48 89 49 private function onComplete(e : Event) : void { 90 frame = [];91 50 var bytes:ByteArray = new ByteArray(); 92 51 stream.readBytes(bytes); … … 94 53 95 54 var swf:SwfStream = new SwfStream(bytes); 96 this.total = swf.length;97 55 swf.seekToBody(); 98 56 try { 99 57 for (;;) { 100 this.loaded = swf.position; 101 notify(onProgress); 58 this.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, 59 false,false, 60 swf.position,swf.length)); 102 61 103 62 var byte:uint = swf.readShort(); … … 109 68 switch (tag) { 110 69 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()}); 112 76 swf.seek(length); 113 77 break; 114 78 115 79 default: 116 frame .push({label:'???',tag:tag,length:length});80 frame_.push({label:'???',tag:tag,length:length}); 117 81 swf.seek(length); 118 82 break; … … 124 88 trace(e); 125 89 } 126 this.notify(this.onLoad); 90 this.notify(LOAD); 91 } 92 93 private function reset():void{ 94 this.frame_ = []; 127 95 } 128 96 129 97 public function showInfo(item : Object):void{ 130 this.info = item;131 this.notify( this.onInfo);98 this.info_ = item; 99 this.notify(INFO); 132 100 } 133 101 } air/ByteCodeDisassembler/Main.mxml
r843 r848 11 11 private function init() : void{ 12 12 var self : Object = this; 13 controller.add LoadListener(function() : void{13 controller.addEventListener(Controller.LOAD,function(event : Event) : void{ 14 14 self.tree.dataProvider = controller.frame; 15 15 }); 16 16 17 controller.add InfoListener(function() : void{17 controller.addEventListener(Controller.INFO,function(event : Event) : void{ 18 18 switch(controller.info.tag){ 19 19 case 'abc': … … 29 29 } 30 30 }); 31 controller.addProgressListener(function () : void{ 32 self.progress.setProgress(self.controller.bytesLoaded,self.controller.bytesTotal); 33 }); 31 this.progress.source = controller; 34 32 } 35 33 ]]> … … 50 48 </HBox> 51 49 </HBox> 52 <ProgressBar width="100%" id="progress" mode="manual"/>50 <ProgressBar width="100%" id="progress" /> 53 51 </Application>
