Example #1
0
 public ExternClass(PEReader buff)
 {
     flags = buff.ReadUInt32();
     typeDefId = buff.ReadUInt32();
     Name = buff.GetString();
     NameSpace = buff.GetString();
     implIx = buff.GetCodedIndex(CIx.Implementation);
     tabIx = MDTable.ExportedType;
 }
Example #2
0
 internal ClassDef(PEReader buff, uint row, bool isMSCorLib)
 {
     flags = buff.ReadUInt32();
     Name = buff.GetString();
     NameSpace = buff.GetString();
     extendsIx = buff.GetCodedIndex(CIx.TypeDefOrRef);
     fieldIx = buff.GetIndex(MDTable.Field);
     methodIx = buff.GetIndex(MDTable.Method);
     this.Row = row;
     tabIx = MDTable.TypeDef;
     if (isMSCorLib && (Name == "ValueType"))
         typeIndex = (byte)ElementType.ValueType;
 }
Example #3
0
 internal Event(PEReader buff)
 {
     flags = buff.ReadUInt16();
     name = buff.GetString();
     typeIx = buff.GetCodedIndex(CIx.TypeDefOrRef);
     tabIx = MDTable.Event;
 }
Example #4
0
 internal FileRef(PEReader buff)
 {
     flags = buff.ReadUInt32();
     name = buff.GetString();
     hashBytes = buff.GetBlob();
     tabIx = MDTable.File;
 }
Example #5
0
 internal static void Read(PEReader buff, TableRow[] files)
 {
     for (int i = 0; i < files.Length; i++)
     {
         uint flags = buff.ReadUInt32();
         if (flags == HasMetaData)
             files[i] = new ModuleFile(buff.GetString(), buff.GetBlob());
         else
             files[i] = new ResourceFile(buff.GetString(), buff.GetBlob());
     }
 }
Example #6
0
 internal static void GetMethodRefs(PEReader buff, uint num, ClassRef parent)
 {
     for (int i = 0; i < num; i++)
     {
         uint rva = buff.ReadUInt32();
         ushort implFlags = buff.ReadUInt16();
         ushort methFlags = buff.ReadUInt16();
         string name = buff.GetString();
         uint sigIx = buff.GetBlobIx();
         uint parIx = buff.GetIndex(MDTable.Param);
         if (IsPublicOrProtected(methFlags))
         {
             MethodRef mRef = new MethodRef(parIx, name, sigIx);  // changed
             mRef.SetParent(parent);
             //Console.WriteLine(parent.NameString());
             MethSig mSig = buff.ReadMethSig(mRef, name, sigIx);
             //mSig.name = name;
             mRef.SetSig(mSig); // changed
             parent.AddToMethodList(mRef);
         }
     }
 }
Example #7
0
 internal MethodDef(PEReader buff)
     : base(null)
 {
     rva = buff.ReadUInt32();
     implFlags = buff.ReadUInt16();
     methFlags = buff.ReadUInt16();
     name = buff.GetString();
     sigIx = buff.GetBlobIx();
     parIx = buff.GetIndex(MDTable.Param);
     tabIx = MDTable.Method;
 }
Example #8
0
 internal static void GetFieldRefs(PEReader buff, uint num, ClassRef parent)
 {
     for (int i = 0; i < num; i++)
     {
         uint flags = buff.ReadUInt16();
         string name = buff.GetString();
         uint sigIx = buff.GetBlobIx();
         if ((flags & (uint)FieldAttr.Public) == (uint)FieldAttr.Public)
         {
             if (parent.GetField(name) == null)
             {
                 //Console.WriteLine(parent.NameString());
                 buff.currentClassScope = parent;
                 FieldRef fRef = new FieldRef(parent, name, buff.GetFieldType(sigIx));
                 buff.currentClassScope = null;
                 parent.AddToFieldList(fRef);
             }
         }
     }
 }
Example #9
0
 internal FieldDef(PEReader buff)
     : base(null, null, null)
 {
     flags = buff.ReadUInt16();
     name = buff.GetString();
     sigIx = buff.GetBlobIx();
     tabIx = MDTable.Field;
 }
