示例#1
0
 internal FieldMarshal(PEReader buff)
 {
     Contract.Requires(buff != null);
     parentIx = buff.GetCodedIndex(CIx.HasFieldMarshal);
     ntIx = buff.GetBlobIx();
     tabIx = MDTable.FieldMarshal;
 }
示例#2
0
 internal static void Read(PEReader buff, TableRow[] fMarshal)
 {
     Contract.Requires(buff != null);
     Contract.Requires(fMarshal != null);
     for (int i = 0; i < fMarshal.Length; i++)
         fMarshal[i] = new FieldMarshal(buff);
 }
示例#3
0
 internal Event(PEReader buff)
 {
     flags = buff.ReadUInt16();
     name = buff.GetString();
     typeIx = buff.GetCodedIndex(CIx.TypeDefOrRef);
     tabIx = MDTable.Event;
 }
示例#4
0
 internal FileRef(PEReader buff)
 {
     flags = buff.ReadUInt32();
     name = buff.GetString();
     hashBytes = buff.GetBlob();
     tabIx = MDTable.File;
 }
示例#5
0
 internal static void Read(PEReader buff, TableRow[] fRVAs)
 {
     Contract.Requires(buff != null);
     Contract.Requires(fRVAs != null);
     for (int i = 0; i < fRVAs.Length; i++)
         fRVAs[i] = new FieldRVA(buff);
 }
示例#6
0
 internal FieldRVA(PEReader buff)
 {
     Contract.Requires(buff != null);
     rva = buff.ReadUInt32();
     fieldIx = buff.GetIndex(MDTable.Field);
     tabIx = MDTable.FieldRVA;
 }
示例#7
0
 internal ClassLayout(PEReader buff)
 {
     Contract.Requires(buff != null);
     packSize = buff.ReadUInt16();
     classSize = buff.ReadUInt32();
     parentIx = buff.GetIndex(MDTable.TypeDef);
     tabIx = MDTable.ClassLayout;
 }
示例#8
0
 internal DeclSecurity(PEReader buff)
 {
     Contract.Requires(buff != null);
     action = (SecurityAction)buff.ReadUInt16();
     parentIx = buff.GetCodedIndex(CIx.HasDeclSecurity);
     permissionSet = buff.GetBlob();
     tabIx = MDTable.DeclSecurity;
 }
示例#9
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;
 }
示例#10
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());
     }
 }
示例#11
0
 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;
 }
示例#12
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;
 }
示例#13
0
 internal static void Read(PEReader buff, TableRow[] specs)
 {
     for (int i = 0; i < specs.Length; i++)
         specs[i] = new MethodSpec(buff);
 }
示例#14
0
 internal override void Resolve(PEReader buff)
 {
     buff.currentClassScope = this;
     superType = (Class)buff.GetCodedElement(CIx.TypeDefOrRef, extendsIx);
     if ((superType != null) && superType.isValueType())
         typeIndex = (byte)ElementType.ValueType;
     for (int i = 0; fieldIx < fieldEndIx; i++, fieldIx++)
     {
         FieldDef field = (FieldDef)buff.GetElement(MDTable.Field, fieldIx);
         field.SetParent(this);
         fields.Add(field);
     }
     for (int i = 0; methodIx < methodEndIx; i++, methodIx++)
     {
         MethodDef meth = (MethodDef)buff.GetElement(MDTable.Method, methodIx);
         if (Diag.DiagOn) Console.WriteLine("Adding method " + meth.Name() + " to class " + Name);
         meth.SetParent(this);
         methods.Add(meth);
     }
     buff.currentClassScope = null;
 }
示例#15
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]);
         }
     }
 }
示例#16
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;
 }
示例#17
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";
 }
示例#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);
     }
 }
示例#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;
 }
示例#20
0
 internal static void Read(PEReader buff, TableRow[] methDefs)
 {
     MethodDef prevDef = new MethodDef(buff);
     methDefs[0] = prevDef;
     for (int i = 1; i < methDefs.Length; i++)
     {
         prevDef.Row = (uint)i;
         MethodDef methDef = new MethodDef(buff);
         prevDef.numPars = methDef.parIx - prevDef.parIx;
         prevDef = methDef;
         methDefs[i] = methDef;
     }
     prevDef.Row = (uint)methDefs.Length;
     prevDef.numPars = (buff.GetTableSize(MDTable.Param) + 1) - prevDef.parIx;
 }
