public virtual void  encode(ActionList actionList)
        {
            // write the actions
            for (int i = 0; i < actionList.size(); i++)
            {
                Action a = actionList.getAction(i);

                switch (a.code)
                {
                // don't update actionCount for synthetic opcodes
                case ActionList.sactionLabel:
                    a.visit(this);
                    break;

                case ActionList.sactionLineRecord:
                    if (debug != null)
                    {
                        debug.offset(writer.Pos, (LineRecord)a);
                    }
                    break;


                case ActionList.sactionRegisterRecord:
                    if (debug != null)
                    {
                        debug.registers(writer.Pos, (RegisterRecord)a);
                    }
                    break;

                // the remaining types need counting

                case flash.swf.ActionConstants_Fields.sactionPush:
                    i = encodePush((Push)a, i, actionList);
                    actionCount++;
                    break;

                default:
                    if (a.code < 0x80)
                    {
                        writer.writeUI8(a.code);
                    }
                    else
                    {
                        a.visit(this);
                    }
                    actionCount++;
                    break;
                }
            }

            patchForwardBranches();
        }
        /// <summary> encode a run of push actions into one action record.  The player
        /// supports this compact encoding since push is such a common
        /// opcode.  the format is:
        ///
        /// sactionPush type1 value1 type2 value2 ...
        ///
        /// </summary>
        /// <param name="push">
        /// </param>
        /// <param name="j">the index of the starting push action
        /// </param>
        /// <param name="actions">
        /// </param>
        /// <returns> the index of the last push action encoded.  the next action will
        /// not be a push action.
        /// </returns>
        public virtual int encodePush(Push push, int j, ActionList actions)
        {
            int updatePos = encodeActionHeader(push);

            do
            {
                System.Object value_Renamed = push.value_Renamed;
                int           type          = Push.getTypeCode(value_Renamed);
                writer.writeUI8(type);

                switch (type)
                {
                case 0:                          // string
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    writer.writeString(value_Renamed.ToString());
                    break;

                case 1:                          // float
                    //UPGRADE_ISSUE: Method 'java.lang.Float.floatToIntBits' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangFloatfloatToIntBits_float'"
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Float.floatValue' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    int bits = Float.floatToIntBits((float)((System.Single)value_Renamed));
                    writer.write32(bits);
                    break;

                case 2:                          // null
                    break;

                case 3:                          // undefined
                    break;

                case 4:                          // register
                    writer.writeUI8((int)((System.SByte)value_Renamed) & 0xFF);
                    break;

                case 5:                          // boolean
                    writer.writeUI8(((System.Boolean)value_Renamed)?1:0);
                    break;

                case 6:                          // double
                    double d = ((System.Double)value_Renamed);
                    //UPGRADE_ISSUE: Method 'java.lang.Double.doubleToLongBits' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangDoubledoubleToLongBits_double'"
                    long num = Double.doubleToLongBits(d);
                    writer.write32((int)(num >> 32));
                    writer.write32((int)num);
                    break;

                case 7:                          // integer
                    writer.write32(((System.Int32)value_Renamed));
                    break;

                case 8:                          // const8
                    writer.writeUI8((int)((System.Int16)value_Renamed));
                    break;

                case 9:                          // const16
                    writer.writeUI16((int)((System.Int16)value_Renamed) & 0xFFFF);
                    break;
                }

                if (debug == null)
                {
                    // ignore line records if we aren't debugging
                    while (j + 1 < actions.size() && actions.getAction(j + 1).code == ActionList.sactionLineRecord)
                    {
                        j++;
                    }
                }

                Action a;
                if (++j < actions.size() && (a = actions.getAction(j)).code == flash.swf.ActionConstants_Fields.sactionPush)
                {
                    push = (Push)a;
                }
                else
                {
                    push = null;
                }
            }while (push != null);
            updateActionHeader(updatePos);
            return(j - 1);
        }
