Exemplo n.º 1
0
        private bool SkipFunkyAndCustomModifiers()
        {
            SigParser sigTemp = new SigParser(this);

            if (!sigTemp.SkipAnyVASentinel())
            {
                return(false);
            }


            byte bElementType = 0;

            if (!sigTemp.PeekByte(out bElementType))
            {
                return(false);
            }

            while (ELEMENT_TYPE_CMOD_REQD == bElementType ||
                   ELEMENT_TYPE_CMOD_OPT == bElementType ||
                   ELEMENT_TYPE_MODIFIER == bElementType ||
                   ELEMENT_TYPE_PINNED == bElementType)
            {
                sigTemp.SkipBytes(1);

                int token;
                if (!sigTemp.GetToken(out token))
                {
                    return(false);
                }

                if (!sigTemp.PeekByte(out bElementType))
                {
                    return(false);
                }
            }

            // Following custom modifiers must be an element type value which is less than ELEMENT_TYPE_MAX, or one of the other element types
            // that we support while parsing various signatures
            if (bElementType >= ELEMENT_TYPE_MAX)
            {
                switch (bElementType)
                {
                case ELEMENT_TYPE_PINNED:
                    break;

                default:
                    return(false);
                }
            }

            CopyFrom(sigTemp);
            return(true);
        }// SkipFunkyAndCustomModifiers
Exemplo n.º 2
0
        private bool GetElemTypeSlow(out int etype)
        {
            SigParser sigTemp = new SigParser(this);

            if (sigTemp.SkipCustomModifiers())
            {
                if (sigTemp.GetByte(out byte elemType))
                {
                    etype = elemType;
                    CopyFrom(sigTemp);
                    return(true);
                }
            }

            etype = 0;
            return(false);
        }
Exemplo n.º 3
0
        private void InitEnumData()
        {
            if (!IsEnum)
                throw new InvalidOperationException("Type is not an Enum.");

            _enumData = new EnumData();
            ICorDebug.IMetadataImport import = null;
            if (DesktopModule != null)
                import = DesktopModule.GetMetadataImport();

            if (import == null)
            {
                _enumData = new EnumData();
                return;
            }

            IntPtr hnd = IntPtr.Zero;
            int tokens;

            List<string> names = new List<string>();
            int[] fields = new int[64];
            do
            {
                int res = import.EnumFields(ref hnd, (int)_token, fields, fields.Length, out tokens);
                for (int i = 0; i < tokens; ++i)
                {
                    FieldAttributes attr;
                    int mdTypeDef, pchField, pcbSigBlob, pdwCPlusTypeFlag, pcchValue;
                    IntPtr ppvSigBlob, ppValue = IntPtr.Zero;
                    StringBuilder builder = new StringBuilder(256);

                    res = import.GetFieldProps(fields[i], out mdTypeDef, builder, builder.Capacity, out pchField, out attr, out ppvSigBlob, out pcbSigBlob, out pdwCPlusTypeFlag, out ppValue, out pcchValue);

                    if ((int)attr == 0x606 && builder.ToString() == "value__")
                    {
                        SigParser parser = new SigParser(ppvSigBlob, pcbSigBlob);
                        int sigType, elemType;

                        if (parser.GetCallingConvInfo(out sigType) && parser.GetElemType(out elemType))
                            _enumData.ElementType = (ClrElementType)elemType;
                    }

                    // public, static, literal, has default
                    int intAttr = (int)attr;
                    if ((int)attr == 0x8056)
                    {
                        string name = builder.ToString();
                        names.Add(name);

                        int ccinfo;
                        SigParser parser = new SigParser(ppvSigBlob, pcbSigBlob);
                        parser.GetCallingConvInfo(out ccinfo);
                        int elemType;
                        parser.GetElemType(out elemType);

                        Type type = ClrRuntime.GetTypeForElementType((ClrElementType)pdwCPlusTypeFlag);
                        if (type != null)
                        {
                            object o = System.Runtime.InteropServices.Marshal.PtrToStructure(ppValue, type);
                            _enumData.NameToValue[name] = o;
                            _enumData.ValueToName[o] = name;
                        }
                    }
                }
            } while (fields.Length == tokens);

            import.CloseEnum(hnd);
        }
Exemplo n.º 4
0
 private void CopyFrom(SigParser rhs)
 {
     _sig = rhs._sig;
     _len = rhs._len;
     _offs = rhs._offs;
 }
