Example #1
0
        public MultinameInfo ReadMultinameInfo(ConstantPoolInfo constantPool, uint index)
        {
            MultinameInfo result = new MultinameInfo(index);

            result.Kind = (MultinameKind)ReadByte();
            switch (result.Kind)
            {
            case MultinameKind.QName:
            case MultinameKind.QNameA:
                var mkQName = new MKQName();
                mkQName.Namespace = constantPool.GetNamespaceAt(ReadU30());
                mkQName.Name      = constantPool.GetStringAt(ReadU30());
                result.Data       = mkQName;
                break;

            case MultinameKind.RTQName:
            case MultinameKind.RTQNameA:
                var mkRtkName = new MKRTQName();
                mkRtkName.Name = constantPool.GetStringAt(ReadU30());
                result.Data    = mkRtkName;
                break;

            case MultinameKind.RTQNameL:
            case MultinameKind.RTQNameLA:
                var mkRtqNameL = new MKRTQNameL();
                result.Data = mkRtqNameL;
                break;

            case MultinameKind.Multiname:
            case MultinameKind.MultinameA:
                var mkMultiname = new MKMultiname();

                mkMultiname.Name         = constantPool.GetStringAt(ReadU30());
                mkMultiname.NamespaceSet = constantPool.GetNamespaceSetAt(ReadU30());
                result.Data = mkMultiname;
                break;

            case MultinameKind.MultinameL:
            case MultinameKind.MultinameLA:
                var mkMultinameL = new MKMultinameL();
                mkMultinameL.NamespaceSet = constantPool.GetNamespaceSetAt(ReadU30());
                result.Data = mkMultinameL;
                break;

            case MultinameKind.GenericName:
                var mkGenericName = new MKGenericName(constantPool);
                mkGenericName.TypeDefinitionIndex = ReadU30();
                mkGenericName.ParamArrayIndexes   = ReadU30Array(ReadU30());
                result.Data = mkGenericName;
                break;

            default:
                throw new Exception();
            }
            return(result);
        }
Example #2
0
        public MetadataInfo ReadMetadataInfo(ConstantPoolInfo constantPool)
        {
            MetadataInfo result = new MetadataInfo();

            result.Name = ReadU30();
            uint count = ReadU30();

            result.KeyArray   = (from n in ReadU30Array(count) select constantPool.GetStringAt(n)).ToArray();
            result.ValueArray = (from n in ReadU30Array(count) select constantPool.GetStringAt(n)).ToArray();
            return(result);
        }
Example #3
0
        public MethodInfo ReadMethodInfo(ConstantPoolInfo constantPool, uint index)
        {
            MethodInfo result     = new MethodInfo(index);
            uint       paramCount = ReadU30();

            result.ReturnType     = constantPool.GetMultinameAt(ReadU30());
            result.ParamTypeArray = (from n in ReadU30Array(paramCount) select constantPool.GetMultinameAt(n)).ToArray();
            result.Name           = constantPool.GetStringAt(ReadU30());
            result.Flags          = (MethodFlags)ReadByte();
            if (result.Flags.HasFlag(MethodFlags.HAS_OPTIONAL))
            {
                result.OptionalParamArray = new OptionalParam[ReadU30()];
                for (int i = 0; i < result.OptionalParamArray.Length; i++)
                {
                    result.OptionalParamArray[i]       = new OptionalParam();
                    result.OptionalParamArray[i].Value = ReadU30();
                    result.OptionalParamArray[i].Kind  = (ValueKind)ReadByte();
                }
            }

            if (result.Flags.HasFlag(MethodFlags.HAS_PARAM_NAMES))
            {
                result.ParamNameArray = ReadU30Array(paramCount);
            }

            return(result);
        }
Example #4
0
        public ConstantPoolInfo ReadConstantPoolInfo()
        {
            ConstantPoolInfo result = new ConstantPoolInfo();

            result.IntArrayCapacity = ReadU30();
            for (uint i = 1; i < result.IntArrayCapacity; i++)
            {
                result.SetIntAt(ReadS32(), i);
            }

            result.UIntArrayCapacity = ReadU30();
            for (uint i = 1; i < result.UIntArrayCapacity; i++)
            {
                result.SetUIntAt(ReadU30(), i);
            }

            result.DoubleArrayCapacity = ReadU30();
            for (uint i = 1; i < result.DoubleArrayCapacity; i++)
            {
                result.SetDoubleAt(ReadDouble(), i);
            }

            result.StringArrayCapacity = ReadU30();
            for (uint i = 1; i < result.StringArrayCapacity; i++)
            {
                result.SetStringAt(new StringInfo(i, ReadString()), i);
            }

            result.NamespaceArrayCapacity = ReadU30();
            for (uint i = 1; i < result.NamespaceArrayCapacity; i++)
            {
                NamespaceInfo namespaceInfo = new NamespaceInfo(result, i);
                namespaceInfo.Kind = (NamespaceKind)ReadByte();
                namespaceInfo.Name = result.GetStringAt(ReadU30());
                result.SetNamespaceAt(namespaceInfo, i);
            }

            result.NamespaceSetArrayCapacity = ReadU30();
            for (uint i = 1; i < result.NamespaceSetArrayCapacity; i++)
            {
                NamespaceSetInfo namespaceSetInfo = new NamespaceSetInfo(i);
                namespaceSetInfo.NamespaceArray = new NamespaceInfo[ReadU30()];
                for (int j = 0; j < namespaceSetInfo.NamespaceArray.Length; j++)
                {
                    namespaceSetInfo.NamespaceArray[j] = result.GetNamespaceAt(ReadU30());
                }

                result.SetNamespaceSetAt(namespaceSetInfo, i);
            }

            result.MultinameArrayCapacity = ReadU30();
            for (uint i = 1; i < result.MultinameArrayCapacity; i++)
            {
                result.SetMultinameAt(ReadMultinameInfo(result, i), i);
            }
            return(result);
        }
