Пример #1
0
        //^ [NotDelayed]
        internal LocalVariableSignatureConverter(
            PEFileToObjectModel peFileToObjectModel,
            MethodBody owningMethodBody,
            MemoryReader signatureMemoryReader
            )
            : base(peFileToObjectModel, signatureMemoryReader, owningMethodBody.MethodDefinition)
        {
            _owningMethodBody = owningMethodBody;
            //^ this.LocalVariables = ILReader.EmptyLocalVariables;
            //^ this.SignatureMemoryReader = signatureMemoryReader;
            //^ base;
            byte firstByte = this.SignatureMemoryReader.ReadByte();

            if (!SignatureHeader.IsLocalVarSignature(firstByte))
            {
                //  MDError
            }
            int locVarCount = this.SignatureMemoryReader.ReadCompressedUInt32();

            LocalVariableDefinition[] locVarArr = new LocalVariableDefinition[locVarCount];
            for (int i = 0; i < locVarCount; ++i)
            {
                locVarArr[i] = this.GetLocalVariable((uint)i);
            }
            //^ NonNullType.AssertInitialized(locVarArr);
            this.LocalVariables = new EnumerableArrayWrapper <LocalVariableDefinition, ILocalDefinition>(locVarArr, Dummy.LocalVariable);
        }
Пример #2
0
 /// <summary>
 /// Method to open the module in the MetadataReader. This method loads the module and returns the object corresponding to the opened module.
 /// Also returns the ModuleIDentifier corresponding to the module as the out parameter. Modules are opened as if they are not contained in any assembly.
 /// </summary>
 /// <param name="binaryDocument">The binary document that needes to be opened as an module.</param>
 /// <param name="moduleIdentity">Contains the module identity of the binary document in case it is an module.</param>
 /// <returns>Module that is loaded or Dummy.Module in case module could not be loaded.</returns>
 public IModule OpenModule(
     IBinaryDocument binaryDocument,
     out ModuleIdentity /*?*/ moduleIdentity
     )
 {
     moduleIdentity = null;
     lock (GlobalLock.LockingObject)
     {
         IBinaryDocumentMemoryBlock /*?*/ binaryDocumentMemoryBlock = this.metadataReaderHost.OpenBinaryDocument(binaryDocument);
         if (binaryDocumentMemoryBlock == null)
         {
             //  Error...
             return(Dummy.Module);
         }
         PEFileReader peFileReader = new PEFileReader(this, binaryDocumentMemoryBlock);
         if (peFileReader.ReaderState < ReaderState.Metadata)
         {
             //  Error...
             return(Dummy.Module);
         }
         //^ assert peFileReader.ReaderState >= ReaderState.Metadata;
         if (peFileReader.IsAssembly)
         {
             AssemblyIdentity assemblyIdentity = this.GetAssemblyIdentifier(peFileReader);
             moduleIdentity = assemblyIdentity;
             Assembly /*?*/ lookupAssembly = this.LookupAssembly(null, assemblyIdentity);
             if (lookupAssembly != null)
             {
                 return(lookupAssembly);
             }
         }
         else
         {
             moduleIdentity = this.GetModuleIdentifier(peFileReader);
             Module /*?*/ lookupModule = this.LookupModule(null, moduleIdentity);
             if (lookupModule != null)
             {
                 return(lookupModule);
             }
         }
         try
         {
             PEFileToObjectModel peFileToObjectModel = new PEFileToObjectModel(this, peFileReader, moduleIdentity, null, this.metadataReaderHost.PointerSize);
             this.LoadedModule(peFileToObjectModel.Module);
             Assembly /*?*/ assembly = peFileToObjectModel.Module as Assembly;
             if (assembly != null)
             {
                 this.OpenMemberModules(binaryDocument, assembly);
             }
             return(peFileToObjectModel.Module);
         }
         catch (MetadataReaderException)
         {
             //  Error...
         }
     }
     return(Dummy.Module);
 }
Пример #3
0
     protected AttributeDecoder(
   PEFileToObjectModel peFileToObjectModel,
   MemoryReader signatureMemoryReader
 )
     {
         this.PEFileToObjectModel = peFileToObjectModel;
           this.SignatureMemoryReader = signatureMemoryReader;
           this.morePermutationsArePossible = true;
     }
Пример #4
0
 internal ILReader(
     MethodDefinition methodDefinition,
     MethodIL methodIL
     )
 {
     this.MethodDefinition    = methodDefinition;
     this.PEFileToObjectModel = methodDefinition.PEFileToObjectModel;
     _methodIL          = methodIL;
     this.MethodBody    = new MethodBody(methodDefinition, methodIL.LocalVariablesInited, methodIL.MaxStack);
     _endOfMethodOffset = (uint)methodIL.EncodedILMemoryBlock.Length;
 }
