Beispiel #1
0
 protected override void WriteBodyTo(FlashWriter output)
 {
     output.Write(Id);
     output.Write((uint)Data.Length);
     output.Write(Data);
     output.Write(AlphaData);
 }
Beispiel #2
0
 protected override void WriteValuesTo(FlashWriter output)
 {
     output.Write(DebugType);
     output.WriteInt30(NameIndex);
     output.Write(RegisterIndex);
     output.WriteInt30(Extra);
 }
Beispiel #3
0
        public byte[] ToByteArray()
        {
            using (var asMethodBody = new FlashWriter())
            {
                asMethodBody.Write7BitEncodedInt(MethodIndex);
                asMethodBody.Write7BitEncodedInt(MaxStack);
                asMethodBody.Write7BitEncodedInt(LocalCount);
                asMethodBody.Write7BitEncodedInt(InitialScopeDepth);
                asMethodBody.Write7BitEncodedInt(MaxScopeDepth);

                asMethodBody.Write7BitEncodedInt(Bytecode.Length);
                asMethodBody.Write(Bytecode);

                asMethodBody.Write7BitEncodedInt(Exceptions.Count);
                foreach (ASException exception in Exceptions)
                {
                    asMethodBody.Write(exception.ToByteArray());
                }

                asMethodBody.Write7BitEncodedInt(Traits.Count);
                foreach (ASTrait trait in Traits)
                {
                    asMethodBody.Write(trait.ToByteArray());
                }

                return(asMethodBody.ToArray());
            }
        }
Beispiel #4
0
        public override void WriteTo(FlashWriter output)
        {
            output.WriteInt30(Parameters.Count);
            output.WriteInt30(ReturnTypeIndex);

            int optionalParamCount      = 0;
            int optionalParamStartIndex = (Parameters.Count - 1);

            if (Parameters.Count > 0)
            {
                // This flag will be removed if at least a single parameter has no name assigned.
                Flags |= MethodFlags.HasParamNames;
                for (int i = 0; i < Parameters.Count; i++)
                {
                    ASParameter parameter = Parameters[i];
                    output.WriteInt30(parameter.TypeIndex);

                    // This flag should only be present when all parameters are assigned a Name.
                    if (string.IsNullOrWhiteSpace(parameter.Name))
                    {
                        Flags &= ~MethodFlags.HasParamNames;
                    }

                    // Just one optional parameter is enough to attain this flag.
                    if (parameter.IsOptional)
                    {
                        if (i < optionalParamStartIndex)
                        {
                            optionalParamStartIndex = i;
                        }

                        optionalParamCount++;
                        Flags |= MethodFlags.HasOptional;
                    }
                }
            }

            output.WriteInt30(NameIndex);
            output.Write((byte)Flags);
            if (Flags.HasFlag(MethodFlags.HasOptional))
            {
                output.WriteInt30(optionalParamCount);
                for (int i = optionalParamStartIndex; i < Parameters.Count; i++)
                {
                    ASParameter parameter = Parameters[i];
                    output.WriteInt30(parameter.ValueIndex);
                    output.Write((byte)parameter.ValueKind);
                }
            }

            if (Flags.HasFlag(MethodFlags.HasParamNames))
            {
                for (int i = 0; i < Parameters.Count; i++)
                {
                    ASParameter parameter = Parameters[i];
                    output.WriteInt30(parameter.NameIndex);
                }
            }
        }
Beispiel #5
0
 public byte[] ToByteArray()
 {
     using (var asMultiname = new FlashWriter())
     {
         asMultiname.Write((byte)MultinameType);
         asMultiname.Write(Data.ToByteArray());
         return(asMultiname.ToArray());
     }
 }
Beispiel #6
0
 protected override void WriteBodyTo(FlashWriter output)
 {
     output.Write(Id);
     output.WriteBits(4, Format);
     output.WriteBits(2, Rate);
     output.WriteBits(1, Size);
     output.WriteBits(1, SoundType);
     output.Write(SoundSampleCount);
     output.Write(SoundData);
 }
