In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

SWF inner Classes and Symbols

SWF 内の public なクラスと Symbol を表示する。
Get Adobe Flash player
by bkzen 21 Dec 2010

    Talk

    bkzen at 21 Dec 2010 08:09
    誰か private な class 表示とかできる? abcData のどっかに居るはずなんだけど・・・。
    makc3d at 06 Feb 2011 07:20
    doesnt quite work :(
    bkzen at 06 Feb 2011 17:32
    @makc3d You got it...

    Tags

    Embed
/**
 * Copyright bkzen ( http://wonderfl.net/user/bkzen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/sDvj
 */

package  
{
    import com.bit101.components.PushButton;
    import com.bit101.components.TextArea;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.FileFilter;
    import flash.net.FileReference;
    import flash.utils.ByteArray;
    import org.libspark.swfassist.io.ByteArrayInputStream;
    import org.libspark.swfassist.swf.io.ReadingContext;
    import org.libspark.swfassist.swf.io.SWFReader;
    import org.libspark.swfassist.swf.structures.Asset;
    import org.libspark.swfassist.swf.structures.SWF;
    import org.libspark.swfassist.swf.tags.AbstractTag;
    import org.libspark.swfassist.swf.tags.DoABC;
    import org.libspark.swfassist.swf.tags.SymbolClass;
    import org.libspark.swfassist.swf.tags.TagCodeConstants;
    
    /**
     * SWF 内の public なクラスとシンボル一覧
     * @author jc at bk-zen.com
     */
    [SWF (backgroundColor = "0xFFFFFF", frameRate = "30", width = "465", height = "465")]
    public class SWFInnerClassViewer extends Sprite 
    {
        private var loadBtn: PushButton;
        private var file: FileReference;
        private var symbols: Array;
        private var classes: Array;
        private var text: TextArea;
        
        public function SWFInnerClassViewer() 
        {
            file = new FileReference();
            file.addEventListener(Event.SELECT, onSelectSWF);
            file.addEventListener(Event.COMPLETE, onLoadSWF);
            loadBtn = new PushButton(this, 0, 0, "load swf", onClickLoad);
            text = new TextArea(this, 0, loadBtn.height, "");
            text.setSize(stage.stageWidth, stage.stageHeight - loadBtn.height);
        }
        
        private function onClickLoad(e: Event):void 
        {
            file.browse([new FileFilter("swf", "*.swf")]);
        }
        
        private function onSelectSWF(e:Event):void 
        {
            symbols = [], classes = [];
            file.load();
        }
        
        private function onLoadSWF(e:Event):void 
        {
            var swfReader: SWFReader = new SWFReader();
            var context: ReadingContext = new ReadingContext();
            context.needsABCData = true;
            var swf: SWF = swfReader.readSWF(new ByteArrayInputStream(file.data), context);
            var tags: Array = swf.tags.tags, i: int, n: int = swf.tags.numTags;
            for (i = 0; i < n; i ++)
            {
                var t: AbstractTag = tags[i];
                read(t);
            }
            symbols.sort();
            classes.sort();
            text.text  = "--- Symbols ---\n" + symbols.join("\n");
            text.text += "\n--- Classes ---\n" + classes.join("\n");
        }
        
        private function read(t:AbstractTag):void 
        {
            var i: int, n: int, a: Array, name: String;
            switch (t.code)
            {
                case TagCodeConstants.TAG_SYMBOL_CLASS:
                    a = SymbolClass(t).symbols, n = a.length;
                    for (i = 0; i < n; i ++)
                    {
                        if (a[i] is Asset)
                        {
                            name = (a[i] as Asset).name;
                            if (name.indexOf("__Packages.") == 0 && classes.indexOf(name) < 0) classes.push(name);
                            else if (symbols.indexOf(name) < 0) symbols.push(name);
                        }
                    }
                break;
                case TagCodeConstants.TAG_DO_ABC:
                    a = getNamesByABC(new ByteArrayInputStream(DoABC(t).abcData)), n = a.length;
                    for (i = 0; i < n; i ++)
                    {
                        classes.push(a[i]);
                    }
                break;
            }
        }
        
        private function getNamesByABC(abcData:ByteArrayInputStream): Array
        {
            var res: Array = [];
            var str: String = abcData.readUTF();
            if (str) res.push(str.replace(/\//g, "."));
            return res;
        }
    }
}