⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textdump.java

📁 利用opensource的开源jar实现生成flash文件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * TextDump.java
 * Transform
 * 
 * Copyright (c) 2001-2006 Flagstone Software Ltd. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution.
 *  * Neither the name of Flagstone Software Ltd. nor the names of its contributors 
 *    may be used to endorse or promote products derived from this software 
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.flagstone.transform.tools;

import java.util.Enumeration;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

import javax.swing.tree.DefaultMutableTreeNode;
/**
 * TextDump provides a full description of the data structures in a Flash file.
 * 
 * The tool reads the Flash file and writes the names of the data structures
 * along with the fields and values decoded to a specified file. The output is
 * formatted with tab-stops to show the depth of the decoded data structures and
 * values.
 * 
 * The tool takes two arguments:
 * 
 * --fileIn <flashfile> the name of a Flash (.swf) file.
 * 
 * --fileOut <textfile> the name of the file where the text description will be 
 *                      saved.
 *                      
 * @author Stuart MacKay
 *
 */
public class TextDump extends Tool
{
    private static final int Begin = 0;
    private static final int BeginArray = 1;
    private static final int End = 2;
    private static final int Error  = 3;
    private static final int Value = 4;

    private class SWF
    {
        /*
         * Fill Styles
         */
        static final int Solid = 0; // Solid
        static final int Linear  = 16; // Gradient 
        static final int Radial  = 18; // Gradient
        static final int Tiled = 64; // Bitmap 
        static final int Clipped = 65; // Bitmap 
        /* 
         * Fill Styles added in Flash 7
         */
        static final int Unsmoothed_Tiled = 66; // Bitmap 
        static final int Unsmoothed_Clipped = 67; // Bitmap     
        /*
         * Instructions added in Flash 1
         */
        static final int ShowFrame            = 1;
        static final int DefineShape          = 2;
        static final int PlaceObject          = 4;
        static final int RemoveObject         = 5;
        static final int DefineJPEGImage      = 6;
        static final int DefineButton         = 7;
        static final int JPEGTables           = 8;
        static final int SetBackgroundColor   = 9;
        static final int DefineFont           = 10;
        static final int DefineText           = 11;
        static final int DoAction             = 12;
        static final int FontInfo             = 13;
        static final int DefineSound          = 14;
        static final int StartSound           = 15;
        static final int SoundStreamHead      = 18;
        static final int SoundStreamBlock     = 19;
        /*
         * Instructions added in Flash 2
         */
        private static final int ButtonSound          = 17;
        private static final int DefineImage          = 20;
        private static final int DefineJPEGImage2     = 21;
        private static final int DefineShape2         = 22;
        private static final int ButtonColorTransform = 23;
        private static final int Protect              = 24;
        /*
         * Instructions added in Flash 3
         */
        private static final int Free                 = 3;
        private static final int PlaceObject2         = 26;
        private static final int RemoveObject2        = 28;
        private static final int DefineShape3         = 32;
        private static final int DefineText2          = 33;
        private static final int DefineButton2        = 34;
        private static final int DefineJPEGImage3     = 35;
        private static final int DefineImage2         = 36;
        private static final int DefineMovieClip      = 39;
        private static final int FrameLabel           = 43;
        private static final int SoundStreamHead2     = 45;
        private static final int DefineMorphShape     = 46;
        private static final int DefineFont2          = 48;
        /*
         * Instructions added in Flash 4
         */
        private static final int PathsArePostscript   = 25;
        private static final int DefineTextField      = 37;
        private static final int QuicktimeMovie       = 38;
        private static final int SerialNumber         = 41;
        private static final int DefineBitsPtr        = 1023;
        /*
         * Instructions added in Flash 5
         */
        private static final int Export               = 56;
        private static final int Import               = 57;
        private static final int EnableDebugger       = 58;
        /*
         * Instructions added in Flash 6
         */
        private static final int Initialize           = 59;
        private static final int DefineVideo          = 60;
        private static final int VideoFrame           = 61;
        private static final int FontInfo2            = 62;
        private static final int EnableDebugger2      = 64;
        /*
         * Instructions added in Flash 7
         */
        private static final int LimitScript          = 65;
        private static final int TabOrder             = 66;

        
        /*
         * Stack-based actions added in Flash 1
         */
        private static final int NextFrame        = 4;
        private static final int PrevFrame        = 5;
        private static final int Play             = 6;
        private static final int Stop             = 7;
        private static final int ToggleQuality    = 8;
        private static final int StopSounds       = 9;
        /*
         * Stack-based actions added in Flash 4
         */
        private static final int IntegerAdd       = 10;
        private static final int Subtract         = 11;
        private static final int Multiply         = 12;
        private static final int Divide           = 13;
        private static final int IntegerEquals    = 14;
        private static final int IntegerLess      = 15;
        private static final int And              = 16;
        private static final int Or               = 17;
        private static final int Not              = 18;
        private static final int StringEquals     = 19;
        private static final int StringLength     = 20;
        private static final int StringExtract    = 21;
        private static final int Pop              = 23;
        private static final int ToInteger        = 24;
        private static final int GetVariable      = 28;
        private static final int SetVariable      = 29;
        private static final int SetTarget2       = 32;
        private static final int StringAdd        = 33;
        private static final int GetProperty      = 34;
        private static final int SetProperty      = 35;
        private static final int CloneSprite      = 36;
        private static final int RemoveSprite     = 37;
        private static final int Trace            = 38;
        private static final int StartDrag        = 39;
        private static final int EndDrag          = 40;
        private static final int StringLess       = 41;
        private static final int RandomNumber     = 48;
        private static final int MBStringLength   = 49;
        private static final int CharToAscii      = 50;
        private static final int AsciiToChar      = 51;
        private static final int GetTime          = 52;
        private static final int MBStringExtract  = 53;
        private static final int MBCharToAscii    = 54;
        private static final int MBAsciiToChar    = 55;
        /*
         * Stack-based actions added in Flash 5
         */
        private static final int DeleteVariable   = 58;
        private static final int Delete           = 59;
        private static final int InitVariable     = 60;
        private static final int ExecuteFunction  = 61;
        private static final int Return           = 62;
        private static final int Modulo           = 63;
        private static final int NamedObject      = 64;
        private static final int NewVariable      = 65;
        private static final int NewArray         = 66;
        private static final int NewObject        = 67;
        private static final int GetType          = 68;
        private static final int GetTarget        = 69;
        private static final int Enumerate        = 70;
        private static final int Add              = 71;
        private static final int Less             = 72;
        private static final int Equals           = 73;
        private static final int ToNumber         = 74;
        private static final int ToString         = 75;
        private static final int Duplicate        = 76;
        private static final int Swap             = 77;
        private static final int GetAttribute     = 78;
        private static final int SetAttribute     = 79;
        private static final int Increment        = 80;
        private static final int Decrement        = 81;
        private static final int ExecuteMethod    = 82;
        private static final int NewMethod        = 83;
        private static final int BitwiseAnd       = 96;
        private static final int BitwiseOr        = 97;
        private static final int BitwiseXOr       = 98;
        private static final int LogicalShiftLeft = 99;
        private static final int ArithmeticShiftRight = 100;
        private static final int LogicalShiftRight    = 101;
        /*
         * Stack-based actions added in Flash 6
         */
        private static final int InstanceOf      = 84;
        private static final int EnumerateObject = 85;
        private static final int StrictEquals    = 102;
        private static final int Greater         = 103;
        private static final int StringGreater   = 104;
        /*
         * Stack-based actions added in Flash 7
         */
        private static final int Throw      = 42;
        private static final int Cast       = 43;
        private static final int Implements = 44;
        private static final int Extends    = 105;
        