Beispiel #7
0
        protected override byte[] OnConstruct()
        {
            using (var tag = new FlashWriter(4))
            {
                tag.Write(MaxRecursionDepth);
                tag.Write(ScriptTimeoutSeconds);

                return(tag.ToArray());
            }
        }
        protected override void WriteBodyTo(FlashWriter output)
        {
            output.Write((ushort)Entries.Count);

            foreach (var pair in Entries)
            {
                output.Write(pair.Item1);
                output.WriteNullString(pair.Item2);
            }
        }
Beispiel #9
0
        protected override byte[] OnConstruct()
        {
            using (var tag = new FlashWriter())
            {
                tag.Write(Flags);
                tag.WriteNullTerminatedString(Name);
                tag.Write(ABC.ToByteArray());

                return(tag.ToArray());
            }
        }
Beispiel #10
0
        protected override byte[] OnConstruct()
        {
            using (var tag =
                       new FlashWriter(6 + BinaryData.Length))
            {
                tag.Write(CharacterId);
                tag.Position += 4;
                tag.Write(BinaryData);

                return(tag.ToArray());
            }
        }
Beispiel #11
0
        public override void WriteTo(FlashWriter output)
        {
            var bitContainer = (byte)(
                ((byte)Attributes << 4) + (byte)Kind);

            output.WriteInt30(QNameIndex);
            output.Write(bitContainer);
            output.WriteInt30(Id);
            switch (Kind)
            {
            case TraitKind.Slot:
            case TraitKind.Constant:
            {
                output.WriteInt30(TypeIndex);
                output.WriteInt30(ValueIndex);
                if (ValueIndex != 0)
                {
                    output.Write((byte)ValueKind);
                }
                break;
            }

            case TraitKind.Method:
            case TraitKind.Getter:
            case TraitKind.Setter:
            {
                output.WriteInt30(MethodIndex);
                break;
            }

            case TraitKind.Class:
            {
                output.WriteInt30(ClassIndex);
                break;
            }

            case TraitKind.Function:
            {
                output.WriteInt30(FunctionIndex);
                break;
            }
            }

            if (Attributes.HasFlag(TraitAttributes.Metadata))
            {
                output.WriteInt30(MetadataIndices.Count);
                for (int i = 0; i < MetadataIndices.Count; i++)
                {
                    int metadatumIndex = MetadataIndices[i];
                    output.WriteInt30(metadatumIndex);
                }
            }
        }
Beispiel #12
0
        protected override void WriteBodyTo(FlashWriter output)
        {
            int symbolCount = Math.Min(Ids.Count, Names.Count);

            output.Write((ushort)symbolCount);

            for (int i = 0; i < symbolCount; i++)
            {
                output.Write(Ids[i]);
                output.WriteNullString(Names[i]);
            }
        }
Beispiel #13
0
        public override void WriteTo(FlashWriter output)
        {
            var header = ((uint)Kind << 6);

            header |= (IsLongTag ? 63 : (uint)Length);

            output.Write((ushort)header);
            if (IsLongTag)
            {
                output.Write(Length);
            }
        }
Beispiel #14
0
 protected override byte[] OnConstruct()
 {
     using (var tag = new FlashWriter())
     {
         tag.Write((ushort)Assets.Count);
         foreach (KeyValuePair <ushort, string> pair in Assets)
         {
             tag.Write(pair.Key);
             tag.WriteNullTerminatedString(pair.Value);
         }
         return(tag.ToArray());
     }
 }
Beispiel #15
0
        public override void WriteTo(FlashWriter output)
        {
            output.Write((ushort)Version.Minor);
            output.Write((ushort)Version.Major);

            Pool.WriteTo(output);

            WriteTo(output, Methods);
            WriteTo(output, Metadata);
            WriteTo(output, Instances);
            WriteTo(output, Classes, false);
            WriteTo(output, Scripts);
            WriteTo(output, MethodBodies);
        }