Exemplo n.º 5
0
        private bool SkipFunkyAndCustomModifiers()
        {
            SigParser sigTemp = new SigParser(this);
            if (!sigTemp.SkipAnyVASentinel())
                return false;


            byte bElementType = 0;

            if (!sigTemp.PeekByte(out bElementType))
                return false;

            while (ELEMENT_TYPE_CMOD_REQD == bElementType ||
                   ELEMENT_TYPE_CMOD_OPT == bElementType ||
                   ELEMENT_TYPE_MODIFIER == bElementType ||
                   ELEMENT_TYPE_PINNED == bElementType)
            {
                sigTemp.SkipBytes(1);

                int token;
                if (!sigTemp.GetToken(out token))
                    return false;

                if (!sigTemp.PeekByte(out bElementType))
                    return false;
            }

            // Following custom modifiers must be an element type value which is less than ELEMENT_TYPE_MAX, or one of the other element types
            // that we support while parsing various signatures
            if (bElementType >= ELEMENT_TYPE_MAX)
            {
                switch (bElementType)
                {
                    case ELEMENT_TYPE_PINNED:
                        break;
                    default:
                        return false;
                }
            }

            CopyFrom(sigTemp);
            return true;
        }// SkipFunkyAndCustomModifiers
Exemplo n.º 6
0
 public SigParser(SigParser rhs)
 {
     _sig = rhs._sig;
     _len = rhs._len;
     _offs = rhs._offs;
 }
Exemplo n.º 7
0
        private bool PeekElemTypeSize(out int pSize)
        {
            pSize = 0;
            SigParser sigTemp = new SigParser(this);

            if (!sigTemp.SkipAnyVASentinel())
                return false;

            byte bElementType = 0;
            if (!sigTemp.GetByte(out bElementType))
                return false;


            switch (bElementType)
            {
                case ELEMENT_TYPE_I8:
                case ELEMENT_TYPE_U8:
                case ELEMENT_TYPE_R8:
                    pSize = 8;
                    break;

                case ELEMENT_TYPE_I4:
                case ELEMENT_TYPE_U4:
                case ELEMENT_TYPE_R4:
                    pSize = 4;
                    break;

                case ELEMENT_TYPE_I2:
                case ELEMENT_TYPE_U2:
                case ELEMENT_TYPE_CHAR:
                    pSize = 2;
                    break;

                case ELEMENT_TYPE_I1:
                case ELEMENT_TYPE_U1:
                case ELEMENT_TYPE_BOOLEAN:
                    pSize = 1;
                    break;

                case ELEMENT_TYPE_I:
                case ELEMENT_TYPE_U:
                case ELEMENT_TYPE_STRING:
                case ELEMENT_TYPE_PTR:
                case ELEMENT_TYPE_BYREF:
                case ELEMENT_TYPE_CLASS:
                case ELEMENT_TYPE_OBJECT:
                case ELEMENT_TYPE_FNPTR:
                case ELEMENT_TYPE_TYPEDBYREF:
                case ELEMENT_TYPE_ARRAY:
                case ELEMENT_TYPE_SZARRAY:
                    pSize = IntPtr.Size;
                    break;

                case ELEMENT_TYPE_VOID:
                    break;

                case ELEMENT_TYPE_END:
                case ELEMENT_TYPE_CMOD_REQD:
                case ELEMENT_TYPE_CMOD_OPT:
                case ELEMENT_TYPE_VALUETYPE:
                    Debug.Fail("Asked for the size of an element that doesn't have a size!");
                    return false;

                default:
                    Debug.Fail("CorSigGetElementTypeSize given invalid signature to size!");
                    return false;
            }

            return true; ;
        }
Exemplo n.º 8
0
 private bool PeekElemTypeSlow(out int etype)
 {
     SigParser sigTemp = new SigParser(this);
     return sigTemp.GetElemType(out etype);
 }
Exemplo n.º 9
0
        private bool GetElemTypeSlow(out int etype)
        {
            SigParser sigTemp = new SigParser(this);
            if (sigTemp.SkipCustomModifiers())
            {
                byte elemType;
                if (sigTemp.GetByte(out elemType))
                {
                    etype = elemType;
                    this.CopyFrom(sigTemp);
                    return true;
                }
            }

            etype = 0;
            return false;
        }
Exemplo n.º 10
0
 private void CopyFrom(SigParser rhs)
 {
     _sig  = rhs._sig;
     _len  = rhs._len;
     _offs = rhs._offs;
 }
Exemplo n.º 11
0
 public SigParser(SigParser rhs)
 {
     _sig  = rhs._sig;
     _len  = rhs._len;
     _offs = rhs._offs;
 }
