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

📄 actionparser.java

📁 java版本的flash文件(swf)播放器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        //System.out.println( "codesize=" + codesize ); System.out.flush();

        actions.startFunction( name, params );
        
        //empty functions have no code
        if( codesize == 0 ) {
        	actions.endBlock();
        	return;
        }
        
        blockDepth++;
    }

    protected void parseWith( InStream in ) throws IOException 
    {
        int codesize = in.readUI16();

        actions.startWith( );

		//empty blocks have no code
		if( codesize == 0 ) {
			actions.endBlock();
			return;
		}
		
        blockDepth++;
    }    
    
    protected void parseLookupTable( InStream in ) throws IOException 
    {
        String[] strings = new String[ in.readUI16() ];
        
        for( int i = 0; i < strings.length; i++ )
        {
            strings[i] = in.readString(mStringEncoding);
        }
        
        actions.lookupTable( strings );
    }
    
    protected void parseGetURL2( int flags ) throws IOException
    {
        int sendVars = flags & 0x03;
        int mode = 0;
        
        switch( flags & 0xF0 )
        {
            case 0x40: mode = SWFActions.GET_URL_MODE_LOAD_MOVIE_INTO_SPRITE; break;
            case 0x80: mode = SWFActions.GET_URL_MODE_LOAD_VARS_INTO_LEVEL;   break;
            case 0xC0: mode = SWFActions.GET_URL_MODE_LOAD_VARS_INTO_SPRITE;  break;
            default:   mode = SWFActions.GET_URL_MODE_LOAD_MOVIE_INTO_LEVEL;  break;
        }
        
        actions.getURL( sendVars, mode );
    }
    
    protected void parsePush( int length, InStream in ) throws IOException 
    {
        while( in.getBytesRead() < length )
        {
            int pushType = in.readUI8();
            
            switch( pushType )
            {
                case PUSHTYPE_STRING  : actions.push( in.readString(mStringEncoding) ); break;
                case PUSHTYPE_FLOAT   : actions.push( in.readFloat() ); break;
                case PUSHTYPE_NULL    : actions.pushNull(); break;
                case PUSHTYPE_03      : break;
                case PUSHTYPE_REGISTER: actions.pushRegister( in.readUI8() ); break;
                case PUSHTYPE_BOOLEAN : actions.push( (in.readUI8() != 0) ? true : false ); break;
                case PUSHTYPE_DOUBLE  : actions.push( in.readDouble() ); break;
                case PUSHTYPE_INTEGER : actions.push( in.readSI32() ); break;
                case PUSHTYPE_LOOKUP  : actions.lookup( in.readUI8() ); break;
                default:
            }
        }
    }
    
    protected static class ActionRecord
    {
        public int offset;   //byte offset from start of the action array
        public int code;
        public String label;
        public String jumpLabel;
        public byte[] data;
        public int blockDepth = 0;
        
        protected ActionRecord( int offset, int code, byte[] data )
        {
            this.offset = offset;
            this.code   = code;
            this.data   = data;
        }
    }

    /**
     * First Pass to determine action offsets and jumps
     */
    protected Vector createRecords( byte[] bytes ) throws IOException 
    {            
        return createRecords( new InStream( bytes ));
    }
        
    /**
     * First Pass to determine action offsets and jumps
     */
    protected Vector createRecords( InStream in ) throws IOException 
    {        
        Vector records  = new Vector();
        Vector jumpers  = new Vector();
        Vector skippers = new Vector();
        Hashtable offsetTable = new Hashtable();
   
        Stack blockSizes = new Stack();
        
        int labelIndex = 0;
        
        while( true )
        {   
            int offset = (int)in.getBytesRead();
            
            //System.out.println( "read=" + offset ); System.out.flush();
            
            int code = in.readUI8();                
            int dataLength = (code >= 0x80) ? in.readUI16() : 0;   
            byte[] data = ( dataLength > 0 ) ? in.read( dataLength ) : null;

            //System.out.println( "size=" + dataLength ); System.out.flush();          
            
            ActionRecord rec = new ActionRecord( offset, code, data );
            records.addElement( rec );   
            offsetTable.put( new Integer(offset), rec );

            if( ! blockSizes.isEmpty() )
            {      
                int depth = blockSizes.size();
                rec.blockDepth = depth;
                int blockDecrement = ( dataLength > 0 ) ? ( dataLength + 3 ) : 1;

                //--subtract the size of this action from all the block sizes
                //  in the block stack
                for( int i = depth-1; i >= 0; i-- )
                {                
                    int[] blockSize = (int[])blockSizes.elementAt(i);
                    int size = blockSize[0];
                
                    size -= blockDecrement;
                    
                    //--reached end of block ?
                    if( size <= 0 ) blockSizes.pop();
                    else blockSize[0] = size;
                }
            }            
            
            if( code == 0 ) break; //end of actions
            
            else if( code == DEFINE_FUNCTION )
            {
                InStream in2 = new InStream( rec.data );
                in2.readString(mStringEncoding);
                int params = in2.readUI16();
                for( int i = 0; i < params; i++ ) in2.readString(mStringEncoding);        
                int blockSize = in2.readUI16();
                blockSizes.push( new int[]{ blockSize } );
            }
            else if( code == WITH )
            {
                InStream in2 = new InStream( rec.data );
                int blockSize = in2.readUI16();
                blockSizes.push( new int[]{ blockSize } );                
            }            
            else if( code == WAIT_FOR_FRAME || code == WAIT_FOR_FRAME_2 ) 
            {
                skippers.addElement( new Integer(records.size()-1));
            }
            else if( code == IF || code == JUMP ) jumpers.addElement( rec );
        }        
        
        //--Tie up the jumpers with the offsets
        for( Enumeration enum = jumpers.elements(); enum.hasMoreElements(); )
        {
            ActionRecord rec = (ActionRecord)enum.nextElement();
            
            InStream in2 = new InStream( rec.data );
            int jumpOffset = in2.readSI16();
            int offset = rec.offset + 5;
            int absoluteOffset = offset + jumpOffset;
            
            ActionRecord target = 
                (ActionRecord)offsetTable.get( new Integer(absoluteOffset) );
            
            if( target != null )
            {
                if( target.label == null ) target.label = rec.jumpLabel = "label" + (labelIndex++);
                else rec.jumpLabel = target.label;
            }
        }
        
        //--Tie up the skippers with labels
        for( Enumeration enum = skippers.elements(); enum.hasMoreElements(); )
        {
            int idx = ((Integer)enum.nextElement()).intValue();
            
            ActionRecord rec = (ActionRecord)records.elementAt(idx);
            
            InStream in2 = new InStream( rec.data );
            
            if( rec.code == WAIT_FOR_FRAME ) in2.readUI16();  //skip frame number
            int skip = in2.readUI8();
            int skipIndex = idx + skip + 1;
            
            if( skipIndex < records.size() )
            {
                ActionRecord target = (ActionRecord)records.elementAt(skipIndex);
                
                if( target.label == null ) target.label = rec.jumpLabel = "label" + (labelIndex++);
                else rec.jumpLabel = target.label;                
            }
        }
        
        return records;
    }
    

}

⌨️ 快捷键说明

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