Beispiel #16
0
        public virtual void Assemble(FlashWriter output, CompressionKind compression, Action <TagItem> callback)
        {
            output.Write(((char)compression) + "WS", true);
            output.Write(Version);
            output.Write(uint.MinValue);

            int         fileLength = 8;
            FlashWriter compressor = null;

            switch (compression)
            {
            case CompressionKind.LZMA:
            {
                compressor = new FlashWriter((int)FileLength);
                break;
            }

            case CompressionKind.ZLIB:
            {
                compressor = ZLIB.WrapCompressor(output.BaseStream, true);
                break;
            }
            }

            /* Body Start */
            Frame.WriteTo(compressor ?? output);
            fileLength += (Frame.Area.GetByteSize() + 4);
            for (int i = 0; i < Tags.Count; i++)
            {
                TagItem tag = Tags[i];
                callback?.Invoke(tag);
                WriteTag(tag, compressor ?? output);

                fileLength += tag.Header.Length;
                fileLength += (tag.Header.IsLongTag ? 6 : 2);
            }
            if (compression == CompressionKind.LZMA)
            {
                byte[] uncompressedBody = ((MemoryStream)compressor.BaseStream).ToArray();
                byte[] compressedBody   = LZMA.Compress(uncompressedBody);
                output.Write(compressedBody);
            }
            compressor?.Dispose();
            /* Body End */

            output.Position = 4;
            output.Write((uint)fileLength);
            output.Position = output.Length;
        }
Beispiel #17
0
        public byte[] ToByteArray()
        {
            using (var asConstants = new FlashWriter())
            {
                asConstants.Write7BitEncodedInt(_integers.Count);
                for (int i = 1; i < _integers.Count; i++)
                {
                    asConstants.Write7BitEncodedInt(_integers[i]);
                }

                asConstants.Write7BitEncodedInt(_uintegers.Count);
                for (int i = 1; i < _uintegers.Count; i++)
                {
                    asConstants.Write7BitEncodedInt((int)_uintegers[i]);
                }

                asConstants.Write7BitEncodedInt(_doubles.Count);
                for (int i = 1; i < _doubles.Count; i++)
                {
                    asConstants.Write(_doubles[i]);
                }

                asConstants.Write7BitEncodedInt(_strings.Count);
                for (int i = 1; i < _strings.Count; i++)
                {
                    asConstants.Write(_strings[i]);
                }

                asConstants.Write7BitEncodedInt(_namespaces.Count);
                for (int i = 1; i < _namespaces.Count; i++)
                {
                    asConstants.Write(_namespaces[i].ToByteArray());
                }

                asConstants.Write7BitEncodedInt(_namespaceSets.Count);
                for (int i = 1; i < _namespaceSets.Count; i++)
                {
                    asConstants.Write(_namespaceSets[i].ToByteArray());
                }

                asConstants.Write7BitEncodedInt(_multinames.Count);
                for (int i = 1; i < _multinames.Count; i++)
                {
                    asConstants.Write(_multinames[i].ToByteArray());
                }

                return(asConstants.ToArray());
            }
        }
Beispiel #18
0
        public byte[] ToByteArray()
        {
            using (var asInstance = new FlashWriter())
            {
                asInstance.Write7BitEncodedInt(TypeIndex);
                asInstance.Write7BitEncodedInt(SuperTypeIndex);
                asInstance.Write7BitEncodedInt((byte)ClassInfo);

                if ((ClassInfo & ClassFlags.ProtectedNamespace) != 0)
                {
                    asInstance.Write7BitEncodedInt(ProtectedNamespaceIndex);
                }

                asInstance.Write7BitEncodedInt(InterfaceIndices.Count);
                foreach (int index in InterfaceIndices)
                {
                    asInstance.Write7BitEncodedInt(index);
                }

                asInstance.Write7BitEncodedInt(ConstructorIndex);
                asInstance.Write7BitEncodedInt(Traits.Count);

                foreach (ASTrait trait in Traits)
                {
                    asInstance.Write(trait.ToByteArray());
                }

                return(asInstance.ToArray());
            }
        }
Beispiel #19
0
 public byte[] ToByteArray()
 {
     using (var asNamespace = new FlashWriter())
     {
         asNamespace.Write((byte)NamespaceType);
         asNamespace.Write7BitEncodedInt(ObjNameIndex);
         return(asNamespace.ToArray());
     }
 }