Beispiel #3
0
		/// <summary> encode a run of push actions into one action record.  The player
		/// supports this compact encoding since push is such a common
		/// opcode.  the format is:
		/// 
		/// sactionPush type1 value1 type2 value2 ...
		/// 
		/// </summary>
		/// <param name="push">
		/// </param>
		/// <param name="j">the index of the starting push action
		/// </param>
		/// <param name="actions">
		/// </param>
		/// <returns> the index of the last push action encoded.  the next action will
		/// not be a push action.
		/// </returns>
		public virtual int encodePush(Push push, int j, ActionList actions)
		{
			int updatePos = encodeActionHeader(push);
			do 
			{
				System.Object value_Renamed = push.value_Renamed;
				int type = Push.getTypeCode(value_Renamed);
				writer.writeUI8(type);
				
				switch (type)
				{
					
					case 0:  // string
						//UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
						writer.writeString(value_Renamed.ToString());
						break;
					
					case 1:  // float
						//UPGRADE_ISSUE: Method 'java.lang.Float.floatToIntBits' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangFloatfloatToIntBits_float'"
						//UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Float.floatValue' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
						int bits = Float.floatToIntBits((float) ((System.Single) value_Renamed));
						writer.write32(bits);
						break;
					
					case 2:  // null
						break;
					
					case 3:  // undefined
						break;
					
					case 4:  // register
						writer.writeUI8((int) ((System.SByte) value_Renamed) & 0xFF);
						break;
					
					case 5:  // boolean
						writer.writeUI8(((System.Boolean) value_Renamed)?1:0);
						break;
					
					case 6:  // double
						double d = ((System.Double) value_Renamed);
						//UPGRADE_ISSUE: Method 'java.lang.Double.doubleToLongBits' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangDoubledoubleToLongBits_double'"
						long num = Double.doubleToLongBits(d);
						writer.write32((int) (num >> 32));
						writer.write32((int) num);
						break;
					
					case 7:  // integer
						writer.write32(((System.Int32) value_Renamed));
						break;
					
					case 8:  // const8
						writer.writeUI8((int) ((System.Int16) value_Renamed));
						break;
					
					case 9:  // const16
						writer.writeUI16((int) ((System.Int16) value_Renamed) & 0xFFFF);
						break;
					}
				
				if (debug == null)
				{
					// ignore line records if we aren't debugging
					while (j + 1 < actions.size() && actions.getAction(j + 1).code == ActionList.sactionLineRecord)
						j++;
				}
				
				Action a;
				if (++j < actions.size() && (a = actions.getAction(j)).code == flash.swf.ActionConstants_Fields.sactionPush)
				{
					push = (Push) a;
				}
				else
				{
					push = null;
				}
			}
			while (push != null);
			updateActionHeader(updatePos);
			return j - 1;
		}
Beispiel #4
0
		public virtual void  encode(ActionList actionList)
		{
			// write the actions
			for (int i = 0; i < actionList.size(); i++)
			{
				Action a = actionList.getAction(i);
				
				switch (a.code)
				{
					
					// don't update actionCount for synthetic opcodes
					case ActionList.sactionLabel: 
						a.visit(this);
						break;
					
					case ActionList.sactionLineRecord: 
						if (debug != null)
							debug.offset(writer.Pos, (LineRecord) a);
						break;
					
					
					case ActionList.sactionRegisterRecord: 
						if (debug != null)
							debug.registers(writer.Pos, (RegisterRecord) a);
						break;
						
						// the remaining types need counting
					
					case flash.swf.ActionConstants_Fields.sactionPush: 
						i = encodePush((Push) a, i, actionList);
						actionCount++;
						break;
					
					default: 
						if (a.code < 0x80)
							writer.writeUI8(a.code);
						else
							a.visit(this);
						actionCount++;
						break;
					
				}
			}
			
			patchForwardBranches();
		}
