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);
        }
示例#2
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());
        }
示例#3
0
        public ASNamespace(ASConstants constants, FlashReader reader)
        {
            _constants = constants;

            NamespaceType = (ConstantType)reader.ReadByte();
            NameIndex = reader.Read7BitEncodedInt();
        }
示例#4
0
        public ASTrait(ABCFile abc, FlashReader reader)
        {
            _abc = abc;

            NameIndex = 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, Name.ObjName, traitType);
                break;

                case TraitType.Method:
                case TraitType.Getter:
                case TraitType.Setter:
                {
                    var mgsTrait = new MethodGetterSetterTrait(abc, reader, Name.ObjName, traitType);
                    mgsTrait.Method.ObjName = Name.ObjName;

                    Data = mgsTrait;
                    break;
                }

                case TraitType.Class:
                {
                    var classTrait = new ClassTrait(abc, reader, Name.ObjName);
                    // TODO: Link trait information?
                    Data = classTrait;
                    break;
                }

                case TraitType.Function:
                {
                    var functionTrait = new FunctionTrait(abc, reader, Name.ObjName);
                    // TODO: Link trait information?
                    Data = functionTrait;
                    break;
                }

                default:
                throw new Exception("Invalid trait: " + TraitType);
            }
            #endregion

            MetadataIndices = new List<int>();
            if ((Attributes & TraitAttributes.Metadata) != 0)
                MetadataIndices.Capacity = reader.Read7BitEncodedInt();

            for (int i = 0; i < MetadataIndices.Capacity; i++)
                MetadataIndices.Add(reader.Read7BitEncodedInt());
        }
示例#5
0
        public SlotConstantTrait(ABCFile abc, FlashReader reader, string objName, TraitType traitType)
            : this(abc, objName, traitType)
        {
            SlotId = reader.Read7BitEncodedInt();
            TypeIndex = reader.Read7BitEncodedInt();
            ValueIndex = reader.Read7BitEncodedInt();

            if (ValueIndex != 0)
                ValueType = (ConstantType)reader.ReadByte();
        }
示例#6
0
        public ASMultiname(ASConstants constants, FlashReader reader)
        {
            _constants = constants;

            var multinameType = (ConstantType)reader.ReadByte();
            switch (multinameType)
            {
                case ConstantType.QName:
                case ConstantType.QNameA:
                {
                    var qName = new QName(constants, reader, multinameType);
                    ObjNameIndex = qName.NameIndex;

                    Data = qName;
                    break;
                }

                case ConstantType.RTQName:
                case ConstantType.RTQNameA:
                {
                    var rtqName = new RTQName(constants, reader, multinameType);
                    ObjNameIndex = rtqName.NameIndex;

                    Data = rtqName;
                    break;
                }

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

                case ConstantType.Multiname:
                case ConstantType.MultinameA:
                {
                    var multiname = new Multiname(constants, reader, multinameType);
                    ObjNameIndex = multiname.NameIndex;

                    Data = multiname;
                    break;
                }

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

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

                default:
                throw new Exception("Invalid multiname: " + multinameType);
            }
        }
示例#7
0
        public ASMethod(ABCFile abc, FlashReader reader)
        {
            _abc = abc;

            Parameters = new List<ASParameter>(reader.Read7BitEncodedInt());
            ReturnTypeIndex = reader.Read7BitEncodedInt();

            for (int i = 0; i < Parameters.Capacity; i++)
            {
                int parameterTypeIndex = reader.Read7BitEncodedInt();
                Parameters.Add(new ASParameter(abc, parameterTypeIndex));
            }

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

            if ((MethodInfo & MethodFlags.HasOptional) != 0)
            {
                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 & MethodFlags.HasParamNames) != 0)
            {
                foreach (ASParameter parameter in Parameters)
                    parameter.NameIndex = reader.Read7BitEncodedInt();
            }
        }
示例#8
0
        public bool FindMessageInstances()
        {
            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.Code.ToArray()))
            {
                while (mapReader.Position != mapReader.Length)
                {
                    OPCode op = mapReader.ReadOP();
                    if (op != OPCode.GetLex) continue;

                    int mapTypeIndex = mapReader.Read7BitEncodedInt();
                    bool isOutgoing = (mapTypeIndex == outgoingMap.NameIndex);
                    bool isIncoming = (mapTypeIndex == incomingMap.NameIndex);
                    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];
                    ASInstance messageInstance = abc.FindInstanceByName(messageType.ObjName);

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

            return (OutgoingTypes.Count > 0 &&
                IncomingTypes.Count > 0);
        }
示例#9
0
        public ASInstance(ABCFile abc, FlashReader reader)
        {
            _abc = abc;

            NameIndex = reader.Read7BitEncodedInt();
            SuperNameIndex = reader.Read7BitEncodedInt();
            ClassInfo = (ClassFlags)reader.ReadByte();

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

            InterfaceIndices = new List<int>(reader.Read7BitEncodedInt());
            for (int i = 0; i < InterfaceIndices.Capacity; i++)
                InterfaceIndices.Add(reader.Read7BitEncodedInt());

            ConstructorIndex = reader.Read7BitEncodedInt();
            Traits = new List<ASTrait>(reader.Read7BitEncodedInt());

            for (int i = 0; i < Traits.Capacity; i++)
                Traits.Add(new ASTrait(abc, reader));
        }
示例#10
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;
                }
            }
        }
示例#11
0
        public bool ReplaceRSA(int exponent, string modulus)
        {
            ABCFile abc = _abcFiles[_abcFiles.Count - 1];
            int modulusIndex = abc.Constants.Strings.IndexOf(modulus);
            if (modulusIndex == -1)
            {
                abc.Constants.Strings.Add(modulus);
                modulusIndex = (abc.Constants.Strings.Count - 1);
            }

            string e = exponent.ToString("x");
            int exponentIndex = abc.Constants.Strings.IndexOf(e);
            if (exponentIndex == -1)
            {
                abc.Constants.Strings.Add(e);
                exponentIndex = (abc.Constants.Strings.Count - 1);
            }

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

            ASCode verifierCode = verifier.Body.Code;
            using (var inCode = new FlashReader(verifierCode.ToArray()))
            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;
                    }
                }

                verifierCode.Clear();
                verifierCode.AddRange(outCode.ToArray());
                if (!searchingKeys) return true;
            }
            return false;
        }
示例#12
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;

            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;
        }