Beispiel #20
0
        public override void WriteTo(FlashWriter output)
        {
            output.Write((byte)Kind);
            switch (Kind)
            {
            case MultinameKind.QName:
            case MultinameKind.QNameA:
            {
                output.WriteInt30(NamespaceIndex);
                output.WriteInt30(NameIndex);
                break;
            }

            case MultinameKind.RTQName:
            case MultinameKind.RTQNameA:
            {
                output.WriteInt30(NameIndex);
                break;
            }

            case MultinameKind.RTQNameL:
            case MultinameKind.RTQNameLA:
            {
                /* No data. */
                break;
            }

            case MultinameKind.Multiname:
            case MultinameKind.MultinameA:
            {
                output.WriteInt30(NameIndex);
                output.WriteInt30(NamespaceSetIndex);
                break;
            }

            case MultinameKind.MultinameL:
            case MultinameKind.MultinameLA:
            {
                output.WriteInt30(NamespaceSetIndex);
                break;
            }

            case MultinameKind.TypeName:
            {
                output.WriteInt30(QNameIndex);
                output.WriteInt30(TypeIndices.Count);
                for (int i = 0; i < TypeIndices.Count; i++)
                {
                    int typeIndex = TypeIndices[i];
                    output.WriteInt30(typeIndex);
                }
                break;
            }
            }
        }
Beispiel #21
0
        protected override byte[] OnConstruct()
        {
            using (var tag = new FlashWriter())
            {
                tag.Write(FontId);
                tag.WriteNullTerminatedString(FontName);
                tag.WriteNullTerminatedString(FontCopyright);

                return(tag.ToArray());
            }
        }
Beispiel #22
0
        protected override byte[] OnConstruct()
        {
            if (_compressedBitmapData == null)
            {
                _compressedBitmapData =
                    ZlibStream.CompressBuffer(_bitmapData);
            }

            using (var tag =
                       new FlashWriter(7 + _compressedBitmapData.Length))
            {
                tag.Write(CharacterId);
                tag.Write(BitmapFormat);
                tag.Write(BitmapWidth);
                tag.Write(BitmapHeight);
                tag.Write(_compressedBitmapData);

                return(tag.ToArray());
            }
        }
Beispiel #23
0
        public byte[] ToByteArray()
        {
            using (var abcFile = new FlashWriter())
            {
                abcFile.Write(MinorVersion);
                abcFile.Write(MajorVersion);
                abcFile.Write(Constants.ToByteArray());

                abcFile.Write7BitEncodedInt(Methods.Count);
                foreach (ASMethod methodInfo in Methods)
                {
                    abcFile.Write(methodInfo.ToByteArray());
                }

                abcFile.Write7BitEncodedInt(Metadata.Count);
                foreach (ASMetadata metadataInfo in Metadata)
                {
                    abcFile.Write(metadataInfo.ToByteArray());
                }

                abcFile.Write7BitEncodedInt(Instances.Count);
                foreach (ASInstance instanceInfo in Instances)
                {
                    abcFile.Write(instanceInfo.ToByteArray());
                }

                foreach (ASClass classInfo in Classes)
                {
                    abcFile.Write(classInfo.ToByteArray());
                }

                abcFile.Write7BitEncodedInt(Scripts.Count);
                foreach (ASScript scriptInfo in Scripts)
                {
                    abcFile.Write(scriptInfo.ToByteArray());
                }

                abcFile.Write7BitEncodedInt(MethodBodies.Count);
                foreach (ASMethodBody methodBodyInfo in MethodBodies)
                {
                    abcFile.Write(methodBodyInfo.ToByteArray());
                }

                return(abcFile.ToArray());
            }
        }
Beispiel #24
0
        protected override byte[] OnConstruct()
        {
            using (var tag = new FlashWriter())
            {
                tag.Position = 2;
                ushort symbolCount = 0;
                foreach (KeyValuePair <ushort, string> symbol in Symbols)
                {
                    string[] symbolNames = symbol.Value.Split(',');
                    foreach (string symbolName in symbolNames)
                    {
                        symbolCount++;
                        tag.Write(symbol.Key);
                        tag.WriteNullTerminatedString(symbol.Value);
                    }
                }
                tag.Position = 0;
                tag.Write(symbolCount);

                return(tag.ToArray());
            }
        }
