Esempio n. 1
0
 internal ClassLayout(ushort pack, uint cSize, ClassDef par)
 {
     packSize = pack;
     classSize = cSize;
     parent = par;
     tabIx = MDTable.ClassLayout;
 }
Esempio n. 2
0
 /*-------------------- Constructors ---------------------------------*/
 internal Feature(string name, ClassDef par)
 {
     parent = par;
     this.name = name;
 }
Esempio n. 3
0
 internal static void Read(PEReader buff, TableRow[] typeDefs, bool isMSCorLib)
 {
     Contract.Requires(buff != null);
     Contract.Requires(typeDefs != null);
     ClassDef prevDef = new ClassDef(buff, 1, isMSCorLib);
     typeDefs[0] = prevDef;
     for (int i = 1; i < typeDefs.Length; i++)
     {
         ClassDef typeDef = new ClassDef(buff, (uint)i + 1, isMSCorLib);
         prevDef.fieldEndIx = typeDef.fieldIx;
         prevDef.methodEndIx = typeDef.methodIx;
         prevDef = typeDef;
         typeDefs[i] = typeDef;
     }
     prevDef.fieldEndIx = buff.GetTableSize(MDTable.Field) + 1;
     prevDef.methodEndIx = buff.GetTableSize(MDTable.Method) + 1;
 }
Esempio n. 4
0
 internal void SetParent(ClassDef par)
 {
     parent = par;
 }
Esempio n. 5
0
 internal NestedClassDef MakeNestedClass(ClassDef parent)
 {
     Contract.Requires(parent != null);
     NestedClassDef nClass = new NestedClassDef(parent, (TypeAttr)flags, Name);
     ClassDef tmp = nClass;
     tmp.fieldIx = fieldIx;
     tmp.fieldEndIx = fieldEndIx;
     tmp.methodIx = methodIx;
     tmp.methodEndIx = methodEndIx;
     tmp.extendsIx = extendsIx;
     tmp.Row = Row;
     parent.nestedClasses.Add(nClass);
     return nClass;
 }
Esempio n. 6
0
 internal void SetDefaultClass(ClassDef dClass)
 {
     Contract.Requires(dClass != null);
     defaultClass = dClass;
 }
Esempio n. 7
0
 /// <summary>
 /// Add a class to this module
 /// If this class already exists, throw an exception
 /// </summary>
 /// <param name="aClass">The class to be added</param>
 public void AddClass(ClassDef aClass)
 {
     Contract.Requires(aClass != null);
     ClassDef eClass = GetClass(aClass.NameSpace, aClass.Name);
     if (eClass != null)
         throw new DescriptorException("Class " + aClass.NameString());
     classes.Add(aClass);
     // MERGE change Refs to Defs here, fix this
     aClass.SetScope((PEFile)this);
 }
Esempio n. 8
0
 /*-------------------- Constructors ---------------------------------*/
 internal Module(string mName)
     : base(GetBaseName(mName))
 {
     mvid = Guid.NewGuid();
     //isDLL = name.EndsWith(".dll") || name.EndsWith(".DLL");
     defaultClass = new ClassDef((PEFile)this, TypeAttr.Private, "", "<Module>");
     defaultClass.MakeSpecial();
     tabIx = MDTable.Module;
     ismscorlib = name.ToLower() == "mscorlib.dll";
     if (Diag.DiagOn) Console.WriteLine("Module name = " + name);
     // FIXME Contract.Ensures(defaultClass != null);
 }
Esempio n. 9
0
 internal override void Resolve(PEReader buff)
 {
     theClass = (ClassDef)buff.GetElement(MDTable.TypeDef, classIx);
     theInterface = (Class)buff.GetCodedElement(CIx.TypeDefOrRef, interfacesIndex);
     theClass.AddImplementedInterface(this);
 }
Esempio n. 10
0
 internal InterfaceImpl(ClassDef theClass, TableRow theInterface)
 {
     Contract.Requires(theClass != null);
     Contract.Requires(theInterface != null);
     this.theClass = theClass;
     this.theInterface = (Class)theInterface;
     tabIx = MDTable.InterfaceImpl;
 }
Esempio n. 11
0
 internal static string[] ReadNames(PEReader buff, ClassDef theClass, uint classIx)
 {
     return Feature.GetFeatureNames(buff, MDTable.Event, MDTable.EventMap, theClass, classIx);
 }
Esempio n. 12
0
 internal void ChangeRefsToDefs(ClassDef newType, ClassDef[] oldTypes)
 {
     throw new NotYetImplementedException("Merge for Properties");
 }
Esempio n. 13
0
 /*-------------------- Constructors ---------------------------------*/
 internal Event(string name, Type eType, ClassDef parent)
     : base(name, parent)
 {
     eventType = eType;
     tabIx = MDTable.Event;
 }
Esempio n. 14
0
 /*-------------------- Constructors ---------------------------------*/
 internal Property(string name, Type retType, Type[] pars, ClassDef parent)
     : base(name, parent)
 {
     returnType = retType;
     parList = pars;
     if (pars != null) numPars = (uint)pars.Length;
     tabIx = MDTable.Property;
 }