Beispiel #5
0
        public virtual void  export(Movie m)
        {
            // define the header
            Header h = new Header();

            h.version    = m.version;
            h.compressed = Header.useCompression(m.version);
            h.size       = m.size;
            h.rate       = m.framerate;

            handler.header(h);

            // movie-wide tags
            if (m.fileAttributes != null)
            {
                if (m.metadata != null)
                {
                    m.fileAttributes.hasMetadata = true;
                }

                m.fileAttributes.visit(handler);                 // FileAttributes MUST be first tag after header!
            }
            if (m.metadata != null)
            {
                m.metadata.visit(handler);
            }
            if (m.enableDebugger != null)
            {
                m.enableDebugger.visit(handler);
            }
            if (m.uuid != null)
            {
                new DebugID(m.uuid).visit(handler);
            }
            if (m.protect != null)
            {
                m.protect.visit(handler);
            }
            if (m.scriptLimits != null)
            {
                m.scriptLimits.visit(handler);
            }
            if (m.bgcolor != null)
            {
                m.bgcolor.visit(handler);
            }
            if (m.productInfo != null)
            {
                m.productInfo.visit(handler);
            }
            if (m.sceneAndFrameLabelData != null)
            {
                m.sceneAndFrameLabelData.visit(handler);
            }

            // finally, output the frames
            bool associateRootClass = (m.topLevelClass != null);

            //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
            for (System.Collections.IEnumerator i = m.frames.GetEnumerator(); i.MoveNext();)
            {
                //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                Frame frame = (Frame)i.Current;

                if (frame.label != null)
                {
                    frame.label.visit(handler);
                }

                if (!(frame.imports.Count == 0))
                {
                    //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
                    for (System.Collections.IEnumerator j = frame.imports.GetEnumerator(); j.MoveNext();)
                    {
                        //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                        ImportAssets importAssets = (ImportAssets)j.Current;
                        importAssets.visit(handler);
                    }
                }

                // definitions needed in this frame
                //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
                for (System.Collections.IEnumerator j = frame.References; j.MoveNext();)
                {
                    //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                    DefineTag ref_Renamed = (DefineTag)j.Current;
                    define(ref_Renamed);
                }

                // exports
                if (frame.hasExports())
                {
                    ExportAssets exportAssets = new ExportAssets();
                    //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
                    for (System.Collections.IEnumerator j = frame.exportIterator(); j.MoveNext();)
                    {
                        //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                        DefineTag tag = (DefineTag)j.Current;
                        exportAssets.exports.Add(tag);
                    }
                    exportAssets.visit(handler);
                }

                // TODO: Review this... temporarily special casing fonts here as they should not be
                // included in ExportAssets as they are not required to be exported by name!

                // fonts
                if (frame.hasFonts())
                {
                    //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
                    for (System.Collections.IEnumerator k = frame.fontsIterator(); k.MoveNext();)
                    {
                        //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                        DefineFont tag = (DefineFont)k.Current;

                        // We may have already visited this font because of symbolClasses.
                        if (!done.Contains(tag))
                        {
                            tag.visit(handler);
                            done.Add(tag);
                        }
                    }
                }

                // abc tags
                //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
                for (System.Collections.IEnumerator j = frame.doABCs.GetEnumerator(); j.MoveNext();)
                {
                    //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                    Tag tag = (Tag)j.Current;
                    tag.visit(handler);
                }

                SymbolClass classes = new SymbolClass();

                if (frame.hasSymbolClasses())
                {
                    SupportClass.MapSupport.PutAll(classes.class2tag, frame.symbolClass.class2tag);
                }
                if (associateRootClass)
                {
                    // only works on frame 1
                    classes.topLevelClass = m.topLevelClass;                     // Why do we do this on every frame's symclass?
                }
                if (associateRootClass || frame.hasSymbolClasses())
                {
                    classes.visit(handler);
                }
                associateRootClass = false;

                // control tags
                //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
                for (System.Collections.IEnumerator j = frame.controlTags.GetEnumerator(); j.MoveNext();)
                {
                    //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                    Tag tag = (Tag)j.Current;
                    tag.visit(handler);
                }

                // then frame actions
                //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
                for (System.Collections.IEnumerator j = frame.doActions.GetEnumerator(); j.MoveNext();)
                {
                    //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                    ActionList list = (ActionList)j.Current;
                    new DoAction(list).visit(handler);
                }

                // oh yeah, then showFrame!
                new ShowFrame().visit(handler);
            }

            handler.finish();
        }
Beispiel #6
0
		// Handy dandy for dumping an action list during debugging
		public static System.String actionListToString(ActionList al, System.String[] args)
		{
			// cut and paste arg code from main() could be better but it works
			bool showActions = true;
			bool showOffset = false;
			bool showDebugSource = false;
			bool decompile = false;
			bool defunc = true;
			bool tabbedGlyphs = true;
			int index = 0;
			
			while (args != null && (index < args.Length) && (args[index].StartsWith("-")))
			{
				if (args[index].Equals("-decompile"))
				{
					decompile = true;
					++index;
				}
				else if (args[index].Equals("-nofunctions"))
				{
					defunc = false;
					++index;
				}
				else if (args[index].Equals("-asm"))
				{
					decompile = false;
					++index;
				}
				else if (args[index].Equals("-noactions"))
				{
					showActions = false;
					++index;
				}
				else if (args[index].Equals("-showoffset"))
				{
					showOffset = true;
					++index;
				}
				else if (args[index].Equals("-showdebugsource"))
				{
					showDebugSource = true;
					++index;
				}
				else if (args[index].ToUpper().Equals("-tabbedGlyphs".ToUpper()))
				{
					tabbedGlyphs = true;
					++index;
				}
			}
			
			System.IO.StringWriter sw = new System.IO.StringWriter();
			//UPGRADE_ISSUE: Constructor 'java.io.PrintWriter.PrintWriter' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioPrintWriterPrintWriter_javaioWriter'"
			System.IO.StreamWriter out_Renamed = new PrintWriter(sw);
			SwfxPrinter printer = new SwfxPrinter(out_Renamed);
			printer.showActions = showActions;
			printer.showOffset = showOffset;
			printer.showDebugSource = showDebugSource;
			printer.decompile = decompile;
			printer.defunc = defunc;
			printer.tabbedGlyphs = tabbedGlyphs;
			
			printer.printActions(al);
			out_Renamed.Flush();
			return sw.ToString();
		}
Beispiel #7
0
		private void  printActions(ActionList list)
		{
			if (decompile)
			{
				/*
				AsNode node;
				try
				{
				node = new Decompiler(defunc).decompile(list);
				new PrettyPrinter(out, indent).list(node);
				return;
				}
				catch (Exception e)
				{
				indent();
				out.println("// error while decompiling.  falling back to disassembler");
				}
				*/
			}
			
			Disassembler disassembler = new Disassembler(out_Renamed, showOffset, indent_Renamed_Field);
			if (showDebugSource)
			{
				disassembler.ShowDebugSource = showDebugSource;
				disassembler.Comment = "// ";
			}
			list.visitAll(disassembler);
		}