Example #5
0
        public void WriteConstantPool(ConstantPoolInfo value)
        {
            WriteU30(value.IntArrayLength);
            for (uint i = 1; i < value.IntArrayLength; i++)
            {
                WriteS32(value.GetIntAt(i));
            }

            WriteU30(value.UIntArrayLength);
            for (uint i = 1; i < value.UIntArrayLength; i++)
            {
                WriteU30(value.GetUIntAt(i));
            }

            WriteU30(value.DoubleArrayLength);
            for (uint i = 1; i < value.DoubleArrayLength; i++)
            {
                WriteDouble(value.GetDoubleAt(i));
            }

            WriteU30(value.StringArrayLength);
            for (uint i = 1; i < value.StringArrayLength; i++)
            {
                StringInfo stringInfo = value.GetStringAt(i);

                WriteString(stringInfo);
            }


            WriteU30(value.NamespaceArrayLength);
            for (uint i = 1; i < value.NamespaceArrayLength; i++)
            {
                var namespaceInfo = value.GetNamespaceAt(i);
                WriteByte((Byte)namespaceInfo.Kind);
                WriteU30(namespaceInfo.Name?.Index ?? 0);
            }

            WriteU30(value.NamespaceSetArrayLength);
            for (uint i = 1; i < value.NamespaceSetArrayLength; i++)
            {
                WriteU30Array((from n in value.GetNamespaceSetAt(i).NamespaceArray select n.Index).ToArray(), true);
            }

            WriteU30(value.MultinameArrayLength);
            for (uint i = 1; i < value.MultinameArrayLength; i++)
            {
                WriteMultinameInfo(value.GetMultinameAt(i));
            }
        }
Example #6
0
        public object GetValue(ConstantPoolInfo constantPoolInfo)
        {
            object result;

            switch (ValueKind)
            {
            case ValueKind.Int:
                result = constantPoolInfo.GetIntAt(ValueIndex);
                break;

            case ValueKind.UInt:
                result = constantPoolInfo.GetUIntAt(ValueIndex);
                break;

            case ValueKind.Double:
                result = constantPoolInfo.GetDoubleAt(ValueIndex);
                break;

            case ValueKind.Utf8:
                result = '"' + constantPoolInfo.GetStringAt(ValueIndex) + '"';
                break;

            case ValueKind.False:
                result = "false";
                break;

            case ValueKind.True:
                result = "true";
                break;

            case ValueKind.Null:
                result = "null";
                break;

            case ValueKind.Undefined:
                result = "undefined";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(result);
        }
Example #7
0
        public As3Instruction GetPushInstruction(ConstantPoolInfo cPool)
        {
            if (ValueIndex != 0)
            {
                switch (ValueKind)
                {
                case ValueKind.Double:
                    double doubleValue = (double)GetValue(cPool);
                    if (doubleValue % 1 == 0)
                    {
                        if (doubleValue >= sbyte.MinValue && doubleValue <= sbyte.MaxValue)
                        {
                            return(new As3PushByte((sbyte)doubleValue));
                        }
                        else if (doubleValue >= short.MinValue && doubleValue <= short.MaxValue)
                        {
                            return(new As3PushShort((uint)doubleValue));
                        }
                    }
                    return(new As3PushDouble(ValueIndex));

                case ValueKind.Utf8:
                    return(new As3PushString(cPool.GetStringAt(ValueIndex)));

                case ValueKind.UInt:
                    uint uintValue = (uint)GetValue(cPool);
                    if (uintValue % 1 == 0)
                    {
                        if (uintValue <= sbyte.MaxValue)
                        {
                            return(new As3PushByte((sbyte)uintValue));
                        }
                        else if (uintValue <= short.MaxValue)
                        {
                            return(new As3PushShort((uint)uintValue));
                        }
                    }
                    return(new As3PushUInt(ValueIndex));

                case ValueKind.Int:
                    int intValue = (int)GetValue(cPool);
                    if (intValue % 1 == 0)
                    {
                        if (intValue >= sbyte.MinValue && intValue <= sbyte.MaxValue)
                        {
                            return(new As3PushByte((sbyte)intValue));
                        }
                        else if (intValue >= short.MinValue && intValue <= short.MaxValue)
                        {
                            return(new As3PushShort((uint)intValue));
                        }
                    }
                    return(new As3PushInt(ValueIndex));

                case ValueKind.True:
                    return(new As3PushTrue());

                case ValueKind.False:
                    return(new As3PushFalse());

                case ValueKind.Undefined:
                    return(new As3PushUndefined());
                }
            }

            throw new Exception();
        }
Example #8
0
 public MKMultiname(ConstantPoolInfo cPool)
     : base(cPool)
 {
     Name         = cPool.GetStringAt(1);
     NamespaceSet = cPool.GetNamespaceSetAt(1);
 }