Пример #5
0
        //^ [NotDelayed]
        internal StandAloneMethodSignatureConverter(
            PEFileToObjectModel peFileToObjectModel,
            MethodDefinition moduleMethodDef,
            MemoryReader signatureMemoryReader
            )
            : base(peFileToObjectModel, signatureMemoryReader, moduleMethodDef)
        {
            //^ this.ReturnCustomModifiers = TypeCache.EmptyCustomModifierArray;
            this.RequiredParameters = TypeCache.EmptyParameterInfoArray;
            this.VarArgParameters   = TypeCache.EmptyParameterInfoArray;
            //^ base;
            //^ this.SignatureMemoryReader = signatureMemoryReader; //TODO: Spec# bug. This assignment should not be necessary.
            //  TODO: Check minimum required size of the signature...
            this.FirstByte = this.SignatureMemoryReader.ReadByte();
            int  paramCount = this.SignatureMemoryReader.ReadCompressedUInt32();
            bool dummyPinned;

            this.ReturnCustomModifiers = this.GetCustomModifiers(out dummyPinned);
            byte retByte = this.SignatureMemoryReader.PeekByte(0);

            if (retByte == ElementType.Void)
            {
                this.ReturnTypeReference = peFileToObjectModel.SystemVoid;
                this.SignatureMemoryReader.SkipBytes(1);
            }
            else if (retByte == ElementType.TypedReference)
            {
                this.ReturnTypeReference = peFileToObjectModel.SystemTypedReference;
                this.SignatureMemoryReader.SkipBytes(1);
            }
            else
            {
                if (retByte == ElementType.ByReference)
                {
                    this.IsReturnByReference = true;
                    this.SignatureMemoryReader.SkipBytes(1);
                }
                this.ReturnTypeReference = this.GetTypeReference();
            }
            if (paramCount > 0)
            {
                IModuleParameterTypeInformation[] reqModuleParamArr = this.GetModuleParameterTypeInformations(Dummy.Method, paramCount);
                if (reqModuleParamArr.Length > 0)
                {
                    this.RequiredParameters = new EnumerableArrayWrapper <IModuleParameterTypeInformation, IParameterTypeInformation>(reqModuleParamArr, Dummy.ParameterTypeInformation);
                }
                IModuleParameterTypeInformation[] varArgModuleParamArr = this.GetModuleParameterTypeInformations(Dummy.Method, paramCount - reqModuleParamArr.Length);
                if (varArgModuleParamArr.Length > 0)
                {
                    this.VarArgParameters = new EnumerableArrayWrapper <IModuleParameterTypeInformation, IParameterTypeInformation>(varArgModuleParamArr, Dummy.ParameterTypeInformation);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// This method loads a module from a file containing only the metadata section of a PE file. (No headers and no IL.)
        /// </summary>
        /// <param name="binaryDocument">The binary document that needes to be opened as an module.</param>
        /// <returns>Module that is loaded or Dummy.Module in case module could not be loaded.</returns>
        public IModule OpenSnapshot(IBinaryDocument binaryDocument)
        {
            ModuleIdentity moduleIdentity;

            lock (GlobalLock.LockingObject) {
                IBinaryDocumentMemoryBlock /*?*/ binaryDocumentMemoryBlock = this.metadataReaderHost.OpenBinaryDocument(binaryDocument);
                if (binaryDocumentMemoryBlock == null)
                {
                    //  Error...
                    return(Dummy.Module);
                }
                PEFileReader peFileReader = new PEFileReader(this, binaryDocumentMemoryBlock, snapshot: true);
                if (peFileReader.ReaderState < ReaderState.Metadata)
                {
                    //  Error...
                    return(Dummy.Module);
                }
                if (peFileReader.IsAssembly)
                {
                    AssemblyIdentity assemblyIdentity = this.GetAssemblyIdentifier(peFileReader);
                    moduleIdentity = assemblyIdentity;
                    Assembly /*?*/ lookupAssembly = this.LookupAssembly(null, assemblyIdentity);
                    if (lookupAssembly != null)
                    {
                        return(lookupAssembly);
                    }
                }
                else
                {
                    moduleIdentity = this.GetModuleIdentifier(peFileReader);
                    Module /*?*/ lookupModule = this.LookupModule(null, moduleIdentity);
                    if (lookupModule != null)
                    {
                        return(lookupModule);
                    }
                }
                if (peFileReader.ReaderState < ReaderState.Metadata)
                {
                    //  Error...
                    return(Dummy.Module);
                }
                try {
                    PEFileToObjectModel peFileToObjectModel = new PEFileToObjectModel(this, peFileReader, moduleIdentity, null, this.metadataReaderHost.PointerSize);
                    this.LoadedModule(peFileToObjectModel.Module);
                    CciEventSource.Log.ModuleOpened(peFileToObjectModel.Module, moduleIdentity, binaryDocument.Length);
                    return(peFileToObjectModel.Module);
                } catch (MetadataReaderException) {
                    //  Error...
                }
            }
            return(Dummy.Module);
        }
Пример #7
0
        /// <summary>
        /// This method is called when an assembly is loaded. This makes sure that all the member modules of the assembly are loaded.
        /// </summary>
        /// <param name="binaryDocument"></param>
        /// <param name="assembly"></param>
        private void OpenMemberModules(IBinaryDocument binaryDocument, Assembly assembly)
        {
            List <Module>    memberModuleList = new List <Module>();
            AssemblyIdentity assemblyIdentity = assembly.AssemblyIdentity;

            foreach (IFileReference fileRef in assembly.PEFileToObjectModel.GetFiles())
            {
                if (!fileRef.HasMetadata)
                {
                    continue;
                }
                IBinaryDocumentMemoryBlock /*?*/ binaryDocumentMemoryBlock = this.metadataReaderHost.OpenBinaryDocument(binaryDocument, fileRef.FileName.Value);
                if (binaryDocumentMemoryBlock == null)
                {
                    //  Error...
                    continue;
                }
                try
                {
                    PEFileReader peFileReader = new PEFileReader(this, binaryDocumentMemoryBlock);
                    if (peFileReader.ReaderState < ReaderState.Metadata)
                    {
                        //  Error...
                        continue;
                    }
                    if (peFileReader.IsAssembly)
                    {
                        //  Error...
                        continue;
                    }
                    ModuleIdentity      moduleIdentity      = this.GetModuleIdentifier(peFileReader, assemblyIdentity);
                    PEFileToObjectModel peFileToObjectModel = new PEFileToObjectModel(this, peFileReader, moduleIdentity, assembly, this.metadataReaderHost.PointerSize);
                    memberModuleList.Add(peFileToObjectModel.Module);
                }
                catch (MetadataReaderException)
                {
                    continue;
                }
            }
            if (memberModuleList.Count == 0)
            {
                return;
            }
            assembly.SetMemberModules(new EnumerableArrayWrapper <Module, IModule>(memberModuleList.ToArray(), Dummy.Module));
        }
Пример #8
0
        /// <summary>
        /// Method to open the assembly in MetadataReader. This method loads the assembly and returns the object corresponding to the
        /// opened assembly. Also returns the AssemblyIdentifier corresponding to the assembly as the out parameter.
        /// Only assemblies that unify to themselves can be opened i.e. if the unification policy of the compilation host says that mscorlib 1.0 unifies to mscorlib 2.0
        /// then only mscorlib 2.0 can be loaded.
        /// </summary>
        /// <param name="binaryDocument">The binary document that needes to be opened as an assembly.</param>
        /// <param name="assemblyIdentity">Contains the assembly identifier of the binary document in case it is an assembly.</param>
        /// <returns>Assembly that is loaded or Dummy.Assembly in case assembly could not be loaded.</returns>
        public IAssembly OpenAssembly(IBinaryDocument binaryDocument, out AssemblyIdentity /*?*/ assemblyIdentity)
        {
            Contract.Requires(binaryDocument != null);
            Contract.Ensures(Contract.Result <IAssembly>() != null);

            assemblyIdentity = null;
            lock (GlobalLock.LockingObject) {
                IBinaryDocumentMemoryBlock /*?*/ binaryDocumentMemoryBlock = this.metadataReaderHost.OpenBinaryDocument(binaryDocument);
                if (binaryDocumentMemoryBlock == null)
                {
                    //  Error...
                    return(Dummy.Assembly);
                }
                PEFileReader peFileReader = new PEFileReader(this, binaryDocumentMemoryBlock);
                if (peFileReader.ReaderState < ReaderState.Metadata)
                {
                    //  Error...
                    return(Dummy.Assembly);
                }
                //^ assert peFileReader.ReaderState >= ReaderState.Metadata;
                if (!peFileReader.IsAssembly)
                {
                    //  Error...
                    return(Dummy.Assembly);
                }
                assemblyIdentity = this.GetAssemblyIdentifier(peFileReader);
                Assembly /*?*/ lookupAssembly = this.LookupAssembly(null, assemblyIdentity);
                if (lookupAssembly != null)
                {
                    return(lookupAssembly);
                }
                try {
                    PEFileToObjectModel peFileToObjectModel = new PEFileToObjectModel(this, peFileReader, assemblyIdentity, null, this.metadataReaderHost.PointerSize);
                    Assembly /*?*/      assembly            = peFileToObjectModel.Module as Assembly;
                    //^ assert assembly != null;
                    this.LoadedModule(assembly);
                    CciEventSource.Log.ModuleOpened(assembly, assemblyIdentity, binaryDocument.Length);
                    this.OpenMemberModules(binaryDocument, assembly);
                    return(assembly);
                } catch (MetadataReaderException) {
                    return(Dummy.Assembly);
                }
            }
        }
Пример #9
0
     /*?*/
     internal override IModuleTypeReference GetAsTypeReference(
   PEFileToObjectModel peFileToObjectModel,
   IModuleModuleReference module
 )
     {
         IModuleTypeReference/*?*/ targetType = this.TargetType.GetAsTypeReference(peFileToObjectModel, module);
           if (targetType == null)
         return null;
           return new PointerType(
         peFileToObjectModel,
         0xFFFFFFFF,
         targetType
           );
     }
Пример #10
0
     /*?*/
     internal abstract IModuleTypeReference GetAsTypeReference(
   PEFileToObjectModel peFileToObjectModel,
   IModuleModuleReference module
 );
Пример #11
0
     internal override IModuleTypeReference GetAsTypeReference(
   PEFileToObjectModel peFileToObjectModel, IModuleModuleReference module
 )
     {
         return this.GetAsNomimalType(peFileToObjectModel, module);
     }
Пример #12
0
 internal override ITypeReference/*?*/ GetAsTypeReference(PEFileToObjectModel peFileToObjectModel, IMetadataReaderModuleReference module) {
   foreach (var aref in peFileToObjectModel.GetAssemblyReferences()) {
     var assemRef = aref as AssemblyReference;
     if (assemRef == null) continue;
     if (assemRef.AssemblyIdentity.Equals(this.AssemblyIdentity))
       return this.TypeName.GetAsTypeReference(peFileToObjectModel, assemRef);
   }
   if (module.ContainingAssembly.AssemblyIdentity.Equals(this.AssemblyIdentity))
     return this.TypeName.GetAsTypeReference(peFileToObjectModel, module);
   AssemblyFlags flags = this.Retargetable ? AssemblyFlags.Retargetable : (AssemblyFlags)0;
   return this.TypeName.GetAsTypeReference(peFileToObjectModel, new AssemblyReference(peFileToObjectModel, 0, this.AssemblyIdentity, flags));
 }
Пример #13
0
 internal abstract IMetadataReaderNamedTypeReference/*?*/ GetAsNomimalType(
   PEFileToObjectModel peFileToObjectModel,
   IMetadataReaderModuleReference module
 );
Пример #14
0
 internal override IMetadataReaderNamedTypeReference/*?*/ GetAsNomimalType(
   PEFileToObjectModel peFileToObjectModel,
   IMetadataReaderModuleReference module
 ) {
   var typeRef = new NamespaceTypeNameTypeReference(module, this, peFileToObjectModel);
   var redirectedTypeRef = peFileToObjectModel.ModuleReader.metadataReaderHost.Redirect(peFileToObjectModel.Module, typeRef) as INamespaceTypeReference;
   if (redirectedTypeRef != typeRef && redirectedTypeRef != null) {
     var namespaceName = this.GetNamespaceName(peFileToObjectModel.NameTable, redirectedTypeRef.ContainingUnitNamespace as INestedUnitNamespaceReference);
     var mangledName = redirectedTypeRef.Name;
     if (redirectedTypeRef.GenericParameterCount > 0)
       mangledName = peFileToObjectModel.NameTable.GetNameFor(redirectedTypeRef.Name.Value+"`"+redirectedTypeRef.GenericParameterCount);
     var redirectedNamespaceTypeName = new NamespaceTypeName(peFileToObjectModel.NameTable, namespaceName, mangledName, redirectedTypeRef.Name);
     return new NamespaceTypeNameTypeReference(module, redirectedNamespaceTypeName, peFileToObjectModel);
   }
   return typeRef;
 }
Пример #15
0
 internal abstract INamedTypeDefinition/*?*/ ResolveNominalTypeName(
   PEFileToObjectModel peFileToObjectModel
 );
Пример #16
0
 internal SecurityAttribute(
   PEFileToObjectModel peFileToObjectModel,
   uint declSecurityRowId,
   SecurityAction action
 )
   : base(peFileToObjectModel) {
   this.DeclSecurityRowId = declSecurityRowId;
   this.Action = action;
 }
Пример #17
0
     internal CustomAttribute(
   PEFileToObjectModel peFileToObjectModel,
   uint attributeRowId,
   IModuleMethodReference constructor,
   EnumerableArrayWrapper<ExpressionBase, IMetadataExpression> arguments,
   EnumerableArrayWrapper<FieldOrPropertyNamedArgumentExpression, IMetadataNamedArgument> namedArguments
 )
         : base(peFileToObjectModel)
     {
         this.AttributeRowId = attributeRowId;
           this.Constructor = constructor;
           this.Arguments = arguments;
           this.NamedArguments = namedArguments;
     }
Пример #18
0
        //  Caller should lock peFileToObjectModel
        internal CoreTypes(PEFileToObjectModel peFileToObjectModel)
        {
            INameTable             nameTable        = peFileToObjectModel.NameTable;
            PEFileReader           peFileReader     = peFileToObjectModel.PEFileReader;
            PeReader               peReader         = peFileToObjectModel.ModuleReader;
            Module                 module           = peFileToObjectModel.Module;
            AssemblyIdentity /*?*/ assemblyIdentity = module.ModuleIdentity as AssemblyIdentity;

            //This does more than just initialize the five types exposed above, since it is also
            //necessary to initialize any typedefs and typerefs to types with short forms
            //in such a way that they have the correct type codes.

            int systemName              = nameTable.System.UniqueKey;
            int voidName                = nameTable.Void.UniqueKey;
            int booleanName             = nameTable.Boolean.UniqueKey;
            int charName                = nameTable.Char.UniqueKey;
            int byteName                = nameTable.Byte.UniqueKey;
            int sByteName               = nameTable.SByte.UniqueKey;
            int int16Name               = nameTable.Int16.UniqueKey;
            int uint16Name              = nameTable.UInt16.UniqueKey;
            int int32Name               = nameTable.Int32.UniqueKey;
            int uint32Name              = nameTable.UInt32.UniqueKey;
            int int64Name               = nameTable.Int64.UniqueKey;
            int uint64Name              = nameTable.UInt64.UniqueKey;
            int stringName              = nameTable.String.UniqueKey;
            int intPtrName              = nameTable.IntPtr.UniqueKey;
            int uintPtrName             = nameTable.UIntPtr.UniqueKey;
            int objectName              = nameTable.Object.UniqueKey;
            int singleName              = nameTable.Single.UniqueKey;
            int doubleName              = nameTable.Double.UniqueKey;
            int decimalName             = nameTable.Decimal.UniqueKey;
            int typedReference          = nameTable.TypedReference.UniqueKey;
            int enumName                = nameTable.Enum.UniqueKey;
            int valueTypeName           = nameTable.ValueType.UniqueKey;
            int multicastDelegateName   = nameTable.MulticastDelegate.UniqueKey;
            int typeName                = nameTable.Type.UniqueKey;
            int arrayName               = nameTable.Array.UniqueKey;
            int paramArrayAttributeName = peReader.ParamArrayAttribute.UniqueKey;

            if (assemblyIdentity != null && assemblyIdentity.Equals(peReader.metadataReaderHost.CoreAssemblySymbolicIdentity))
            {
                peReader.RegisterCoreAssembly(module as Assembly);
                uint numberOfTypeDefs = peFileReader.TypeDefTable.NumberOfRows;
                for (uint i = 1; i <= numberOfTypeDefs; ++i)
                {
                    TypeDefRow typeDefRow = peFileReader.TypeDefTable[i];
                    if (!typeDefRow.IsNested)
                    {
                        int namespaceName = peFileToObjectModel.GetNameFromOffset(typeDefRow.Namespace).UniqueKey;
                        if (namespaceName == systemName)
                        {
                            int typeDefName = peFileToObjectModel.GetNameFromOffset(typeDefRow.Name).UniqueKey;
                            if (typeDefName == voidName)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Void);
                            }
                            else if (typeDefName == booleanName)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Boolean);
                            }
                            else if (typeDefName == charName)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Char);
                            }
                            else if (typeDefName == byteName)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Byte);
                            }
                            else if (typeDefName == sByteName)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.SByte);
                            }
                            else if (typeDefName == int16Name)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Int16);
                            }
                            else if (typeDefName == uint16Name)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt16);
                            }
                            else if (typeDefName == int32Name)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Int32);
                            }
                            else if (typeDefName == uint32Name)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt32);
                            }
                            else if (typeDefName == int64Name)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Int64);
                            }
                            else if (typeDefName == uint64Name)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt64);
                            }
                            else if (typeDefName == stringName)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.String);
                            }
                            else if (typeDefName == intPtrName)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.IntPtr);
                            }
                            else if (typeDefName == uintPtrName)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.UIntPtr);
                            }
                            else if (typeDefName == objectName)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Object);
                            }
                            else if (typeDefName == singleName)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Single);
                            }
                            else if (typeDefName == doubleName)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Double);
                            }
                            else if (typeDefName == typedReference)
                            {
                                peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.TypedReference);
                            }
                            else if (typeDefName == enumName)
                            {
                                this.SystemEnum = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                            }
                            else if (typeDefName == valueTypeName)
                            {
                                this.SystemValueType = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                            }
                            else if (typeDefName == multicastDelegateName)
                            {
                                this.SystemMulticastDelegate = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                            }
                            else if (typeDefName == typeName)
                            {
                                this.SystemType = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                            }
                            else if (typeDefName == paramArrayAttributeName)
                            {
                                this.SystemParamArrayAttribute = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                            }
                        }
                    }
                }
            }
            else
            {
                uint numberOfTypeRefs = peFileReader.TypeRefTable.NumberOfRows;
                AssemblyReference /*?*/ coreAssemblyRef = peFileToObjectModel.FindAssemblyReference(peFileToObjectModel.CoreAssemblySymbolicIdentity);
                if (coreAssemblyRef == null)
                {
                    //  Error...
                    coreAssemblyRef = new AssemblyReference(peFileToObjectModel, 1, peFileToObjectModel.CoreAssemblySymbolicIdentity, AssemblyFlags.Retargetable);
                }
                uint coreAssemblyRefToken = coreAssemblyRef.TokenValue;
                for (uint i = 1; i <= numberOfTypeRefs; ++i)
                {
                    TypeRefRow typeRefRow = peFileReader.TypeRefTable[i];
                    if (typeRefRow.ResolutionScope != coreAssemblyRefToken)
                    {
                        continue;
                    }
                    int namespaceName = peFileToObjectModel.GetNameFromOffset(typeRefRow.Namespace).UniqueKey;
                    if (namespaceName == systemName)
                    {
                        int typeDefName = peFileToObjectModel.GetNameFromOffset(typeRefRow.Name).UniqueKey;
                        if (typeDefName == voidName)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Void);
                        }
                        else if (typeDefName == booleanName)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Boolean);
                        }
                        else if (typeDefName == charName)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Char);
                        }
                        else if (typeDefName == byteName)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Byte);
                        }
                        else if (typeDefName == sByteName)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.SByte);
                        }
                        else if (typeDefName == int16Name)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Int16);
                        }
                        else if (typeDefName == uint16Name)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt16);
                        }
                        else if (typeDefName == int32Name)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Int32);
                        }
                        else if (typeDefName == uint32Name)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt32);
                        }
                        else if (typeDefName == int64Name)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Int64);
                        }
                        else if (typeDefName == uint64Name)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt64);
                        }
                        else if (typeDefName == stringName)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.String);
                        }
                        else if (typeDefName == intPtrName)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.IntPtr);
                        }
                        else if (typeDefName == uintPtrName)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.UIntPtr);
                        }
                        else if (typeDefName == objectName)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Object);
                        }
                        else if (typeDefName == singleName)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Single);
                        }
                        else if (typeDefName == doubleName)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Double);
                        }
                        else if (typeDefName == typedReference)
                        {
                            peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.TypedReference);
                        }
                        else if (typeDefName == enumName)
                        {
                            this.SystemEnum = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                        }
                        else if (typeDefName == valueTypeName)
                        {
                            this.SystemValueType = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                        }
                        else if (typeDefName == multicastDelegateName)
                        {
                            this.SystemMulticastDelegate = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                        }
                        else if (typeDefName == typeName)
                        {
                            this.SystemType = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                        }
                        else if (typeDefName == paramArrayAttributeName)
                        {
                            this.SystemParamArrayAttribute = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                        }
                    }
                }
                NamespaceReference systemNSR = peFileToObjectModel.GetNamespaceReferenceForString(coreAssemblyRef, nameTable.System);
                if (this.SystemEnum == null || (peFileToObjectModel.SystemEnumAssembly != null && coreAssemblyRef != peFileToObjectModel.SystemEnumAssembly))
                {
                    this.SystemEnum = peFileToObjectModel.typeCache.CreateCoreTypeReference(peFileToObjectModel.SystemEnumAssembly ?? coreAssemblyRef, systemNSR, nameTable.Enum, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                }
                if (this.SystemValueType == null || (peFileToObjectModel.SystemValueTypeAssembly != null && coreAssemblyRef != peFileToObjectModel.SystemValueTypeAssembly))
                {
                    this.SystemValueType = peFileToObjectModel.typeCache.CreateCoreTypeReference(peFileToObjectModel.SystemValueTypeAssembly ?? coreAssemblyRef, systemNSR, nameTable.ValueType, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                }
                if (this.SystemMulticastDelegate == null || (peFileToObjectModel.SystemMulticastDelegateAssembly != null && coreAssemblyRef != peFileToObjectModel.SystemMulticastDelegateAssembly))
                {
                    this.SystemMulticastDelegate = peFileToObjectModel.typeCache.CreateCoreTypeReference(peFileToObjectModel.SystemMulticastDelegateAssembly ?? coreAssemblyRef, systemNSR, nameTable.MulticastDelegate, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                }
                if (this.SystemType == null || (peFileToObjectModel.SystemTypeAssembly != null && coreAssemblyRef != peFileToObjectModel.SystemTypeAssembly))
                {
                    this.SystemType = peFileToObjectModel.typeCache.CreateCoreTypeReference(peFileToObjectModel.SystemTypeAssembly ?? coreAssemblyRef, systemNSR, nameTable.Type, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                }
                if (this.SystemParamArrayAttribute == null || (peFileToObjectModel.SystemParamArrayAttributeAssembly != null && coreAssemblyRef != peFileToObjectModel.SystemParamArrayAttributeAssembly))
                {
                    this.SystemParamArrayAttribute = peFileToObjectModel.typeCache.CreateCoreTypeReference(peFileToObjectModel.SystemParamArrayAttributeAssembly ?? coreAssemblyRef, systemNSR, peReader.ParamArrayAttribute, MetadataReaderSignatureTypeCode.NotModulePrimitive);
                }
            }
        }
Пример #19
0
     /*?*/
     internal override IModuleTypeReference GetAsTypeReference(
   PEFileToObjectModel peFileToObjectModel,
   IModuleModuleReference module
 )
     {
         foreach (AssemblyReference aref in peFileToObjectModel.GetAssemblyReferences()) {
         if (aref.AssemblyIdentity.Equals(this.AssemblyIdentity))
           return this.TypeName.GetAsTypeReference(peFileToObjectModel, aref);
           }
           if (module.ContainingAssembly.AssemblyIdentity.Equals(this.AssemblyIdentity))
         return this.TypeName.GetAsTypeReference(peFileToObjectModel, module);
           AssemblyFlags flags = this.Retargetable ? AssemblyFlags.Retargetable : (AssemblyFlags)0;
           return this.TypeName.GetAsTypeReference(peFileToObjectModel, new AssemblyReference(peFileToObjectModel, 0, this.AssemblyIdentity, flags));
     }
Пример #20
0
     /*?*/
     internal override IModuleTypeReference GetAsTypeReference(
   PEFileToObjectModel peFileToObjectModel,
   IModuleModuleReference module
 )
     {
         IModuleTypeReference/*?*/ elementType = this.ElementType.GetAsTypeReference(peFileToObjectModel, module);
           if (elementType == null)
         return null;
           if (this.Rank == 0) {
         return new VectorType(
           peFileToObjectModel,
           0xFFFFFFFF,
           elementType
         );
           } else {
         return new MatrixType(
           peFileToObjectModel,
           0xFFFFFFFF,
           elementType,
           this.Rank,
           TypeCache.EmptyUlongArray,
           TypeCache.EmptyIntArray
         );
           }
     }
Пример #21
0
     //^ [NotDelayed]
     internal SecurityAttributeDecoder20(
   PEFileToObjectModel peFileToObjectModel,
   MemoryReader signatureMemoryReader,
   SecurityAttribute securityAttribute
 )
         : base(peFileToObjectModel, signatureMemoryReader)
     {
         //^ this.SignatureMemoryReader = signatureMemoryReader; //TODO: Spec# bug. This assignment should not be necessary.
           this.SecurityAttributes = TypeCache.EmptySecurityAttributes;
           //^ base;
           byte prolog = this.SignatureMemoryReader.ReadByte();
           if (prolog != SerializationType.SecurityAttribute20Start) {
         return;
           }
           int numberOfAttributes = this.SignatureMemoryReader.ReadCompressedUInt32();
           SecurityCustomAttribute[] securityCustomAttributes = new SecurityCustomAttribute[numberOfAttributes];
           for (int i = 0; i < numberOfAttributes; ++i) {
         SecurityCustomAttribute/*?*/ secAttr = this.ReadSecurityAttribute(securityAttribute);
         if (secAttr == null) {
           //  MDError...
           return;
         }
         securityCustomAttributes[i] = secAttr;
           }
           //^ NonNullType.AssertInitialized(securityCustomAttributes);
           this.SecurityAttributes = new EnumerableArrayWrapper<SecurityCustomAttribute, ICustomAttribute>(securityCustomAttributes, Dummy.CustomAttribute);
     }
Пример #22
0
 internal TypeOfExpression(
   PEFileToObjectModel peFileToObjectModel,
   ITypeReference/*?*/ typeExpression
 ) {
   this.PEFileToObjectModel = peFileToObjectModel;
   this.TypeExpression = typeExpression;
 }
Пример #23
0
 internal override INamedTypeDefinition/*?*/ ResolveNominalTypeName(
   PEFileToObjectModel peFileToObjectModel
 ) {
   if (this.NamespaceName == null)
     return peFileToObjectModel.ResolveNamespaceTypeDefinition(
       peFileToObjectModel.NameTable.EmptyName,
       this.Name
     );
   else
     return peFileToObjectModel.ResolveNamespaceTypeDefinition(
       this.NamespaceName.FullyQualifiedName,
       this.Name
     );
 }
Пример #24
0
 internal CustomAttribute(PEFileToObjectModel peFileToObjectModel, uint attributeRowId, IMethodReference constructor,
   IMetadataExpression[]/*?*/ arguments, IMetadataNamedArgument[]/*?*/ namedArguments)
   : base(peFileToObjectModel) {
   this.AttributeRowId = attributeRowId;
   this.Constructor = constructor;
   this.Arguments = arguments;
   this.NamedArguments = namedArguments;
 }
Пример #25
0
 internal override INamedTypeDefinition/*?*/ ResolveNominalTypeName(
   PEFileToObjectModel peFileToObjectModel
 ) {
   var containingType = this.ContainingTypeName.ResolveNominalTypeName(peFileToObjectModel);
   if (containingType == null)
     return null;
   return peFileToObjectModel.ResolveNestedTypeDefinition(
     containingType,
     this.Name
   );
 }
Пример #26
0
 internal abstract ITypeReference/*?*/ GetAsTypeReference(
   PEFileToObjectModel peFileToObjectModel,
   IMetadataReaderModuleReference module
 );
Пример #27
0
 internal override ITypeReference/*?*/ GetAsTypeReference(PEFileToObjectModel peFileToObjectModel, IMetadataReaderModuleReference module) {
   var nominalType = this.GenericTemplate.GetAsNomimalType(peFileToObjectModel, module);
   if (nominalType == null) return null;
   int argumentUsed;
   return this.GetSpecializedTypeReference(peFileToObjectModel, nominalType, out argumentUsed, mostNested: true);
 }
Пример #28
0
 internal IMetadataReaderNamedTypeReference GetAsNamedTypeReference(
   PEFileToObjectModel peFileToObjectModel, IMetadataReaderModuleReference module
 ) {
   return this.GetAsNomimalType(peFileToObjectModel, module);
 }
Пример #29
0
 internal override ITypeReference/*?*/ GetAsTypeReference(PEFileToObjectModel peFileToObjectModel, IMetadataReaderModuleReference module) {
   ITypeReference/*?*/ elementType = this.ElementType.GetAsTypeReference(peFileToObjectModel, module);
   if (elementType == null) return null;
   if (this.Rank == 0)
     return Vector.GetVector(elementType, peFileToObjectModel.InternFactory);
   else
     return Matrix.GetMatrix(elementType, this.Rank, peFileToObjectModel.InternFactory);
 }
Пример #30
0
 internal override IMetadataReaderNamedTypeReference/*?*/ GetAsNomimalType(
   PEFileToObjectModel peFileToObjectModel,
   IMetadataReaderModuleReference module
 ) {
   return new NestedTypeNameTypeReference(module, this, peFileToObjectModel);
 }
Пример #31
0
     //^ [NotDelayed]
     internal CustomAttributeDecoder(
   PEFileToObjectModel peFileToObjectModel,
   MemoryReader signatureMemoryReader,
   uint customAttributeRowId,
   IModuleMethodReference attributeConstructor
 )
         : base(peFileToObjectModel, signatureMemoryReader)
     {
         //^ this.SignatureMemoryReader = signatureMemoryReader; //TODO: Spec# bug. This assignment should not be necessary.
           this.CustomAttribute = Dummy.CustomAttribute;
           //^ base;
           ushort prolog = this.SignatureMemoryReader.ReadUInt16();
           if (prolog != SerializationType.CustomAttributeStart) {
         return;
           }
           List<ExpressionBase> exprList = new List<ExpressionBase>();
           IModuleParameterTypeInformation[] modParams = attributeConstructor.RequiredModuleParameterInfos.RawArray;
           int len = modParams.Length;
           for (int i = 0; i < len; ++i) {
         IModuleTypeReference/*?*/ moduleTypeRef = modParams[i].ModuleTypeReference;
         if (moduleTypeRef == null) {
           //  Error...
           return;
         }
         ExpressionBase/*?*/ argument = this.ReadSerializedValue(moduleTypeRef);
         if (argument == null) {
           //  Error...
           this.decodeFailed = true;
           return;
         }
         exprList.Add(argument);
           }
           ushort numOfNamedArgs = this.SignatureMemoryReader.ReadUInt16();
           FieldOrPropertyNamedArgumentExpression[]/*?*/ namedArgumentArray = null;
           if (numOfNamedArgs > 0) {
         namedArgumentArray = new FieldOrPropertyNamedArgumentExpression[numOfNamedArgs];
         for (ushort i = 0; i < numOfNamedArgs; ++i) {
           bool isField = this.SignatureMemoryReader.ReadByte() == SerializationType.Field;
           IModuleTypeReference/*?*/ memberType = this.GetFieldOrPropType();
           if (memberType == null) {
         //  Error...
         return;
           }
           string/*?*/ memberStr = this.GetSerializedString();
           if (memberStr == null)
         return;
           IName memberName = this.PEFileToObjectModel.NameTable.GetNameFor(memberStr);
           ExpressionBase/*?*/ value = this.ReadSerializedValue(memberType);
           if (value == null) {
         //  Error...
         return;
           }
           IModuleTypeReference/*?*/ moduleTypeRef = attributeConstructor.OwningTypeReference;
           if (moduleTypeRef == null) {
         //  Error...
         return;
           }
           FieldOrPropertyNamedArgumentExpression namedArg = new FieldOrPropertyNamedArgumentExpression(memberName, moduleTypeRef, isField, memberType, value);
           namedArgumentArray[i] = namedArg;
         }
           }
           EnumerableArrayWrapper<ExpressionBase, IMetadataExpression> arguments = TypeCache.EmptyExpressionList;
           if (exprList.Count > 0)
         arguments = new EnumerableArrayWrapper<ExpressionBase, IMetadataExpression>(exprList.ToArray(), Dummy.Expression);
           EnumerableArrayWrapper<FieldOrPropertyNamedArgumentExpression, IMetadataNamedArgument> namedArguments = TypeCache.EmptyNamedArgumentList;
           if (namedArgumentArray != null)
         namedArguments = new EnumerableArrayWrapper<FieldOrPropertyNamedArgumentExpression, IMetadataNamedArgument>(namedArgumentArray, Dummy.NamedArgument);
           this.CustomAttribute = new CustomAttribute(this.PEFileToObjectModel, customAttributeRowId, attributeConstructor, arguments, namedArguments);
     }
Пример #32
0
 private ITypeReference GetSpecializedTypeReference(PEFileToObjectModel peFileToObjectModel, INamedTypeReference nominalType, out int argumentUsed, bool mostNested) {
   argumentUsed = 0;
   int len = this.GenericArguments.Count;
   var nestedType = nominalType as INestedTypeReference;
   if (nestedType != null) {
     var parentTemplate = this.GetSpecializedTypeReference(peFileToObjectModel, (INamedTypeReference)nestedType.ContainingType, out argumentUsed, mostNested: false);
     if (parentTemplate != nestedType.ContainingType)
       nominalType = new SpecializedNestedTypeReference(nestedType, parentTemplate, peFileToObjectModel.InternFactory);
   }
   var argsToUse = mostNested ? len-argumentUsed : nominalType.GenericParameterCount;
   if (argsToUse == 0) return nominalType;
   var genericArgumentsReferences = new ITypeReference[argsToUse];
   for (int i = 0; i < argsToUse; ++i)
     genericArgumentsReferences[i] = this.GenericArguments[i+argumentUsed].GetAsTypeReference(peFileToObjectModel, peFileToObjectModel.Module)??Dummy.TypeReference;
   argumentUsed += argsToUse;
   return new GenericTypeInstanceReference(nominalType, IteratorHelper.GetReadonly(genericArgumentsReferences), peFileToObjectModel.InternFactory);
 }
Пример #33
0
 internal StandAloneMethodSignatureConverter(PEFileToObjectModel peFileToObjectModel, MethodDefinition moduleMethodDef, MemoryReader signatureMemoryReader)
   : base(peFileToObjectModel, signatureMemoryReader, moduleMethodDef) {
   this.RequiredParameters = Enumerable<IParameterTypeInformation>.Empty;
   this.VarArgParameters = Enumerable<IParameterTypeInformation>.Empty;
   //  TODO: Check minimum required size of the signature...
   this.FirstByte = this.SignatureMemoryReader.ReadByte();
   int paramCount = this.SignatureMemoryReader.ReadCompressedUInt32();
   bool dummyPinned;
   this.ReturnCustomModifiers = this.GetCustomModifiers(out dummyPinned);
   byte retByte = this.SignatureMemoryReader.PeekByte(0);
   if (retByte == ElementType.Void) {
     this.ReturnTypeReference = peFileToObjectModel.PlatformType.SystemVoid;
     this.SignatureMemoryReader.SkipBytes(1);
   } else if (retByte == ElementType.TypedReference) {
     this.ReturnTypeReference = peFileToObjectModel.PlatformType.SystemTypedReference;
     this.SignatureMemoryReader.SkipBytes(1);
   } else {
     if (retByte == ElementType.ByReference) {
       this.IsReturnByReference = true;
       this.SignatureMemoryReader.SkipBytes(1);
     }
     this.ReturnTypeReference = this.GetTypeReference();
   }
   if (paramCount > 0) {
     IParameterTypeInformation[] reqModuleParamArr = this.GetModuleParameterTypeInformations(Dummy.Signature, paramCount);
     if (reqModuleParamArr.Length > 0) this.RequiredParameters = IteratorHelper.GetReadonly(reqModuleParamArr);
     IParameterTypeInformation[] varArgModuleParamArr = this.GetModuleParameterTypeInformations(Dummy.Signature, paramCount - reqModuleParamArr.Length);
     if (varArgModuleParamArr.Length > 0) this.VarArgParameters = IteratorHelper.GetReadonly(varArgModuleParamArr);
   }
 }
Пример #34
0
 internal override ITypeReference GetAsTypeReference(
   PEFileToObjectModel peFileToObjectModel,
   IMetadataReaderModuleReference module
 ) {
   ITypeReference/*?*/ targetType = this.TargetType.GetAsTypeReference(peFileToObjectModel, module);
   if (targetType == null) return null;
   return ManagedPointerType.GetManagedPointerType(targetType, peFileToObjectModel.InternFactory);
 }
Пример #35
0
     /*?*/
     internal abstract IModuleNominalType GetAsNomimalType(
   PEFileToObjectModel peFileToObjectModel,
   IModuleModuleReference module
 );
Пример #36
0
 internal LocalVariableSignatureConverter(
   PEFileToObjectModel peFileToObjectModel,
   MethodBody owningMethodBody,
   MemoryReader signatureMemoryReader
 )
   : base(peFileToObjectModel, signatureMemoryReader, owningMethodBody.MethodDefinition) {
   this.OwningMethodBody = owningMethodBody;
   byte firstByte = this.SignatureMemoryReader.ReadByte();
   if (!SignatureHeader.IsLocalVarSignature(firstByte)) {
     //  MDError
   }
   int locVarCount = this.SignatureMemoryReader.ReadCompressedUInt32();
   LocalVariableDefinition[] locVarArr = new LocalVariableDefinition[locVarCount];
   for (int i = 0; i < locVarCount; ++i) {
     locVarArr[i] = this.GetLocalVariable((uint)i);
   }
   this.LocalVariables = locVarArr;
 }
Пример #37
0
     /*?*/
     internal abstract TypeBase ResolveNominalTypeName(
   PEFileToObjectModel peFileToObjectModel
 );
Пример #38
0
 internal ILReader(
   MethodDefinition methodDefinition,
   MethodIL methodIL
 ) {
   this.MethodDefinition = methodDefinition;
   this.PEFileToObjectModel = methodDefinition.PEFileToObjectModel;
   this.MethodIL = methodIL;
   this.MethodBody = new MethodBody(methodDefinition, methodIL.LocalVariablesInited, methodIL.MaxStack);
   this.EndOfMethodOffset = (uint)methodIL.EncodedILMemoryBlock.Length;
 }
Пример #39
0
        //  Caller should lock peFileToObjectModel
        internal CoreTypes(PEFileToObjectModel peFileToObjectModel)
        {
            INameTable             nameTable        = peFileToObjectModel.NameTable;
            PEFileReader           peFileReader     = peFileToObjectModel.PEFileReader;
            PeReader               peReader         = peFileToObjectModel.ModuleReader;
            Module                 module           = peFileToObjectModel.Module;
            AssemblyIdentity /*?*/ assemblyIdentity = module.ModuleIdentity as AssemblyIdentity;

            int systemName              = nameTable.System.UniqueKey;
            int voidName                = nameTable.Void.UniqueKey;
            int booleanName             = nameTable.Boolean.UniqueKey;
            int charName                = nameTable.Char.UniqueKey;
            int byteName                = nameTable.Byte.UniqueKey;
            int sByteName               = nameTable.SByte.UniqueKey;
            int int16Name               = nameTable.Int16.UniqueKey;
            int uint16Name              = nameTable.UInt16.UniqueKey;
            int int32Name               = nameTable.Int32.UniqueKey;
            int uint32Name              = nameTable.UInt32.UniqueKey;
            int int64Name               = nameTable.Int64.UniqueKey;
            int uint64Name              = nameTable.UInt64.UniqueKey;
            int stringName              = nameTable.String.UniqueKey;
            int intPtrName              = nameTable.IntPtr.UniqueKey;
            int uintPtrName             = nameTable.UIntPtr.UniqueKey;
            int objectName              = nameTable.Object.UniqueKey;
            int singleName              = nameTable.Single.UniqueKey;
            int doubleName              = nameTable.Double.UniqueKey;
            int decimalName             = nameTable.Decimal.UniqueKey;
            int typedReference          = nameTable.TypedReference.UniqueKey;
            int enumName                = nameTable.Enum.UniqueKey;
            int valueTypeName           = nameTable.ValueType.UniqueKey;
            int multicastDelegateName   = nameTable.MulticastDelegate.UniqueKey;
            int typeName                = nameTable.Type.UniqueKey;
            int arrayName               = nameTable.Array.UniqueKey;
            int paramArrayAttributeName = peReader.ParamArrayAttribute.UniqueKey;

            if (assemblyIdentity != null && assemblyIdentity.Equals(peReader.metadataReaderHost.CoreAssemblySymbolicIdentity))
            {
                peReader.RegisterCoreAssembly(module as Assembly);
                uint numberOfTypeDefs = peFileReader.TypeDefTable.NumberOfRows;
                for (uint i = 1; i <= numberOfTypeDefs; ++i)
                {
                    TypeDefRow typeDefRow = peFileReader.TypeDefTable[i];
                    if (!typeDefRow.IsNested)
                    {
                        int namespaceName = peFileToObjectModel.GetNameFromOffset(typeDefRow.Namespace).UniqueKey;
                        if (namespaceName == systemName)
                        {
                            int typeDefName = peFileToObjectModel.GetNameFromOffset(typeDefRow.Name).UniqueKey;
                            if (typeDefName == voidName)
                            {
                                this.SystemVoid = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Void);
                            }
                            else if (typeDefName == booleanName)
                            {
                                this.SystemBoolean = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Boolean);
                            }
                            else if (typeDefName == charName)
                            {
                                this.SystemChar = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Char);
                            }
                            else if (typeDefName == byteName)
                            {
                                this.SystemByte = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Byte);
                            }
                            else if (typeDefName == sByteName)
                            {
                                this.SystemSByte = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.SByte);
                            }
                            else if (typeDefName == int16Name)
                            {
                                this.SystemInt16 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Int16);
                            }
                            else if (typeDefName == uint16Name)
                            {
                                this.SystemUInt16 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.UInt16);
                            }
                            else if (typeDefName == int32Name)
                            {
                                this.SystemInt32 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Int32);
                            }
                            else if (typeDefName == uint32Name)
                            {
                                this.SystemUInt32 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.UInt32);
                            }
                            else if (typeDefName == int64Name)
                            {
                                this.SystemInt64 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Int64);
                            }
                            else if (typeDefName == uint64Name)
                            {
                                this.SystemUInt64 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.UInt64);
                            }
                            else if (typeDefName == stringName)
                            {
                                this.SystemString = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.String);
                            }
                            else if (typeDefName == intPtrName)
                            {
                                this.SystemIntPtr = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.IntPtr);
                            }
                            else if (typeDefName == uintPtrName)
                            {
                                this.SystemUIntPtr = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.UIntPtr);
                            }
                            else if (typeDefName == objectName)
                            {
                                this.SystemObject = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Object);
                            }
                            else if (typeDefName == singleName)
                            {
                                this.SystemSingle = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Single);
                            }
                            else if (typeDefName == doubleName)
                            {
                                this.SystemDouble = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Double);
                            }
                            else if (typeDefName == decimalName)
                            {
                                this.SystemDecimal = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                            }
                            else if (typeDefName == typedReference)
                            {
                                this.SystemTypedReference = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.TypedReference);
                            }
                            else if (typeDefName == enumName)
                            {
                                this.SystemEnum = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                            }
                            else if (typeDefName == valueTypeName)
                            {
                                this.SystemValueType = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                            }
                            else if (typeDefName == multicastDelegateName)
                            {
                                this.SystemMulticastDelegate = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                            }
                            else if (typeDefName == typeName)
                            {
                                this.SystemType = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                            }
                            else if (typeDefName == arrayName)
                            {
                                this.SystemArray = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                            }
                            else if (typeDefName == paramArrayAttributeName)
                            {
                                this.SystemParamArrayAttribute = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                            }
                        }
                    }
                }
            }
            else
            {
                uint numberOfTypeRefs = peFileReader.TypeRefTable.NumberOfRows;
                AssemblyReference /*?*/ coreAssemblyRef = peFileToObjectModel.FindAssemblyReference(peReader.metadataReaderHost.CoreAssemblySymbolicIdentity);
                if (coreAssemblyRef == null)
                {
                    //  Error...
                    coreAssemblyRef = new AssemblyReference(peFileToObjectModel, 0, peReader.metadataReaderHost.CoreAssemblySymbolicIdentity, AssemblyFlags.Retargetable);
                }
                uint coreAssemblyRefToken = coreAssemblyRef.TokenValue;
                for (uint i = 1; i <= numberOfTypeRefs; ++i)
                {
                    TypeRefRow typeRefRow = peFileReader.TypeRefTable[i];
                    if (typeRefRow.ResolutionScope != coreAssemblyRefToken)
                    {
                        continue;
                    }
                    int namespaceName = peFileToObjectModel.GetNameFromOffset(typeRefRow.Namespace).UniqueKey;
                    if (namespaceName == systemName)
                    {
                        int typeDefName = peFileToObjectModel.GetNameFromOffset(typeRefRow.Name).UniqueKey;
                        if (typeDefName == voidName)
                        {
                            this.SystemVoid = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Void);
                        }
                        else if (typeDefName == booleanName)
                        {
                            this.SystemBoolean = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Boolean);
                        }
                        else if (typeDefName == charName)
                        {
                            this.SystemChar = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Char);
                        }
                        else if (typeDefName == byteName)
                        {
                            this.SystemByte = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Byte);
                        }
                        else if (typeDefName == sByteName)
                        {
                            this.SystemSByte = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.SByte);
                        }
                        else if (typeDefName == int16Name)
                        {
                            this.SystemInt16 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Int16);
                        }
                        else if (typeDefName == uint16Name)
                        {
                            this.SystemUInt16 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.UInt16);
                        }
                        else if (typeDefName == int32Name)
                        {
                            this.SystemInt32 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Int32);
                        }
                        else if (typeDefName == uint32Name)
                        {
                            this.SystemUInt32 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.UInt32);
                        }
                        else if (typeDefName == int64Name)
                        {
                            this.SystemInt64 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Int64);
                        }
                        else if (typeDefName == uint64Name)
                        {
                            this.SystemUInt64 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.UInt64);
                        }
                        else if (typeDefName == stringName)
                        {
                            this.SystemString = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.String);
                        }
                        else if (typeDefName == intPtrName)
                        {
                            this.SystemIntPtr = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.IntPtr);
                        }
                        else if (typeDefName == uintPtrName)
                        {
                            this.SystemUIntPtr = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.UIntPtr);
                        }
                        else if (typeDefName == objectName)
                        {
                            this.SystemObject = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Object);
                        }
                        else if (typeDefName == singleName)
                        {
                            this.SystemSingle = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Single);
                        }
                        else if (typeDefName == doubleName)
                        {
                            this.SystemDouble = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Double);
                        }
                        else if (typeDefName == decimalName)
                        {
                            this.SystemDecimal = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                        }
                        else if (typeDefName == typedReference)
                        {
                            this.SystemTypedReference = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.TypedReference);
                        }
                        else if (typeDefName == enumName)
                        {
                            this.SystemEnum = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                        }
                        else if (typeDefName == valueTypeName)
                        {
                            this.SystemValueType = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                        }
                        else if (typeDefName == multicastDelegateName)
                        {
                            this.SystemMulticastDelegate = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                        }
                        else if (typeDefName == typeName)
                        {
                            this.SystemType = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                        }
                        else if (typeDefName == arrayName)
                        {
                            this.SystemArray = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                        }
                        else if (typeDefName == paramArrayAttributeName)
                        {
                            this.SystemParamArrayAttribute = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive);
                        }
                    }
                }
                NamespaceReference systemNSR = peFileToObjectModel.GetNamespaceReferenceForString(coreAssemblyRef, nameTable.System);
                if (this.SystemVoid == null)
                {
                    this.SystemVoid = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Void, ModuleSignatureTypeCode.Void);
                }
                if (this.SystemBoolean == null)
                {
                    this.SystemBoolean = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Boolean, ModuleSignatureTypeCode.Boolean);
                }
                if (this.SystemChar == null)
                {
                    this.SystemChar = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Char, ModuleSignatureTypeCode.Char);
                }
                if (this.SystemByte == null)
                {
                    this.SystemByte = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Byte, ModuleSignatureTypeCode.Byte);
                }
                if (this.SystemSByte == null)
                {
                    this.SystemSByte = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.SByte, ModuleSignatureTypeCode.SByte);
                }
                if (this.SystemInt16 == null)
                {
                    this.SystemInt16 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Int16, ModuleSignatureTypeCode.Int16);
                }
                if (this.SystemUInt16 == null)
                {
                    this.SystemUInt16 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.UInt16, ModuleSignatureTypeCode.UInt16);
                }
                if (this.SystemInt32 == null)
                {
                    this.SystemInt32 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Int32, ModuleSignatureTypeCode.Int32);
                }
                if (this.SystemUInt32 == null)
                {
                    this.SystemUInt32 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.UInt32, ModuleSignatureTypeCode.UInt32);
                }
                if (this.SystemInt64 == null)
                {
                    this.SystemInt64 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Int64, ModuleSignatureTypeCode.Int64);
                }
                if (this.SystemUInt64 == null)
                {
                    this.SystemUInt64 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.UInt64, ModuleSignatureTypeCode.UInt64);
                }
                if (this.SystemString == null)
                {
                    this.SystemString = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.String, ModuleSignatureTypeCode.String);
                }
                if (this.SystemIntPtr == null)
                {
                    this.SystemIntPtr = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.IntPtr, ModuleSignatureTypeCode.IntPtr);
                }
                if (this.SystemUIntPtr == null)
                {
                    this.SystemUIntPtr = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.UIntPtr, ModuleSignatureTypeCode.UIntPtr);
                }
                if (this.SystemObject == null)
                {
                    this.SystemObject = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Object, ModuleSignatureTypeCode.Object);
                }
                if (this.SystemSingle == null)
                {
                    this.SystemSingle = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Single, ModuleSignatureTypeCode.Single);
                }
                if (this.SystemDouble == null)
                {
                    this.SystemDouble = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Double, ModuleSignatureTypeCode.Double);
                }
                if (this.SystemDecimal == null)
                {
                    this.SystemDecimal = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Decimal, ModuleSignatureTypeCode.NotModulePrimitive);
                }
                if (this.SystemTypedReference == null)
                {
                    this.SystemTypedReference = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.TypedReference, ModuleSignatureTypeCode.NotModulePrimitive);
                }
                if (this.SystemEnum == null)
                {
                    this.SystemEnum = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Enum, ModuleSignatureTypeCode.NotModulePrimitive);
                }
                if (this.SystemValueType == null)
                {
                    this.SystemValueType = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.ValueType, ModuleSignatureTypeCode.NotModulePrimitive);
                }
                if (this.SystemMulticastDelegate == null)
                {
                    this.SystemMulticastDelegate = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.MulticastDelegate, ModuleSignatureTypeCode.NotModulePrimitive);
                }
                if (this.SystemType == null)
                {
                    this.SystemType = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Type, ModuleSignatureTypeCode.NotModulePrimitive);
                }
                if (this.SystemArray == null)
                {
                    this.SystemArray = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Array, ModuleSignatureTypeCode.NotModulePrimitive);
                }
                if (this.SystemParamArrayAttribute == null)
                {
                    this.SystemParamArrayAttribute = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, peReader.ParamArrayAttribute, ModuleSignatureTypeCode.NotModulePrimitive);
                }
            }
        }