        /*
         * Non stack-based actions added in Flash 1
         */
        private static final int GotoFrame     = 129;
        private static final int GetUrl        = 131;
        /*
         * Non stack-based actions added in Flash 3
         */
        private static final int WaitForFrame  = 138;
        private static final int SetTarget     = 139;
        private static final int GotoLabel     = 140;
        /*
         * Non stack-based actions added in Flash 4
         */
        private static final int WaitForFrame2 = 141;
        private static final int Push          = 150;
        private static final int Jump          = 153;
        private static final int GetUrl2       = 154;
        private static final int If            = 157;
        private static final int Call          = 158;
        private static final int GotoFrame2    = 159;
        /*
         * Non stack-based actions added in Flash 5
         */
        private static final int RegisterCopy  = 135;
        private static final int Table         = 136;
        private static final int With          = 148;
        private static final int NewFunction   = 155;
        /*
         * Non stack-based actions added in Flash 7
         */
        private static final int NewFunction2     = 142;
        private static final int ExceptionHandler = 143;

        void decodeMovie(byte[] bytes, TextDump listener)
        {
            SWFDecoder coder = null;

            try
            {
                if (bytes[0] == 0x43)
                {
                    int movieLength = 0;

                    for (int i=0; i<4; i++)
                        movieLength += (bytes[i+4] & 0x000000FF) << (i*8);
                        
                    byte[] unzippedBytes = new byte[movieLength];
                    
                    for (int i=0; i<8; i++)
                        unzippedBytes[i] = bytes[i];            
                    
                    Inflater inflater = new Inflater();
                    inflater.setInput(bytes, 8, bytes.length-8);
                    inflater.inflate(unzippedBytes, 8, movieLength-8);

                    coder = new SWFDecoder(unzippedBytes, listener);
                }
                else
                {
                    coder = new SWFDecoder(bytes, listener);
                }
                coder.beginObject("movie", "Movie");
        
                coder.readString("signature", 3);
                int version = coder.readWord("version", 1, false);
                coder.readWord("length", 4, false);
                decodeBounds("frameSize", coder);
                coder.readFixedWord("frameRate", 16, 256, false);
                coder.readWord("frameCount", 2, false);
        
                coder.context[SWFDecoder.Version] = version;
        
                coder.beginArray("objects");
            
                while (decodeObject(coder));
                    
                coder.endObject();        
                coder.endObject();
            }
            catch (DataFormatException e)
            {
                coder.logError("DataFormatError", 0, 0);
            }
        }

        boolean decodeObject(SWFDecoder coder)
        {
            int type = coder.scanWord(2, false) >> 6;

            if (type == 0)
                return false;
                
            int length = coder.scanWord(2, false) & 0x3F;
            int next = coder.getPointer() + 16 + (length << 3);
        
            if (length == 0x3F)
            {
                coder.adjustPointer(16);
                length = coder.scanWord(4, false);
                next = coder.getPointer() + 32 + (length << 3);
                coder.adjustPointer(-16);
            }
            

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -