Пример #1
0
 public SetBackgroundColorTag(HeaderRecord header, FlashReader input)
     : base(header)
 {
     R = input.ReadByte();
     G = input.ReadByte();
     B = input.ReadByte();
 }
Пример #2
0
 public DebugIns(ABCFile abc, FlashReader input)
     : this(abc)
 {
     DebugType     = input.ReadByte();
     NameIndex     = input.ReadInt30();
     RegisterIndex = input.ReadByte();
     Extra         = input.ReadInt30();
 }
        public SetBackgroundColorTag(HeaderRecord header, FlashReader input)
            : base(header)
        {
            byte r = input.ReadByte();
            byte g = input.ReadByte();
            byte b = input.ReadByte();

            BackgroundColor = Color.FromArgb(r, g, b);
        }
Пример #4
0
        public ASTrait(ABCFile abc, FlashReader input)
            : this(abc)
        {
            QNameIndex = input.ReadInt30();

            byte bitContainer = input.ReadByte();
            Kind       = (TraitKind)(bitContainer & 0x0F);
            Attributes = (TraitAttributes)(bitContainer >> 4);

            Id = input.ReadInt30();
            switch (Kind)
            {
            case TraitKind.Slot:
            case TraitKind.Constant:
            {
                TypeIndex  = input.ReadInt30();
                ValueIndex = input.ReadInt30();
                if (ValueIndex != 0)
                {
                    ValueKind = (ConstantKind)input.ReadByte();
                }
                break;
            }

            case TraitKind.Method:
            case TraitKind.Getter:
            case TraitKind.Setter:
            {
                MethodIndex  = input.ReadInt30();
                Method.Trait = this;
                break;
            }

            case TraitKind.Class:
            {
                ClassIndex = input.ReadInt30();
                break;
            }

            case TraitKind.Function:
            {
                FunctionIndex = input.ReadInt30();
                break;
            }
            }

            if (Attributes.HasFlag(TraitAttributes.Metadata))
            {
                MetadataIndices.Capacity = input.ReadInt30();
                for (int i = 0; i < MetadataIndices.Capacity; i++)
                {
                    int metadatumIndex = input.ReadInt30();
                    MetadataIndices.Add(metadatumIndex);
                }
            }
        }
Пример #5
0
        public SetBackgroundColorTag(FlashReader reader, TagRecord header) :
            base(reader, header)
        {
            byte red   = reader.ReadByte();
            byte green = reader.ReadByte();
            byte blue  = reader.ReadByte();

            BackgroundColor =
                Color.FromArgb(red, green, blue);
        }
Пример #6
0
        public ProductInfoTag(FlashReader reader, TagRecord header) :
            base(reader, header)
        {
            ProductId = (FlashProductId)reader.ReadUInt32();
            Edition   = (FlashEdition)reader.ReadUInt32();

            MajorVersion = reader.ReadByte();
            MinorVersion = reader.ReadByte();

            BuildLow  = reader.ReadUInt32();
            BuildHigh = reader.ReadUInt32();

            CompilationDate =
                _epoch.AddMilliseconds(reader.ReadUInt64());
        }
Пример #7
0
        public ProductInfoTag(HeaderRecord header, FlashReader input)
            : base(header)
        {
            Product = (FlashProduct)input.ReadUInt32();
            Edition = (FlashEdition)input.ReadUInt32();

            MajorVersion = input.ReadByte();
            MinorVersion = input.ReadByte();

            BuildLow  = input.ReadUInt32();
            BuildHigh = input.ReadUInt32();

            CompilationDate = FlashTools.Epoch
                              .AddMilliseconds(input.ReadUInt64());
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShockwaveFlash"/> class based on the specified array of bytes.
        /// </summary>
        /// <param name="data">The data containing the raw Shockwave Flash(SWF) file.</param>
        public ShockwaveFlash(byte[] data)
        {
            _flashData = data;
            _abcFiles  = new List <ABCFile>();

            Reader     = new FlashReader(data);
            Tags       = new List <FlashTag>();
            Dictionary = new FlashDictionary();

            Signature    = Reader.ReadString(3);
            CompressWith = (CompressionStandard)Signature[0];

            Version    = Reader.ReadByte();
            FileLength = Reader.ReadUInt32();

            if (CompressWith ==
                CompressionStandard.None)
            {
                ReadFrameInformation();
            }
            else
            {
                IsCompressed = true;
            }
        }
        public DefineBitsLossless2Tag(HeaderRecord header, FlashReader input) : base(header)
        {
            Id     = input.ReadUInt16();
            Format = input.ReadByte();
            Width  = input.ReadUInt16();
            Height = input.ReadUInt16();

            if (Format == Format8BitColormapped)
            {
                ColorTableSize = input.ReadByte();
            }

            var readSize = 7 + (Format == Format8BitColormapped ? 1 : 0);

            _zlibData = input.ReadBytes(header.Length - readSize);
        }
Пример #10
0
        protected ShockwaveFlash(FlashReader input)
            : this(false)
        {
            Compression = (CompressionKind)input.ReadString(3)[0];
            Version     = input.ReadByte();
            FileLength  = input.ReadUInt32();

            switch (Compression)
            {
            case CompressionKind.LZMA:
            {
                byte[] decompressed = LZMA.Decompress(input.BaseStream, ((int)FileLength - 8));
                _input = new FlashReader(decompressed);
                break;
            }

            case CompressionKind.ZLIB:
            {
                _input = ZLIB.WrapDecompressor(input.BaseStream);
                break;
            }

            case CompressionKind.None:
            {
                _input = input;
                break;
            }
            }
            Frame = new FrameRecord(_input);
        }
Пример #11
0
        public ASInstance(ABCFile abc, FlashReader reader)
            : this(abc)
        {
            TypeIndex      = reader.Read7BitEncodedInt();
            SuperTypeIndex = reader.Read7BitEncodedInt();
            ClassInfo      = (ClassFlags)reader.ReadByte();

            if ((ClassInfo & ClassFlags.ProtectedNamespace) != 0)
            {
                ProtectedNamespaceIndex = reader.Read7BitEncodedInt();
            }

            InterfaceIndices.Capacity = reader.Read7BitEncodedInt();
            for (int i = 0; i < InterfaceIndices.Capacity; i++)
            {
                InterfaceIndices.Add(reader.Read7BitEncodedInt());
            }

            ConstructorIndex = reader.Read7BitEncodedInt();
            if (Constructor != null)
            {
                Constructor.IsConstructor = true;
            }

            Traits.Capacity = reader.Read7BitEncodedInt();
            for (int i = 0; i < Traits.Capacity; i++)
            {
                Traits.Add(new ASTrait(abc, reader));
            }
        }
Пример #12
0
        public ASInstance(ABCFile abc, FlashReader input)
            : this(abc)
        {
            QNameIndex = input.ReadInt30();
            SuperIndex = input.ReadInt30();
            Flags      = (ClassFlags)input.ReadByte();

            if (Flags.HasFlag(ClassFlags.ProtectedNamespace))
            {
                ProtectedNamespaceIndex = input.ReadInt30();
            }

            InterfaceIndices.Capacity = input.ReadInt30();
            for (int i = 0; i < InterfaceIndices.Capacity; i++)
            {
                int interfaceIndex = input.ReadInt30();
                InterfaceIndices.Add(interfaceIndex);
            }

            ConstructorIndex          = input.ReadInt30();
            Constructor.IsConstructor = true;
            Constructor.Container     = this;

            PopulateTraits(input);
        }
Пример #13
0
        public DefineBitsLossless2Tag(HeaderRecord header, FlashReader input)
            : base(header)
        {
            Id      = input.ReadUInt16();
            _format = input.ReadByte();

            _width  = input.ReadUInt16();
            _height = input.ReadUInt16();

            if (_format == 3)
            {
                _colorTableSize = input.ReadByte();
            }

            int partialLength = (7 + (_format == 3 ? 1 : 0));

            _compressedBitmapData = input.ReadBytes(header.Length - partialLength);
        }
Пример #14
0
        public ASMultiname(ASConstantPool pool, FlashReader input)
            : this(pool)
        {
            Kind = (MultinameKind)input.ReadByte();
            switch (Kind)
            {
            case MultinameKind.QName:
            case MultinameKind.QNameA:
            {
                NamespaceIndex = input.ReadInt30();
                NameIndex      = input.ReadInt30();
                break;
            }

            case MultinameKind.RTQName:
            case MultinameKind.RTQNameA:
            {
                NameIndex = input.ReadInt30();
                break;
            }

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

            case MultinameKind.Multiname:
            case MultinameKind.MultinameA:
            {
                NameIndex         = input.ReadInt30();
                NamespaceSetIndex = input.ReadInt30();
                break;
            }

            case MultinameKind.MultinameL:
            case MultinameKind.MultinameLA:
            {
                NamespaceSetIndex = input.ReadInt30();
                break;
            }

            case MultinameKind.TypeName:
            {
                QNameIndex           = input.ReadInt30();
                TypeIndices.Capacity = input.ReadInt30();
                for (int i = 0; i < TypeIndices.Capacity; i++)
                {
                    int typeIndex = input.ReadInt30();
                    TypeIndices.Add(typeIndex);
                }
                break;
            }
            }
        }
Пример #15
0
 public ASNamespace(ASConstantPool pool, FlashReader input)
     : base(pool)
 {
     Kind = (NamespaceKind)input.ReadByte();
     if (!Enum.IsDefined(typeof(NamespaceKind), Kind))
     {
         throw new InvalidCastException($"Invalid namespace kind for value {Kind:0x00}.");
     }
     NameIndex = input.ReadInt30();
 }
Пример #16
0
        public DefineBitsLossless2Tag(HeaderRecord header, FlashReader input)
            : base(header)
        {
            Id      = input.ReadUInt16();
            _format = input.ReadByte();

            ushort width  = input.ReadUInt16();
            ushort height = input.ReadUInt16();

            _argbMap = new Color[width, height];

            if (_format == 3)
            {
                _colorTableSize = input.ReadByte();
            }

            int partialLength = (7 + (_format == 3 ? 1 : 0));

            _compressedData = input.ReadBytes(header.Length - partialLength);
        }
Пример #17
0
        public ASMethod(ABCFile abc, FlashReader reader)
            : this(abc)
        {
            Parameters.Capacity = reader.Read7BitEncodedInt();
            ReturnTypeIndex     = reader.Read7BitEncodedInt();

            for (int i = 0; i < Parameters.Capacity; i++)
            {
                int parameterTypeIndex = reader.Read7BitEncodedInt();

                var parameter = new ASParameter(abc, parameterTypeIndex);
                Parameters.Add(parameter);

                parameter.Rank = Parameters.Count;
            }

            NameIndex  = reader.Read7BitEncodedInt();
            MethodInfo = (MethodFlags)reader.ReadByte();

            if (MethodInfo.HasFlag(MethodFlags.HasOptional))
            {
                int optionalParamCount = reader.Read7BitEncodedInt();
                while (optionalParamCount > 0)
                {
                    int         paramIndex        = ((Parameters.Count - 1) - (--optionalParamCount));
                    ASParameter optionalParameter = Parameters[paramIndex];

                    optionalParameter.IsOptional = true;
                    optionalParameter.ValueIndex = reader.Read7BitEncodedInt();
                    optionalParameter.ValueType  = (ConstantType)reader.ReadByte();
                }
            }

            if (MethodInfo.HasFlag(MethodFlags.HasParamNames))
            {
                foreach (ASParameter parameter in Parameters)
                {
                    parameter.ObjNameIndex = reader.Read7BitEncodedInt();
                }
            }
        }
Пример #18
0
        public SlotConstantTrait(ABCFile abc, FlashReader reader, TraitType traitType)
            : this(abc, traitType)
        {
            SlotId     = reader.Read7BitEncodedInt();
            TypeIndex  = reader.Read7BitEncodedInt();
            ValueIndex = reader.Read7BitEncodedInt();

            if (ValueIndex != 0)
            {
                ValueType = (ConstantType)reader.ReadByte();
            }
        }
Пример #19
0
        public ASMethod(ABCFile abc, FlashReader input)
            : this(abc)
        {
            Parameters.Capacity = input.ReadInt30();
            ReturnTypeIndex     = input.ReadInt30();

            for (int i = 0; i < Parameters.Capacity; i++)
            {
                var parameter = new ASParameter(abc, this);
                parameter.TypeIndex = input.ReadInt30();
                Parameters.Add(parameter);
            }

            NameIndex = input.ReadInt30();
            Flags     = (MethodFlags)input.ReadByte();

            if (Flags.HasFlag(MethodFlags.HasOptional))
            {
                int optionalParamCount = input.ReadInt30();
                for (int i = (Parameters.Count - optionalParamCount);
                     optionalParamCount > 0;
                     i++, optionalParamCount--)
                {
                    ASParameter parameter = Parameters[i];
                    parameter.IsOptional = true;
                    parameter.ValueIndex = input.ReadInt30();
                    parameter.ValueKind  = (ConstantKind)input.ReadByte();
                }
            }

            if (Flags.HasFlag(MethodFlags.HasParamNames))
            {
                for (int i = 0; i < Parameters.Count; i++)
                {
                    ASParameter parameter = Parameters[i];
                    parameter.NameIndex = input.ReadInt30();
                }
            }
        }
Пример #20
0
        public ASMultiname(ABCFile abc, FlashReader reader)
            : this(abc)
        {
            var multinameType = (ConstantType)reader.ReadByte();
            switch (multinameType)
            {
            case ConstantType.QName:
            case ConstantType.QNameA:
            {
                var qName = new QName(abc, reader, multinameType);
                ObjNameIndex = qName.ObjNameIndex;
                Data         = qName;
                break;
            }

            case ConstantType.RTQName:
            case ConstantType.RTQNameA:
            {
                var rtqName = new RTQName(abc, reader, multinameType);
                ObjNameIndex = rtqName.ObjNameIndex;
                Data         = rtqName;
                break;
            }

            case ConstantType.RTQNameL:
            case ConstantType.RTQNameLA:
                Data = new RTQNameL(abc, multinameType);
                break;

            case ConstantType.Multiname:
            case ConstantType.MultinameA:
            {
                var multiname = new Multiname(abc, reader, multinameType);
                ObjNameIndex = multiname.ObjNameIndex;
                Data         = multiname;
                break;
            }

            case ConstantType.MultinameL:
            case ConstantType.MultinameLA:
                Data = new MultinameL(abc, reader, multinameType);
                break;

            case ConstantType.Typename:
                Data = new Typename(abc, reader);
                break;

            default:
                throw new Exception("Invalid multiname: " + multinameType);
            }
        }
Пример #21
0
        public DefineBitsLossless2Tag(FlashReader reader, TagRecord header) :
            base(reader, header)
        {
            CharacterId  = reader.ReadUInt16();
            BitmapFormat = reader.ReadByte();
            BitmapWidth  = reader.ReadUInt16();
            BitmapHeight = reader.ReadUInt16();

            _isCompressed = true;
            switch (BitmapFormat - 3)
            {
            case 0: break;

            case 1:
            case 2:
            {
                _compressedBitmapData =
                    reader.ReadBytes(header.Body.Length - 7);

                break;
            }
            }
        }
Пример #22
0
 public PushByteIns(FlashReader input)
     : this()
 {
     Value = input.ReadByte();
 }
Пример #23
0
        public static ASInstruction Create(ABCFile abc, FlashReader input)
        {
            var op = (OPCode)input.ReadByte();

            switch (op)
            {
                #region Arithmetic
            case OPCode.Add_i:
                return(new AddIIns());

            case OPCode.Add:
                return(new AddIns());

            case OPCode.Decrement_i:
                return(new DecrementIIns());

            case OPCode.Decrement:
                return(new DecrementIns());

            case OPCode.Divide:
                return(new DivideIns());

            case OPCode.Equals:
                return(new EqualsIns());

            case OPCode.GreaterEquals:
                return(new GreaterEqualsIns());

            case OPCode.GreaterThan:
                return(new GreaterThanIns());

            case OPCode.Increment_i:
                return(new IncrementIIns());

            case OPCode.Increment:
                return(new IncrementIns());

            case OPCode.In:
                return(new InIns());

            case OPCode.IsTypeLate:
                return(new IsTypeLateIns());

            case OPCode.LessEquals:
                return(new LessEqualsIns());

            case OPCode.LessThan:
                return(new LessThanIns());

            case OPCode.Modulo:
                return(new ModuloIns());

            case OPCode.Multiply_i:
                return(new MultiplyIIns());

            case OPCode.Multiply:
                return(new MultiplyIns());

            case OPCode.Negate_i:
                return(new NegateIIns());

            case OPCode.Negate:
                return(new NegateIns());

            case OPCode.StrictEquals:
                return(new StrictEqualsIns());

            case OPCode.Subtract_i:
                return(new SubtractIIns());

            case OPCode.Subtract:
                return(new SubtractIns());

                #endregion

                #region Bit Manipulation
            case OPCode.BitAnd:
                return(new BitAndIns());

            case OPCode.BitNot:
                return(new BitNotIns());

            case OPCode.BitOr:
                return(new BitOrIns());

            case OPCode.BitXor:
                return(new BitXorIns());

            case OPCode.LShift:
                return(new LShiftIns());

            case OPCode.RShift:
                return(new RShiftIns());

            case OPCode.URShift:
                return(new URShiftIns());

                #endregion

                #region Control Transfer
            case OPCode.IfEq:
                return(new IfEqualIns(input));

            case OPCode.IfFalse:
                return(new IfFalseIns(input));

            case OPCode.IfGe:
                return(new IfGreaterEqualIns(input));

            case OPCode.IfGt:
                return(new IfGreaterThanIns(input));

            case OPCode.IfLe:
                return(new IfLessEqualIns(input));

            case OPCode.IfLt:
                return(new IfLessThanIns(input));

            case OPCode.IfNe:
                return(new IfNotEqualIns(input));

            case OPCode.IfNGe:
                return(new IfNotGreaterEqualIns(input));

            case OPCode.IfNGt:
                return(new IfNotGreaterThanIns(input));

            case OPCode.IfNLe:
                return(new IfNotLessEqualIns(input));

            case OPCode.IfNLt:
                return(new IfNotLessThanIns(input));

            case OPCode.IfStrictEq:
                return(new IfStrictEqualIns(input));

            case OPCode.IfStrictNE:
                return(new IfStrictNotEqualIns(input));

            case OPCode.IfTrue:
                return(new IfTrueIns(input));

            case OPCode.Jump:
                return(new JumpIns(input));

                #endregion

                #region Register Management
            case OPCode.DecLocal_i:
                return(new DecLocalIIns(input));

            case OPCode.DecLocal:
                return(new DecLocalIns(input));

            case OPCode.GetLocal_0:
                return(new GetLocal0Ins());

            case OPCode.GetLocal_1:
                return(new GetLocal1Ins());

            case OPCode.GetLocal_2:
                return(new GetLocal2Ins());

            case OPCode.GetLocal_3:
                return(new GetLocal3Ins());

            case OPCode.GetLocal:
                return(new GetLocalIns(input));

            case OPCode.IncLocal_i:
                return(new IncLocalIIns(input));

            case OPCode.IncLocal:
                return(new IncLocalIns(input));

            case OPCode.Kill:
                return(new KillIns(input));

            case OPCode.SetLocal_0:
                return(new SetLocal0Ins());

            case OPCode.SetLocal_1:
                return(new SetLocal1Ins());

            case OPCode.SetLocal_2:
                return(new SetLocal2Ins());

            case OPCode.SetLocal_3:
                return(new SetLocal3Ins());

            case OPCode.SetLocal:
                return(new SetLocalIns(input));

                #endregion

                #region Stack Management
            case OPCode.PushByte:
                return(new PushByteIns(input));

            case OPCode.PushDouble:
                return(new PushDoubleIns(abc, input));

            case OPCode.PushFalse:
                return(new PushFalseIns());

            case OPCode.PushInt:
                return(new PushIntIns(abc, input));

            case OPCode.PushNan:
                return(new PushNaNIns());

            case OPCode.PushNull:
                return(new PushNullIns());

            case OPCode.PushShort:
                return(new PushShortIns(input));

            case OPCode.PushString:
                return(new PushStringIns(abc, input));

            case OPCode.PushTrue:
                return(new PushTrueIns());

            case OPCode.PushUInt:
                return(new PushUIntIns(abc, input));

                #endregion

                #region Type Conversion
            case OPCode.Coerce_a:
                return(new CoerceAIns());

            case OPCode.Coerce:
                return(new CoerceIns(abc, input));

            case OPCode.Coerce_s:
                return(new CoerceSIns());

            case OPCode.Convert_b:
                return(new ConvertBIns());

            case OPCode.Convert_d:
                return(new ConvertDIns());

            case OPCode.Convert_i:
                return(new ConvertIIns());

            case OPCode.Convert_o:
                return(new ConvertOIns());

            case OPCode.Convert_s:
                return(new ConvertSIns());

            case OPCode.Convert_u:
                return(new ConvertUIns());

                #endregion

                #region Miscellaneous
            case OPCode.ApplyType:
                return(new ApplyTypeIns(input));

            case OPCode.AsType:
                return(new AsTypeIns(abc, input));

            case OPCode.AsTypeLate:
                return(new AsTypeLateIns());

            case OPCode.Call:
                return(new CallIns(input));

            case OPCode.CallMethod:
                return(new CallMethodIns(abc, input));

            case OPCode.CallProperty:
                return(new CallPropertyIns(abc, input));

            case OPCode.CallPropLex:
                return(new CallPropLexIns(abc, input));

            case OPCode.CallPropVoid:
                return(new CallPropVoidIns(abc, input));

            case OPCode.CallStatic:
                return(new CallStaticIns(abc, input));

            case OPCode.CallSuper:
                return(new CallSuperIns(abc, input));

            case OPCode.CallSuperVoid:
                return(new CallSuperVoidIns(abc, input));

            case OPCode.CheckFilter:
                return(new CheckFilterIns());

            case OPCode.Construct:
                return(new ConstructIns(input));

            case OPCode.ConstructProp:
                return(new ConstructPropIns(abc, input));

            case OPCode.ConstructSuper:
                return(new ConstructSuperIns(input));

            case OPCode.DebugFile:
                return(new DebugFileIns(abc, input));

            case OPCode.Debug:
                return(new DebugIns(abc, input));

            case OPCode.DebugLine:
                return(new DebugLineIns(input));

            case OPCode.DeleteProperty:
                return(new DeletePropertyIns(abc, input));

            case OPCode.Dup:
                return(new DupIns());

            case OPCode.Dxns:
                return(new DxnsIns(abc, input));

            case OPCode.DxnsLate:
                return(new DxnsLateIns());

            case OPCode.Esc_XElem:
                return(new EscXElemIns());

            case OPCode.Esc_XAttr:
                return(new EscXAttrIns());

            case OPCode.FindProperty:
                return(new FindPropertyIns(abc, input));

            case OPCode.FindPropStrict:
                return(new FindPropStrictIns(abc, input));

            case OPCode.GetDescendants:
                return(new GetDescendantsIns(abc, input));

            case OPCode.GetGlobalScope:
                return(new GetGlobalScopeIns());

            case OPCode.GetLex:
                return(new GetLexIns(abc, input));

            case OPCode.GetProperty:
                return(new GetPropertyIns(abc, input));

            case OPCode.GetScopeObject:
                return(new GetScopeObjectIns(input));

            case OPCode.GetSlot:
                return(new GetSlotIns(input));

            case OPCode.GetSuper:
                return(new GetSuperIns(abc, input));

            case OPCode.HasNext2:
                return(new HasNext2Ins(input));

            case OPCode.HasNext:
                return(new HasNextIns());

            case OPCode.InitProperty:
                return(new InitPropertyIns(abc, input));

            case OPCode.InstanceOf:
                return(new InstanceOfIns());

            case OPCode.Label:
                return(new LabelIns());

            case OPCode.LookUpSwitch:
                return(new LookUpSwitchIns(input));

            case OPCode.NewActivation:
                return(new NewActivationIns());

            case OPCode.NewArray:
                return(new NewArrayIns(input));

            case OPCode.NewCatch:
                return(new NewCatchIns(input));

            case OPCode.NewClass:
                return(new NewClassIns(abc, input));

            case OPCode.NewFunction:
                return(new NewFunctionIns(abc, input));

            case OPCode.NewObject:
                return(new NewObjectIns(input));

            case OPCode.NextName:
                return(new NextNameIns());

            case OPCode.NextValue:
                return(new NextValueIns());

            case OPCode.Nop:
                return(new NopIns());

            case OPCode.Not:
                return(new NotIns());

            case OPCode.Pop:
                return(new PopIns());

            case OPCode.PopScope:
                return(new PopScopeIns());

            case OPCode.PushScope:
                return(new PushScopeIns());

            case OPCode.PushUndefined:
                return(new PushUndefinedIns());

            case OPCode.PushWith:
                return(new PushWithIns());

            case OPCode.ReturnValue:
                return(new ReturnValueIns());

            case OPCode.ReturnVoid:
                return(new ReturnVoidIns());

            case OPCode.SetProperty:
                return(new SetPropertyIns(abc, input));

            case OPCode.SetSlot:
                return(new SetSlotIns(input));

            case OPCode.SetSuper:
                return(new SetSuperIns(abc, input));

            case OPCode.Swap:
                return(new SwapIns());

            case OPCode.Throw:
                return(new ThrowIns());

            case OPCode.TypeOf:
                return(new TypeOfIns());

                #endregion
            }
            throw new Exception("Unhandled OPCode: " + op);
        }
Пример #24
0
        public bool FindMessageInstances()
        {
            if (OutgoingTypes.Count > 0 &&
                IncomingTypes.Count > 0)
            {
                return(true);
            }

            ABCFile abc           = ABCFiles[2];
            ASClass habboMessages = abc.FindClassByName("HabboMessages");

            if (habboMessages == null || habboMessages.Traits.Count < 2)
            {
                return(false);
            }

            ASTrait incomingMap = habboMessages.Traits[0];
            ASTrait outgoingMap = habboMessages.Traits[1];

            using (var mapReader = new FlashReader(
                       habboMessages.Constructor.Body.Bytecode.ToArray()))
            {
                while (mapReader.Position != mapReader.Length)
                {
                    OPCode op = mapReader.ReadOP();
                    if (op != OPCode.GetLex)
                    {
                        continue;
                    }

                    int  mapTypeIndex = mapReader.Read7BitEncodedInt();
                    bool isOutgoing   = (mapTypeIndex == outgoingMap.TypeIndex);
                    bool isIncoming   = (mapTypeIndex == incomingMap.TypeIndex);
                    if (!isOutgoing && !isIncoming)
                    {
                        continue;
                    }

                    op = mapReader.ReadOP();
                    if (op != OPCode.PushShort && op != OPCode.PushByte)
                    {
                        continue;
                    }

                    ushort header = 0;
                    if (op == OPCode.PushByte)
                    {
                        header = mapReader.ReadByte();
                    }
                    else
                    {
                        header = (ushort)mapReader.Read7BitEncodedInt();
                    }

                    op = mapReader.ReadOP();
                    if (op != OPCode.GetLex)
                    {
                        continue;
                    }

                    int         messageTypeIndex = mapReader.Read7BitEncodedInt();
                    ASMultiname messageType      = abc.Constants.Multinames[messageTypeIndex];
                    ASClass     messageInstance  = abc.FindClassByName(messageType.ObjName);

                    if (isOutgoing)
                    {
                        OutgoingTypes[header] = messageInstance;
                    }
                    else if (isIncoming)
                    {
                        IncomingTypes[header] = messageInstance;
                    }
                }
            }

            return(OutgoingTypes.Count > 0 &&
                   IncomingTypes.Count > 0);
        }
Пример #25
0
        public bool ReplaceRSA(int exponent, string modulus)
        {
            ABCFile abc          = ABCFiles[2];
            int     modulusIndex = abc.Constants.AddString(modulus);

            int exponentIndex = abc.Constants
                                .AddString(exponent.ToString("x"));

            int        rsaStart  = 0;
            ASInstance commClass = abc.FindInstanceByName("HabboCommunicationDemo");
            ASMethod   verifier  = FindVerifyMethod(commClass, abc, out rsaStart);

            using (var inCode = new FlashReader(verifier.Body.Bytecode))
                using (var outCode = new FlashWriter(inCode.Length))
                {
                    bool searchingKeys = true;
                    inCode.Position = rsaStart;
                    outCode.Write(inCode.ToArray(), 0, rsaStart);

                    while (inCode.Position != inCode.Length)
                    {
                        byte codeByte = inCode.ReadByte();
                        outCode.Write(codeByte);

                        if (!searchingKeys)
                        {
                            outCode.Write(inCode.ToArray(),
                                          inCode.Position, inCode.Length - inCode.Position);

                            break;
                        }
                        switch ((OPCode)codeByte)
                        {
                        case OPCode.GetLex:
                        {
                            outCode.Position--;
                            outCode.WriteOP(OPCode.PushString);

                            int         typeIndex = inCode.Read7BitEncodedInt();
                            ASMultiname type      = abc.Constants.Multinames[typeIndex];

                            inCode.ReadOP();
                            inCode.Read7BitEncodedInt();
                            inCode.Read7BitEncodedInt();

                            if (modulusIndex > 0)
                            {
                                outCode.Write7BitEncodedInt(modulusIndex);
                                modulusIndex = -1;
                            }
                            else if (searchingKeys)
                            {
                                outCode.Write7BitEncodedInt(exponentIndex);
                                searchingKeys = false;
                            }
                            break;
                        }

                        case OPCode.PushString:
                        {
                            int    stringIndex = inCode.Read7BitEncodedInt();
                            string value       = abc.Constants.Strings[stringIndex];

                            if (string.IsNullOrWhiteSpace(Modulus))
                            {
                                Modulus = value;
                                outCode.Write7BitEncodedInt(modulusIndex);
                            }
                            else if (string.IsNullOrWhiteSpace(Exponent))
                            {
                                Exponent = value;
                                outCode.Write7BitEncodedInt(exponentIndex);

                                searchingKeys = false;
                            }
                            break;
                        }

                        default: continue;
                        }
                    }

                    verifier.Body.Bytecode = outCode.ToArray();
                    if (!searchingKeys)
                    {
                        return(true);
                    }
                }
            return(false);
        }
Пример #26
0
        public ASTrait(ABCFile abc, FlashReader reader)
            : this(abc)
        {
            TypeIndex = reader.Read7BitEncodedInt();
            byte trueKind = reader.ReadByte();

            var traitType = (TraitType)(trueKind & 0xF);
            Attributes = (TraitAttributes)(trueKind >> 4);
            #region Trait Reading
            switch (traitType)
            {
            case TraitType.Slot:
            case TraitType.Constant:
            {
                Data = new SlotConstantTrait(abc, reader, traitType)
                {
                    ObjName = Type.ObjName
                };
                break;
            }

            case TraitType.Method:
            case TraitType.Getter:
            case TraitType.Setter:
            {
                Data = new MethodGetterSetterTrait(abc, reader, traitType)
                {
                    ObjName = Type.ObjName
                };

                ((MethodGetterSetterTrait)Data).Method.ObjName = ObjName;
                break;
            }

            case TraitType.Class:
            {
                Data = new ClassTrait(abc, reader)
                {
                    ObjName = Type.ObjName
                };
                break;
            }

            case TraitType.Function:
            {
                Data = new FunctionTrait(abc, reader)
                {
                    ObjName = Type.ObjName
                };
                break;
            }

            default:
                throw new Exception($"Invalid {nameof(ASTrait)} type: " + traitType);
            }
            #endregion

            if ((Attributes & TraitAttributes.Metadata) != 0)
            {
                MetadataIndices.Capacity = reader.Read7BitEncodedInt();
            }

            for (int i = 0; i < MetadataIndices.Capacity; i++)
            {
                MetadataIndices.Add(reader.Read7BitEncodedInt());
            }
        }
Пример #27
0
 public GetScopeObjectIns(FlashReader input)
     : this()
 {
     ScopeIndex = input.ReadByte();
 }
Пример #28
0
 public ASNamespace(ABCFile abc, FlashReader reader)
     : this(abc)
 {
     NamespaceType = (ConstantType)reader.ReadByte();
     ObjNameIndex  = reader.Read7BitEncodedInt();
 }