Exemplo n.º 12
0
        private bool PeekElemTypeSize(out int pSize)
        {
            pSize = 0;
            SigParser sigTemp = new SigParser(this);

            if (!sigTemp.SkipAnyVASentinel())
            {
                return(false);
            }

            if (!sigTemp.GetByte(out byte bElementType))
            {
                return(false);
            }

            switch (bElementType)
            {
            case ELEMENT_TYPE_I8:
            case ELEMENT_TYPE_U8:
            case ELEMENT_TYPE_R8:
                pSize = 8;
                break;

            case ELEMENT_TYPE_I4:
            case ELEMENT_TYPE_U4:
            case ELEMENT_TYPE_R4:
                pSize = 4;
                break;

            case ELEMENT_TYPE_I2:
            case ELEMENT_TYPE_U2:
            case ELEMENT_TYPE_CHAR:
                pSize = 2;
                break;

            case ELEMENT_TYPE_I1:
            case ELEMENT_TYPE_U1:
            case ELEMENT_TYPE_BOOLEAN:
                pSize = 1;
                break;

            case ELEMENT_TYPE_I:
            case ELEMENT_TYPE_U:
            case ELEMENT_TYPE_STRING:
            case ELEMENT_TYPE_PTR:
            case ELEMENT_TYPE_BYREF:
            case ELEMENT_TYPE_CLASS:
            case ELEMENT_TYPE_OBJECT:
            case ELEMENT_TYPE_FNPTR:
            case ELEMENT_TYPE_TYPEDBYREF:
            case ELEMENT_TYPE_ARRAY:
            case ELEMENT_TYPE_SZARRAY:
                pSize = IntPtr.Size;
                break;

            case ELEMENT_TYPE_VOID:
                break;

            case ELEMENT_TYPE_END:
            case ELEMENT_TYPE_CMOD_REQD:
            case ELEMENT_TYPE_CMOD_OPT:
            case ELEMENT_TYPE_VALUETYPE:
                Debug.Fail("Asked for the size of an element that doesn't have a size!");
                return(false);

            default:
                Debug.Fail("CorSigGetElementTypeSize given invalid signature to size!");
                return(false);
            }

            return(true);

            ;
        }
Exemplo n.º 13
0
        private bool PeekElemTypeSlow(out int etype)
        {
            SigParser sigTemp = new SigParser(this);

            return(sigTemp.GetElemType(out etype));
        }
Exemplo n.º 14
0
        public DesktopInstanceField(DesktopGCHeap heap, IFieldData data, string name, FieldAttributes attributes, IntPtr sig, int sigLen)
        {
            _name = name;
            _field = data;
            _attributes = attributes;

            ulong mt = data.TypeMethodTable;
            if (mt != 0)
                _type = (BaseDesktopHeapType)heap.GetTypeByTypeHandle(mt, 0);

            if (_type == null)
            {
                if (sig != IntPtr.Zero && sigLen > 0)
                {
                    SigParser sigParser = new SigParser(sig, sigLen);

                    bool res;
                    int sigType, etype = 0;

                    if (res = sigParser.GetCallingConvInfo(out sigType))
                        Debug.Assert(sigType == SigParser.IMAGE_CEE_CS_CALLCONV_FIELD);

                    res = res && sigParser.SkipCustomModifiers();
                    res = res && sigParser.GetElemType(out etype);

                    if (res)
                    {
                        ClrElementType type = (ClrElementType)etype;

                        if (type == ClrElementType.Array)
                        {
                            res = sigParser.PeekElemType(out etype);
                            res = res && sigParser.SkipExactlyOne();

                            int ranks = 0;
                            res = res && sigParser.GetData(out ranks);

                            if (res)
                                _type = heap.GetArrayType((ClrElementType)etype, ranks, null);
                        }
                        else if (type == ClrElementType.SZArray)
                        {
                            res = sigParser.PeekElemType(out etype);
                            type = (ClrElementType)etype;

                            if (DesktopRuntimeBase.IsObjectReference(type))
                                _type = (BaseDesktopHeapType)heap.GetBasicType(ClrElementType.SZArray);
                            else
                                _type = (BaseDesktopHeapType)heap.GetArrayType(type, -1, null);
                        }
                        else if (type == ClrElementType.Pointer)
                        {
                            // Only deal with single pointers for now and types that have already been constructed
                            res = sigParser.GetElemType(out etype);
                            type = (ClrElementType)etype;

                            int token;
                            sigParser.GetToken(out token);
                            BaseDesktopHeapType innerType = (BaseDesktopHeapType)heap.GetGCHeapTypeFromModuleAndToken(data.Module, Convert.ToUInt32(token));

                            if (innerType == null)
                            {
                                innerType = (BaseDesktopHeapType)heap.GetBasicType(type);
                            }

                            _type = heap.CreatePointerType(innerType, type, null);
                        }
                    }
                }

                if (_type == null)
                    _type = (BaseDesktopHeapType)heap.GetBasicType(ElementType);
            }
            else if (ElementType != ClrElementType.Class)
            {
                _type.ElementType = ElementType;
            }
        }