コード例 #1
0
ファイル: MDElements.cs プロジェクト: dbremner/perwapi
 internal static DeclSecurity FindSecurity(PEReader buff, MetaDataElement paren, uint codedParIx)
 {
     buff.SetElementPosition(MDTable.DeclSecurity, 0);
     for (int i = 0; i < buff.GetTableSize(MDTable.DeclSecurity); i++)
     {
         uint act = buff.ReadUInt16();
         if (buff.GetCodedIndex(CIx.HasDeclSecurity) == codedParIx)
             return new DeclSecurity(paren, (SecurityAction)act, buff.GetBlob());
         uint junk = buff.GetBlobIx();
     }
     return null;
 }
コード例 #2
0
ファイル: MDClassDefElems.cs プロジェクト: dbremner/perwapi
 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]);
         }
     }
 }
コード例 #3
0
ファイル: MDDefScopeElems.cs プロジェクト: dbremner/perwapi
 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;
 }
コード例 #4
0
ファイル: ClassLayout.cs プロジェクト: dbremner/perwapi
 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;
 }
コード例 #5
0
ファイル: MDFeatureElems.cs プロジェクト: dbremner/perwapi
 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;
 }