Example #10
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]);
         }
     }
 }
Example #11
0
 internal static ModuleRef ReadModuleRef(PEReader buff)
 {
     buff.ReadZeros(2);
     string name = buff.GetString();
     uint junk = buff.GetGUIDIx();
     junk = buff.GetGUIDIx();
     junk = buff.GetGUIDIx();
     ModuleRef mRef = new ModuleRef(new ModuleFile(name, null));
     mRef.ReadAsDef();
     return mRef;
 }
Example #12
0
 internal ImplMap(PEReader buff)
 {
     Contract.Requires(buff != null);
     flags = buff.ReadUInt16();
     memForIndex = buff.GetCodedIndex(CIx.MemberForwarded);
     importName = buff.GetString();
     scopeIx = buff.GetIndex(MDTable.ModuleRef);
     tabIx = MDTable.ImplMap;
 }
Example #13
0
 internal Property(PEReader buff)
 {
     flags = buff.ReadUInt16();
     name = buff.GetString();
     typeBlobIx = buff.GetBlobIx();
     tabIx = MDTable.Property;
 }
Example #14
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;
 }
Example #15
0
 internal static ClassRef ReadDef(PEReader buff, ReferenceScope resScope, uint index)
 {
     uint junk = buff.ReadUInt32();
     string cName = buff.GetString();
     string nsName = buff.GetString();
     ClassRef newClass = (ClassRef)resScope.GetExistingClass(nsName, cName);
     if (newClass == null)
     {
         newClass = new ClassRef(resScope, nsName, cName);
         resScope.AddToClassList(newClass);
     }
     newClass.readAsDef = true;
     newClass.Row = index;
     junk = buff.GetCodedIndex(CIx.TypeDefOrRef);
     newClass.fieldIx = buff.GetIndex(MDTable.Field);
     newClass.methodIx = buff.GetIndex(MDTable.Method);
     return newClass;
 }
Example #16
0
 internal static ClassRef ReadClass(PEReader buff, ReferenceScope resScope)
 {
     uint resScopeIx = buff.GetCodedIndex(CIx.ResolutionScope);
     string name = buff.GetString();
     string nameSpace = buff.GetString();
     ClassRef newClass = (ClassRef)resScope.GetExistingClass(nameSpace, name);
     if (newClass == null)
         newClass = new ClassRef(resScope, nameSpace, name);
     return newClass;
 }
Example #17
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);
         }
     }
 }
Example #18
0
 internal static void Read(PEReader buff, TableRow[] table, PEFile pefile)
 {
     for (int i = 0; i < table.Length; i++)
     {
         HashAlgorithmType hAlg = (HashAlgorithmType)buff.ReadUInt32();
         ushort majVer = buff.ReadUInt16();
         ushort minVer = buff.ReadUInt16();
         ushort bldNo = buff.ReadUInt16();
         ushort revNo = buff.ReadUInt16();
         uint flags = buff.ReadUInt32();
         byte[] pKey = buff.GetBlob();
         string name = buff.GetString();
         string cult = buff.GetString();
         table[i] = new Assembly(name, hAlg, majVer, minVer, bldNo, revNo, flags, pKey, cult, pefile);
     }
 }
Example #19
0
 internal static AssemblyRef ReadAssemblyRef(PEReader buff)
 {
     buff.SetElementPosition(MDTable.Assembly, 1);
     HashAlgorithmType hAlg = (HashAlgorithmType)buff.ReadUInt32();
     ushort majVer = buff.ReadUInt16();
     ushort minVer = buff.ReadUInt16();
     ushort bldNo = buff.ReadUInt16();
     ushort revNo = buff.ReadUInt16();
     uint flags = buff.ReadUInt32();
     byte[] pKey = buff.GetBlob();
     string name = buff.GetString();
     string cult = buff.GetString();
     AssemblyRef assemRef;
     if (name.ToLower() == "mscorlib")
     {
         assemRef = MSCorLib.mscorlib;
         assemRef.AddVersionInfo(majVer, minVer, bldNo, revNo);
         if (pKey.Length > 8) assemRef.AddKey(pKey);
         else assemRef.AddKeyToken(pKey);
         assemRef.AddCulture(cult);
         assemRef.SetFlags(flags);
     }
     else
     {
         assemRef = new AssemblyRef(name, majVer, minVer, bldNo, revNo, flags, pKey, cult, null);
     }
     //AssemblyRef assemRef = new AssemblyRef(name,majVer,minVer,bldNo,revNo,flags,pKey,cult,null);
     assemRef.ReadAsDef();
     return assemRef;
 }