Beispiel #25
0
        /// <summary>
        /// Reconstructs the Shockwave Flash(SWF) file using the tags from <see cref="Tags"/>.
        /// </summary>
        public byte[] Reconstruct()
        {
            using (var flash = new FlashWriter())
            {
                flash.WriteUTF8SimpleString("FWS");
                flash.Write(Version);

                flash.Position += 4;
                flash.Write(_frameData);

                foreach (FlashTag tag in Tags)
                {
                    flash.Write(tag.ToArray());
                }

                flash.Position = 4;
                flash.Write(flash.Length);

                _flashData = flash.ToArray();
                Reader.ResetBuffer(_flashData);
                return(_flashData);
            }
        }
Beispiel #26
0
        public byte[] ToByteArray()
        {
            using (var asTrait = new FlashWriter())
            {
                var trueKind = (byte)((
                                          (byte)Attributes << 4) + (byte)TraitType);

                asTrait.Write7BitEncodedInt(TypeIndex);
                asTrait.Write(trueKind);
                asTrait.Write(Data.ToByteArray());

                if ((Attributes & TraitAttributes.Metadata) != 0)
                {
                    asTrait.Write7BitEncodedInt(MetadataIndices.Count);

                    foreach (int index in MetadataIndices)
                    {
                        asTrait.Write7BitEncodedInt(index);
                    }
                }
                return(asTrait.ToArray());
            }
        }
Beispiel #27
0
        public byte[] ToByteArray()
        {
            using (var asMethod = new FlashWriter())
            {
                asMethod.Write7BitEncodedInt(Parameters.Count);
                asMethod.Write7BitEncodedInt(ReturnTypeIndex);

                foreach (ASParameter parameter in Parameters)
                {
                    asMethod.Write7BitEncodedInt(parameter.TypeIndex);
                }

                asMethod.Write7BitEncodedInt(NameIndex);
                asMethod.Write7BitEncodedInt((byte)MethodInfo);

                if ((MethodInfo & MethodFlags.HasOptional) != 0)
                {
                    int    optionalParamCount = 0;
                    byte[] optionalParamData  = null;
                    using (var opParam = new FlashWriter())
                    {
                        for (int i = 0; i < Parameters.Count; i++)
                        {
                            if (!Parameters[i].IsOptional)
                            {
                                continue;
                            }

                            optionalParamCount++;
                            opParam.Write7BitEncodedInt(Parameters[i].ValueIndex);
                            opParam.Write((byte)Parameters[i].ValueType);
                        }
                        optionalParamData = opParam.ToArray();
                    }

                    asMethod.Write7BitEncodedInt(optionalParamCount);
                    asMethod.Write(optionalParamData);
                }

                if ((MethodInfo & MethodFlags.HasParamNames) != 0)
                {
                    foreach (ASParameter parameter in Parameters)
                    {
                        asMethod.Write7BitEncodedInt(parameter.ObjNameIndex);
                    }
                }
                return(asMethod.ToArray());
            }
        }
        protected override void WriteBodyTo(FlashWriter output)
        {
            output.Write((uint)Product);
            output.Write((uint)Edition);
            output.Write(MajorVersion);
            output.Write(MinorVersion);
            output.Write(BuildLow);
            output.Write(BuildHigh);

            TimeSpan sinceEpoch = (CompilationDate - FlashTools.Epoch);

            output.Write((ulong)sinceEpoch.TotalMilliseconds);
        }
Beispiel #29
0
        public byte[] ToByteArray()
        {
            using (var asScript = new FlashWriter())
            {
                asScript.Write7BitEncodedInt(FunctionIndex);
                asScript.Write7BitEncodedInt(Traits.Count);

                foreach (ASTrait trait in Traits)
                {
                    asScript.Write(trait.ToByteArray());
                }

                return(asScript.ToArray());
            }
        }
Beispiel #30
0
        public byte[] ToByteArray()
        {
            using (var asClass = new FlashWriter())
            {
                asClass.Write7BitEncodedInt(ConstructorIndex);
                asClass.Write7BitEncodedInt(Traits.Count);

                foreach (ASTrait trait in Traits)
                {
                    asClass.Write(trait.ToByteArray());
                }

                return(asClass.ToArray());
            }
        }