Esempio n. 15
0
 internal static string[] GetFeatureNames(PEReader buff, MDTable tabIx, MDTable mapTabIx,
     ClassDef theClass, uint classIx)
 {
     buff.SetElementPosition(mapTabIx, 0);
     uint start = 0;
     uint i = 0;
     for (; (i < buff.GetTableSize(tabIx)) && (start == 0); i++)
     {
         if (buff.GetIndex(MDTable.TypeDef) == classIx)
         {
             start = buff.GetIndex(tabIx);
         }
     }
     if (start == 0) return null;
     uint end;
     if (i < buff.GetTableSize(mapTabIx))
     {
         uint junk = buff.GetIndex(MDTable.TypeDef);
         end = buff.GetIndex(tabIx);
     }
     else
         end = buff.GetTableSize(tabIx);
     if (tabIx == MDTable.Event)
         theClass.eventIx = start;
     else
         theClass.propIx = start;
     string[] names = new string[end - start];
     buff.SetElementPosition(tabIx, start);
     for (i = start; i < end; i++)
     {
         uint junk = buff.ReadUInt16();
         names[i] = buff.GetString();
         if (tabIx == MDTable.Event)
             junk = buff.GetCodedIndex(CIx.TypeDefOrRef);
         else
             junk = buff.GetBlobIx();
     }
     return names;
 }
Esempio n. 16
0
 internal void ChangeRefsToDefs(ClassDef newPar, ClassDef[] oldTypes)
 {
     parent = newPar;
     bool changeType = false;
     for (int i = 0; i < oldTypes.Length && !changeType; i++)
     {
         if (type == oldTypes[i])
             type = newPar;
     }
 }
Esempio n. 17
0
 internal void ChangeRefsToDefs(ClassDef newPar, ClassDef[] oldTypes)
 {
     parent = newPar;
     sig.ChangeParTypes(newPar, oldTypes);
     if (code != null)
         code.ChangeRefsToDefs(newPar, oldTypes);
 }
Esempio n. 18
0
 internal void ChangeRefsToDefs(ClassDef newType, ClassDef[] oldTypes)
 {
     foreach (ClassDef oldType in oldTypes)
     {
         if (retType == oldType) retType = newType;
         for (int j = 0; j < numPars; j++)
         {
             if (parTypes[j] == oldType)
                 parTypes[j] = newType;
         }
         for (int j = 0; j < numOptPars; j++)
         {
             if (optParTypes[j] == oldType)
                 optParTypes[j] = newType;
         }
     }
 }
Esempio n. 19
0
 /*------------------------- public set and get methods --------------------------*/
 /// <summary>
 /// Add a class to this Module
 /// If this class already exists, throw an exception
 /// </summary>
 /// <param name="attrSet">attributes of this class</param>
 /// <param name="nsName">name space name</param>
 /// <param name="name">class name</param>
 /// <returns>a descriptor for this new class</returns>
 public ClassDef AddClass(TypeAttr attrSet, string nsName, string name)
 {
     //FIXME Contract.Requires(classes != null);
     ClassDef aClass = GetClass(nsName, name);
     if (aClass != null)
         throw new DescriptorException("Class " + aClass.NameString());
     aClass = new ClassDef((PEFile)this, attrSet, nsName, name);
     classes.Add(aClass);
     return aClass;
 }
Esempio n. 20
0
 internal void ChangeRefsToDefs(ClassDef newType, ClassDef[] oldTypes)
 {
     for (int i = 0; i < tide; i++) {
     if (buffer[i] is SigInstr) {
       CalliSig sig = ((SigInstr)buffer[i]).GetSig();
       sig.ChangeRefsToDefs(newType, oldTypes);
     }
     else if (buffer[i] is TypeInstr) {
       TypeInstr tinst = (TypeInstr)buffer[i];
       if (tinst.GetTypeArg() is ClassDef) {
     ClassDef iType = (ClassDef)tinst.GetTypeArg();
     bool changed = false;
     for (int j = 0; (j < oldTypes.Length) && !changed; j++) {
       if (iType == oldTypes[j])
         tinst.SetTypeArg(newType);
     }
       }
     }
       }
 }
Esempio n. 21
0
 internal bool isDefaultClass(ClassDef aClass)
 {
     return aClass == defaultClass;
 }
Esempio n. 22
0
 internal override void Resolve(PEReader buff)
 {
     parent = (ClassDef)buff.GetElement(MDTable.TypeDef, parentIx);
     if (parent != null) parent.Layout = this;
 }