Example #20
0
 internal static AssemblyRef Read(PEReader buff)
 {
     ushort majVer = buff.ReadUInt16();
     ushort minVer = buff.ReadUInt16();
     ushort bldNo = buff.ReadUInt16();
     ushort revNo = buff.ReadUInt16();
     uint flags = buff.ReadUInt32();
     byte[] pKey = buff.GetBlob();
     string name = buff.GetString();
     string cult = buff.GetString();
     byte[] hBytes = buff.GetBlob();
     AssemblyRef assemRef;
     if (name.ToLower() == "mscorlib")
     {
         assemRef = MSCorLib.mscorlib;
         assemRef.AddVersionInfo(majVer, minVer, bldNo, revNo);
         assemRef.AddHash(hBytes);
         if (pKey.Length > 8) assemRef.AddKey(pKey);
         else assemRef.AddKeyToken(pKey);
         assemRef.AddCulture(cult);
         assemRef.SetFlags(flags);
     }
     else
     {
         assemRef = new AssemblyRef(name, majVer, minVer, bldNo, revNo, flags, pKey, cult, hBytes);
     }
     return assemRef;
 }
Example #21
0
 internal void Read(PEReader buff)
 {
     buff.ReadZeros(2);
     name = buff.GetString();
     mvid = buff.GetGUID();
     uint junk = buff.GetGUIDIx();
     junk = buff.GetGUIDIx();
     if (Diag.DiagOn) Console.WriteLine("Reading module with name " + name + " and Mvid = " + mvid);
     ismscorlib = name.ToLower() == "mscorlib.dll";
 }
Example #22
0
 internal static void GetClassRefs(PEReader buff, TableRow[] eClasses)
 {
     for (uint i = 0; i < eClasses.Length; i++)
     {
         uint junk = buff.ReadUInt32();
         junk = buff.ReadUInt32();
         string name = buff.GetString();
         string nameSpace = buff.GetString();
         uint implIx = buff.GetCodedIndex(CIx.Implementation);
         eClasses[i] = new ClassRef(implIx, nameSpace, name);
         eClasses[i].Row = i + 1;
     }
 }
Example #23
0
 internal static void Read(PEReader buff, TableRow[] mods, bool resolve)
 {
     Contract.Requires(buff != null);
     Contract.Requires(mods != null);
     for (int i = 0; i < mods.Length; i++)
     {
         string name = buff.GetString();
         ModuleRef mRef = new ModuleRef(name);
         if (resolve) mRef.modFile = buff.GetFileDesc(name);
         mods[i] = mRef;
     }
 }
Example #24
0
 internal GenericParam(PEReader buff)
     : base(VAR)
 {
     Contract.Requires(buff != null);
     index = buff.ReadUInt16();
     flags = buff.ReadUInt16();
     parentIx = buff.GetCodedIndex(CIx.TypeOrMethodDef);
     name = buff.GetString();
     if (extraField) kind = buff.ReadUInt16();
     tabIx = MDTable.GenericParam;
     // resolve generic param immediately for signature resolution
     parent = buff.GetCodedElement(CIx.TypeOrMethodDef, parentIx);
     if (parent != null)
     {
         if (parent is MethodDef)
         {
             typeIndex = MVAR;
             ((MethodDef)parent).AddGenericParam(this);
         }
         else
         {
             ((ClassDef)parent).AddGenericParam(this);
         }
     }
 }