示例#21
0
 internal override sealed void Resolve(PEReader buff)
 {
     buff.currentMethodScope = this;
     buff.currentClassScope = parent;
     DoPars(buff, true);
     if (!buff.skipBody)
     {
         DoCode(buff);
     }
     buff.currentMethodScope = null;
     buff.currentClassScope = null;
 }
示例#22
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;
 }
示例#23
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);
         }
     }
 }
示例#24
0
 internal MethSig GetSig(PEReader buff)
 {
     if (sig == null)
     sig = buff.ReadMethSig(this, this.sigIx);
       return sig;
 }
示例#25
0
 internal override void Resolve(PEReader buff)
 {
     if (sig == null)
     {
         buff.currentMethodScope = this;
         buff.currentClassScope = parent;
         sig = buff.ReadMethSig(this, name, sigIx);
         buff.currentMethodScope = null;
         buff.currentClassScope = null;
     }
 }
示例#26
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;
 }
示例#27
0
 internal MethodSpec(PEReader buff)
     : base(null)
 {
     parentIx = buff.GetCodedIndex(CIx.MethodDefOrRef);
     instIx = buff.GetBlobIx();
     tabIx = MDTable.MethodSpec;
     this.unresolved = true;
 }
示例#28
0
 internal override Member ResolveParent(PEReader buff)
 {
     if (parent != null) return this;
     buff.currentMethodScope = this;
     MetaDataElement paren = buff.GetCodedElement(CIx.MemberRefParent, parentIx);
     buff.currentMethodScope = null;
     if (paren is MethodDef)
     {
         parent = null;
         varArgParent = (MethodDef)paren;
         //this.sig = buff.ReadMethSig(this,name,sigIx);
         ((MethodDef)paren).AddVarArgSig(this);
         return this;
     }
     else if (paren is ClassSpec)
     {
         ((ClassSpec)paren).AddMethod(this);
         return this;
     }
     else if (paren is PrimitiveType)
     {
         paren = MSCorLib.mscorlib.GetDefaultClass();
     }
     else if (paren is ClassDef)
     {
         this.sig = buff.ReadMethSig(this, name, sigIx);
         return ((ClassDef)paren).GetMethod(this.sig);
     }
     else if (paren is TypeSpec)
     {
         paren = new ConstructedTypeSpec((TypeSpec)paren);
         //Console.WriteLine("Got TypeSpec as parent of Member");
         //return this;
         //throw new Exception("Got TypeSpec as parent of Member");
         //((TypeSpec)paren).AddMethod(buff,this);
     }
     if (paren is ReferenceScope)
         parent = ((ReferenceScope)paren).GetDefaultClass();
     parent = (Class)paren;
     //if ((MethodRef)parent.GetMethodDesc(name) != null) throw new PEFileException("Existing method!!");
     //sig = buff.ReadMethSig(this,name,sigIx);
     //MethodRef existing = (MethodRef)parent.GetMethod(sig);
     //if (existing != null)
     //  return existing;
     parent.AddToMethodList(this);
     return this;
 }
示例#29
0
 internal void SetBuffer(PEReader buff)
 {
     Contract.Requires(buff != null);
     buffer = buff;
 }
示例#30
0
 internal override void Resolve(PEReader buff)
 {
     methParent = (Method)buff.GetCodedElement(CIx.MethodDefOrRef, parentIx);
       buff.currentMethodScope = methParent;  // set scopes - Fix by CK
       buff.currentClassScope = (Class)methParent.GetParent();
       //
       // EXPERIMENTAL: The signature of the methParent must be
       // visible as the signature of this MethodSpec.  The type-actuals
       // are held in the instTypes array.
       this.sig = this.methParent.GetSig(buff);
       instTypes = buff.ReadMethSpecSig(instIx);
       this.unresolved = false;
       //
       buff.currentMethodScope = null;
       buff.currentClassScope = null;
 }