Esempio n. 23
0
 internal void ChangeRefsToDefs(ClassDef newType, ClassDef[] oldTypes)
 {
     Contract.Requires(newType != null);
     Contract.Requires(oldTypes != null);
     foreach (ClassDef oldType in oldTypes)
     {
         foreach (object field in oldType.fields)
             ((FieldDef)field).ChangeRefsToDefs(this, oldTypes);
         foreach (object method in oldType.methods)
             ((MethodDef)method).ChangeRefsToDefs(this, oldTypes);
         foreach (object evnt in oldType.events)
             ((Event)evnt).ChangeRefsToDefs(this, oldTypes);
         foreach (object property in oldType.properties)
             ((Property)property).ChangeRefsToDefs(this, oldTypes);
         foreach (object interfc in oldType.interfaces)
             ((ClassDef)interfc).ChangeRefsToDefs(this, oldTypes);
         foreach (object methodImpl in oldType.methodImpls)
             ((MethodImpl)methodImpl).ChangeRefsToDefs(this, oldTypes);
         foreach (object nestedClass in oldType.nestedClasses)
             ((ClassDef)nestedClass).ChangeRefsToDefs(this, oldTypes);
     }
 }
Esempio n. 24
0
 /*-------------------- Constructors ---------------------------------*/
 internal ClassLayout(int pack, int cSize, ClassDef par)
     : this((ushort) pack, (uint) cSize, par)
 {
 }
Esempio n. 25
0
 /*-------------------- Constructors ---------------------------------*/
 internal NestedClassDef(ClassDef parent, TypeAttr attrSet, string name)
     : base(parent.GetScope(), attrSet, "", name)
 {
     this.parent = parent;
 }
Esempio n. 26
0
 internal static ClassLayout FindLayout(PEReader buff, ClassDef paren, uint classIx)
 {
     Contract.Requires(buff != null);
     Contract.Requires(paren != null);
     buff.SetElementPosition(MDTable.ClassLayout, 0);
     for (int i = 0; i < buff.GetTableSize(MDTable.ClassLayout); i++)
     {
         ushort packSize = buff.ReadUInt16();
         uint classSize = buff.ReadUInt32();
         if (buff.GetIndex(MDTable.TypeDef) == classIx)
             return new ClassLayout(packSize, classSize, paren);
     }
     return null;
 }
Esempio n. 27
0
 public void MergeClasses(ClassDef[] classes)
 {
     // FIXME Contract.Requires(methods != null);
     Contract.Requires(classes != null);
     ChangeRefsToDefs(this, classes);
     foreach (ClassDef cls in classes)
     {
         fields.AddRange(cls.fields);
         methods.AddRange(cls.methods);
         events.AddRange(cls.events);
         properties.AddRange(cls.properties);
         interfaces.AddRange(cls.interfaces);
         methodImpls.AddRange(cls.methodImpls);
         nestedClasses.AddRange(cls.nestedClasses);
     }
 }
Esempio n. 28
0
 internal void ReadMethodImpls(ClassDef theClass, uint classIx)
 {
     Contract.Requires(theClass != null);
     SetElementPosition(MDTable.InterfaceImpl, 0);
     for (int i = 0; (i < tableLengths[(int)MDTable.MethodImpl]); i++)
     {
         uint clIx = GetIndex(MDTable.TypeDef);
         uint bodIx = GetCodedIndex(CIx.MethodDefOrRef);
         uint declIx = GetCodedIndex(CIx.MethodDefOrRef);
         if (clIx == classIx)
         {
             MethodImpl mImpl = new MethodImpl(this, theClass, bodIx, declIx);
             theClass.AddMethodImpl(mImpl);
             tables[(int)MDTable.MethodImpl][i] = mImpl;
         }
     }
 }
Esempio n. 29
0
 internal void ChangeParTypes(ClassDef newType, ClassDef[] oldTypes)
 {
     Contract.Requires(newType != null);
     Contract.Requires(oldTypes != null);
     foreach (ClassDef oldType in oldTypes)
     {
         if (retType == oldType) retType = newType;
         for (int j = 0; j < numPars; j++)
         {
             if (parTypes[j] == oldType)
                 parTypes[j] = newType;
         }
         for (int j = 0; j < numOptPars; j++)
         {
             if (optParTypes[j] == oldType)
                 optParTypes[j] = newType;
         }
     }
 }
Esempio n. 30
0
 internal virtual void ResolveParent(PEReader buff, bool isExtern)
 {
     CIx cIx = CIx.ResolutionScope;
     if (isExtern) cIx = CIx.Implementation;
     if (scope != null) return;
     MetaDataElement parentScope = buff.GetCodedElement(cIx, resScopeIx);
     if (parentScope is Module)
     {  // special code for glitch in Everett ilasm
         ClassDef newDef = new ClassDef((PEFile)parentScope, 0, NameSpace, Name);
         ((Module)parentScope).AddToClassList(newDef);
         buff.InsertInTable(MDTable.TypeRef, Row, newDef);
     }
     else
     {
         scope = (ReferenceScope)buff.GetCodedElement(cIx, resScopeIx);
         ClassRef existing = (ClassRef)scope.GetExistingClass(NameSpace, Name);
         if (existing == null)
         {
             scope.AddToClassList(this);
         }
         else
         {
             if (isExtern)
                 buff.InsertInTable(MDTable.ExportedType, Row, existing);
             else
                 buff.InsertInTable(MDTable.TypeRef, Row, existing);
         }
     }
 }