Esempio n. 1
0
 internal static void Read(PEReader buff, TableRow[] typeRefs, bool resolve)
 {
     for (uint i = 0; i < typeRefs.Length; i++)
     {
         uint   resScopeIx = buff.GetCodedIndex(CIx.ResolutionScope);
         string name       = buff.GetString();
         string nameSpace  = buff.GetString();
         if (buff.CodedTable(CIx.ResolutionScope, resScopeIx) == MDTable.TypeRef)
         {
             typeRefs[i] = new NestedClassRef(resScopeIx, nameSpace, name);
         }
         else
         {
             typeRefs[i] = new ClassRef(resScopeIx, nameSpace, name);
         }
         typeRefs[i].Row = i + 1;
     }
     if (resolve)
     {
         foreach (TableRow typeRef in typeRefs)
         {
             ((ClassRef)typeRef).ResolveParent(buff, false);
         }
     }
 }
Esempio n. 2
0
        internal override void ResolveParent(PEReader buff, bool isExtern)
        {
            if (parent != null)
            {
                return;
            }
            CIx cIx = CIx.ResolutionScope;

            if (isExtern)
            {
                cIx = CIx.Implementation;
            }
            parent = (ClassRef)buff.GetCodedElement(cIx, resScopeIx);
            parent.ResolveParent(buff, isExtern);
            parent = (ClassRef)buff.GetCodedElement(cIx, resScopeIx);
            if (parent == null)
            {
                return;
            }
            NestedClassRef existing = parent.GetNestedClass(Name);

            if (existing == null)
            {
                scope = parent.GetScope();
                parent.AddToClassList(this);
            }
            else if (isExtern)
            {
                buff.InsertInTable(MDTable.ExportedType, Row, existing);
            }
            else
            {
                buff.InsertInTable(MDTable.TypeRef, Row, existing);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Add a nested class to this class
        /// </summary>
        /// <param name="name">Nested class name</param>
        /// <returns>Descriptor for the nested class "name"</returns>
        public NestedClassRef AddNestedClass(string name)
        {
            Contract.Requires(name != null);
            NestedClassRef nestedClass = (NestedClassRef)GetNested(name);

            if (nestedClass != null)
            {
                DescriptorError(nestedClass);
            }
            nestedClass = new NestedClassRef(this, name);
            AddToClassList(nestedClass);
            return(nestedClass);
        }
Esempio n. 4
0
 internal static void GetClassRefs(PEReader buff, TableRow[] typeRefs, ReferenceScope paren, uint[] parIxs)
 {
     Contract.Requires(buff != null);
     Contract.Requires(typeRefs != null);
     Contract.Requires(paren != null);
     Contract.Requires(parIxs != null);
     int num = typeRefs.Length;
     uint[] fieldStart = new uint[num + 1], methStart = new uint[num + 1], extends = new uint[num + 1];
     for (int i = 0; i < num; i++)
     {
         uint flags = buff.ReadUInt32();
         string name = buff.GetString();
         string nameSpace = buff.GetString();
         extends[i] = buff.GetCodedIndex(CIx.TypeDefOrRef);
         fieldStart[i] = buff.GetIndex(MDTable.Field);
         methStart[i] = buff.GetIndex(MDTable.Method);
         //Console.WriteLine("flags = " + Hex.Int(flags));
         if (i == 0) // ASSERT first entry is always <Module>
             typeRefs[i] = paren.GetDefaultClass();
         else if (isPublic(flags))
         {
             if (parIxs[i] != 0)
             {
                 typeRefs[i] = new NestedClassRef(paren, nameSpace, name);
             }
             else
             {
                 typeRefs[i] = paren.GetExistingClass(nameSpace, name);
                 if (typeRefs[i] == null)
                 {
                     typeRefs[i] = new ClassRef(paren, nameSpace, name);
                     paren.AddToClassList((ClassRef)typeRefs[i]);
                 }
             }
         }
     }
     fieldStart[num] = buff.GetTableSize(MDTable.Field) + 1;
     methStart[num] = buff.GetTableSize(MDTable.Method) + 1;
     // Find Nested Classes
     for (int i = 0; i < typeRefs.Length; i++)
     {
         if ((typeRefs[i] != null) && (typeRefs[i] is NestedClassRef))
         {
             NestedClassRef nRef = (NestedClassRef)typeRefs[i];
             ClassRef nPar = (ClassRef)typeRefs[parIxs[i] - 1];
             if (nPar == null)
             {  // parent is private, so ignore
                 typeRefs[i] = null;
             }
             else
             {
                 nRef.SetParent(nPar);
                 nPar.AddToClassList(nRef);
             }
         }
         if (typeRefs[i] != null)
         {
             if (buff.GetCodedElement(CIx.TypeDefOrRef, extends[i]) == MSCorLib.mscorlib.ValueType())
                 ((ClassRef)typeRefs[i]).MakeValueClass();
             buff.SetElementPosition(MDTable.Field, fieldStart[i]);
             FieldDef.GetFieldRefs(buff, fieldStart[i + 1] - fieldStart[i], (ClassRef)typeRefs[i]);
             buff.SetElementPosition(MDTable.Method, methStart[i]);
             MethodDef.GetMethodRefs(buff, methStart[i + 1] - methStart[i], (ClassRef)typeRefs[i]);
         }
     }
 }
Esempio n. 5
0
 internal static void Read(PEReader buff, TableRow[] typeRefs, bool resolve)
 {
     for (uint i = 0; i < typeRefs.Length; i++)
     {
         uint resScopeIx = buff.GetCodedIndex(CIx.ResolutionScope);
         string name = buff.GetString();
         string nameSpace = buff.GetString();
         if (buff.CodedTable(CIx.ResolutionScope, resScopeIx) == MDTable.TypeRef)
             typeRefs[i] = new NestedClassRef(resScopeIx, nameSpace, name);
         else
             typeRefs[i] = new ClassRef(resScopeIx, nameSpace, name);
         typeRefs[i].Row = i + 1;
     }
     if (resolve)
     {
         foreach (TableRow typeRef in typeRefs)
         {
             ((ClassRef)typeRef).ResolveParent(buff, false);
         }
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Add a nested class to this class
 /// </summary>
 /// <param name="name">Nested class name</param>
 /// <returns>Descriptor for the nested class "name"</returns>
 public NestedClassRef AddNestedClass(string name)
 {
     Contract.Requires(name != null);
     NestedClassRef nestedClass = (NestedClassRef)GetNested(name);
     if (nestedClass != null) DescriptorError(nestedClass);
     nestedClass = new NestedClassRef(this, name);
     AddToClassList(nestedClass);
     return nestedClass;
 }