예제 #1
0
 static UTF8String GetDllImportMethodName(MethodDef method, ImplMap implMap)
 {
     if (!UTF8String.IsNullOrEmpty(implMap.Name))
     {
         return(implMap.Name);
     }
     return(method.Name);
 }
예제 #2
0
 public FieldDefOptions(FieldDef field)
 {
     this.Attributes   = field.Attributes;
     this.Name         = field.Name;
     this.FieldSig     = field.FieldSig;
     this.FieldOffset  = field.FieldOffset;
     this.MarshalType  = field.MarshalType;
     this.RVA          = field.RVA;
     this.InitialValue = field.InitialValue;
     this.ImplMap      = field.ImplMap;
     this.Constant     = field.Constant;
     this.CustomAttributes.AddRange(field.CustomAttributes);
 }
예제 #3
0
 public FieldDefOptions(FieldDef field)
 {
     Attributes   = field.Attributes;
     Name         = field.Name;
     FieldSig     = field.FieldSig;
     FieldOffset  = field.FieldOffset;
     MarshalType  = field.MarshalType;
     RVA          = field.RVA;
     InitialValue = field.InitialValue;
     ImplMap      = field.ImplMap;
     Constant     = field.Constant;
     CustomAttributes.AddRange(field.CustomAttributes);
 }
예제 #4
0
 public MethodDefOptions(MethodDef method)
 {
     this.ImplAttributes = method.ImplAttributes;
     this.Attributes     = method.Attributes;
     this.Name           = method.Name;
     this.MethodSig      = method.MethodSig;
     this.ImplMap        = method.ImplMap;
     this.CustomAttributes.AddRange(method.CustomAttributes);
     this.DeclSecurities.AddRange(method.DeclSecurities);
     this.ParamDefs.AddRange(method.ParamDefs);
     this.GenericParameters.AddRange(method.GenericParameters);
     this.Overrides.AddRange(method.Overrides);
 }
예제 #5
0
            public unsafe ImplMapEntry(PEFile module, byte *ptr, int metadataOffset, int row)
            {
                this.module   = module;
                this.metadata = module.Metadata;
                this.RID      = row;
                var rowOffset = metadata.GetTableMetadataOffset(TableIndex.ImplMap)
                                + metadata.GetTableRowSize(TableIndex.ImplMap) * (row - 1);

                this.Offset = metadataOffset + rowOffset;
                int moduleRefSize             = metadata.GetTableRowCount(TableIndex.ModuleRef) < ushort.MaxValue ? 2 : 4;
                int memberForwardedTagRefSize = metadata.ComputeCodedTokenSize(32768, TableMask.MethodDef | TableMask.Field);
                int stringHandleSize          = metadata.GetHeapSize(HeapIndex.String) < ushort.MaxValue ? 2 : 4;

                this.implMap = new ImplMap(ptr + rowOffset, moduleRefSize, memberForwardedTagRefSize, stringHandleSize);
            }
예제 #6
0
 public MethodDefOptions(MethodDef method)
 {
     ImplAttributes      = method.ImplAttributes;
     Attributes          = method.Attributes;
     SemanticsAttributes = method.SemanticsAttributes;
     RVA       = method.RVA;
     Name      = method.Name;
     MethodSig = method.MethodSig;
     ImplMap   = method.ImplMap;
     CustomAttributes.AddRange(method.CustomAttributes);
     DeclSecurities.AddRange(method.DeclSecurities);
     ParamDefs.AddRange(method.ParamDefs);
     GenericParameters.AddRange(method.GenericParameters);
     Overrides.AddRange(method.Overrides);
 }
예제 #7
0
 internal void CalcElemSize()
 {
     elemSize[(int)MDTable.Assembly]             = Assembly.Size(this);
     elemSize[(int)MDTable.AssemblyOS]           = 12;
     elemSize[(int)MDTable.AssemblyProcessor]    = 4;
     elemSize[(int)MDTable.AssemblyRefOS]        = 12 + TableIndexSize(MDTable.AssemblyRef);
     elemSize[(int)MDTable.AssemblyRefProcessor] = 4 + TableIndexSize(MDTable.AssemblyRef);
     elemSize[(int)MDTable.Module]                 = Module.Size(this);
     elemSize[(int)MDTable.TypeRef]                = ClassRef.Size(this);
     elemSize[(int)MDTable.TypeDef]                = ClassDef.Size(this);
     elemSize[(int)MDTable.Field]                  = FieldDef.Size(this);
     elemSize[(int)MDTable.Method]                 = MethodDef.Size(this);
     elemSize[(int)MDTable.Param]                  = Param.Size(this);
     elemSize[(int)MDTable.InterfaceImpl]          = InterfaceImpl.Size(this);
     elemSize[(int)MDTable.MemberRef]              = FieldRef.Size(this);
     elemSize[(int)MDTable.Constant]               = ConstantElem.Size(this);
     elemSize[(int)MDTable.CustomAttribute]        = CustomAttribute.Size(this);
     elemSize[(int)MDTable.FieldMarshal]           = FieldMarshal.Size(this);
     elemSize[(int)MDTable.DeclSecurity]           = DeclSecurity.Size(this);
     elemSize[(int)MDTable.ClassLayout]            = ClassLayout.Size(this);
     elemSize[(int)MDTable.FieldLayout]            = FieldLayout.Size(this);
     elemSize[(int)MDTable.StandAloneSig]          = Signature.Size(this);
     elemSize[(int)MDTable.EventMap]               = MapElem.Size(this, MDTable.EventMap);
     elemSize[(int)MDTable.Event]                  = Event.Size(this);
     elemSize[(int)MDTable.PropertyMap]            = MapElem.Size(this, MDTable.PropertyMap);
     elemSize[(int)MDTable.Property]               = Property.Size(this);
     elemSize[(int)MDTable.MethodSemantics]        = MethodSemantics.Size(this);
     elemSize[(int)MDTable.MethodImpl]             = MethodImpl.Size(this);
     elemSize[(int)MDTable.ModuleRef]              = ModuleRef.Size(this);
     elemSize[(int)MDTable.TypeSpec]               = TypeSpec.Size(this);
     elemSize[(int)MDTable.ImplMap]                = ImplMap.Size(this);
     elemSize[(int)MDTable.FieldRVA]               = FieldRVA.Size(this);
     elemSize[(int)MDTable.Assembly]               = Assembly.Size(this);
     elemSize[(int)MDTable.AssemblyRef]            = AssemblyRef.Size(this);
     elemSize[(int)MDTable.File]                   = FileRef.Size(this);
     elemSize[(int)MDTable.ExportedType]           = ExternClass.Size(this);
     elemSize[(int)MDTable.ManifestResource]       = ManifestResource.Size(this);
     elemSize[(int)MDTable.NestedClass]            = MapElem.Size(this, MDTable.NestedClass);
     elemSize[(int)MDTable.GenericParam]           = GenericParam.Size(this);
     elemSize[(int)MDTable.GenericParamConstraint] = GenericParamConstraint.Size(this);
     elemSize[(int)MDTable.MethodSpec]             = MethodSpec.Size(this);
 }
예제 #8
0
        public Tabels(PEFile p)
        {
            //Init
            this.r = p.MetadataReader;

            //Read all of the tabels
            ModuleTabel           = new List <Module>();
            TypeRefTabel          = new List <TypeRef>();
            TypeDefTabel          = new List <TypeDef>();
            FieldTabel            = new List <Field>();
            MethodTabel           = new List <Method>();
            ParmTabel             = new List <Param>();
            InterfaceImplTable    = new List <InterfaceImpl>();
            MemberRefTabelRow     = new List <MemberRef>();
            ConstantTabel         = new List <Constant>();
            CustomAttributeTabel  = new List <CustomAttribute>();
            FieldMarshalTabel     = new List <FieldMarshal>();
            DeclSecurityTabel     = new List <DeclSecurity>();
            ClassLayoutTabel      = new List <ClassLayout>();
            FieldLayoutTabel      = new List <FieldLayout>();
            StandAloneSigTabel    = new List <StandAloneSig>();
            EventMapTabel         = new List <EventMap>();
            EventTabel            = new List <Event>();
            PropertyMapTabel      = new List <PropertyMap>();
            PropertyTabel         = new List <PropertyTabel>();
            MethodSemanticsTabel  = new List <MethodSemantics>();
            MethodImplTabel       = new List <MethodImpl>();
            ModuleRefTabel        = new List <ModuleRef>();
            TypeSpecTabel         = new List <TypeSpec>();
            ImplMapTabel          = new List <ImplMap>();
            FieldRVATabel         = new List <FieldRVA>();
            AssemblyTabel         = new List <Assembly>();
            AssemblyRefTabel      = new List <AssemblyRef>();
            FileTable             = new List <File>();
            ExportedTypeTable     = new List <ExportedType>();
            ManifestResourceTable = new List <ManifestResource>();
            NestedClassTable      = new List <NestedClass>();
            GenericParamTable     = new List <GenericParam>();
            MethodSpecTable       = new List <MethodSpec>();

            int a = 0;

            //Read module Tabel (if any)
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.Module) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new Module();
                    m.Read(r);
                    ModuleTabel.Add(m);
                }
                a++;
            }
            //Read TypeRef Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.TypeRef) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new TypeRef();
                    m.Read(r);
                    TypeRefTabel.Add(m);
                }
                a++;
            }
            //Read TypeDef Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.TypeDef) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new TypeDef();
                    m.Read(r);
                    TypeDefTabel.Add(m);
                }
                a++;
            }
            //Read Field Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.Field) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new Field();
                    m.Read(r);
                    FieldTabel.Add(m);
                }
                a++;
            }
            //Read Method tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.Method) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new Method();
                    m.Read(r);
                    MethodTabel.Add(m);
                }
                a++;
            }
            //Read Parm Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.Param) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new Param();
                    m.Read(r);
                    ParmTabel.Add(m);
                }
                a++;
            }
            //Read interfaceimpl Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.InterfaceImpl) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new InterfaceImpl();
                    m.Read(r);
                    InterfaceImplTable.Add(m);
                }
                a++;
            }
            //Read MemberRef tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.MemberRef) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new MemberRef();
                    m.Read(r);
                    MemberRefTabelRow.Add(m);
                }
                a++;
            }
            //Read Constant tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.Constant) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new Constant();
                    m.Read(r);
                    ConstantTabel.Add(m);
                }
                a++;
            }
            //Read CustomAttribute tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.CustomAttribute) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new CustomAttribute();
                    m.Read(r);
                    CustomAttributeTabel.Add(m);
                }
                a++;
            }
            //Read FieldMarshal tabel (Please test)
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.FieldMarshal) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new FieldMarshal();
                    m.Read(r);
                    FieldMarshalTabel.Add(m);
                }
                a++;
            }
            //Read DeclSecurity tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.DeclSecurity) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new DeclSecurity();
                    m.Read(r);
                    DeclSecurityTabel.Add(m);
                }
                a++;
            }
            //Read ClassLayout tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.ClassLayout) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new ClassLayout();
                    m.Read(r);
                    ClassLayoutTabel.Add(m);
                }
                a++;
            }
            //Read FieldLayout tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.FieldLayout) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new FieldLayout();
                    m.Read(r);
                    FieldLayoutTabel.Add(m);
                }
                a++;
            }
            //Read StandAloneSig tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.StandAloneSig) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new StandAloneSig();
                    m.Read(r);
                    StandAloneSigTabel.Add(m);
                }
                a++;
            }
            //Read EventMap tabel (please test)
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.EventMap) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new EventMap();
                    m.Read(r);
                    EventMapTabel.Add(m);
                }
                a++;
            }
            //Read event tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.Event) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new Event();
                    m.Read(r);
                    EventTabel.Add(m);
                }
                a++;
            }
            //Read Property Map tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.PropertyMap) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new PropertyMap();
                    m.Read(r);
                    PropertyMapTabel.Add(m);
                }
                a++;
            }
            //Read Property tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.Property) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new PropertyTabel();
                    m.Read(r);
                    PropertyTabel.Add(m);
                }
                a++;
            }
            //Read MethodSemantics  tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.MethodSemantics) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new MethodSemantics();
                    m.Read(r);
                    MethodSemanticsTabel.Add(m);
                }
                a++;
            }
            //Read MethodImpl tabel (Please test)
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.MethodImpl) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new MethodImpl();
                    m.Read(r);
                    MethodImplTabel.Add(m);
                }
                a++;
            }
            //Read ModuleRef tabel (pls test)
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.ModuleRef) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new ModuleRef();
                    m.Read(r);
                    ModuleRefTabel.Add(m);
                }
                a++;
            }
            //Read TypeSpec tabel (pls test)
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.TypeSpec) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new TypeSpec();
                    m.Read(r);
                    TypeSpecTabel.Add(m);
                }
                a++;
            }
            //Read ImplMap tabel (pls test)
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.ImplMap) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new ImplMap();
                    m.Read(r);
                    ImplMapTabel.Add(m);
                }
                a++;
            }
            //Read FieldRVA  tabel (pls test)
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.FieldRVA) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new FieldRVA();
                    m.Read(r);
                    FieldRVATabel.Add(m);
                }
                a++;
            }
            //Read Assembly tabel (pls test)
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.Assembly) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new Assembly();
                    m.Read(r);
                    AssemblyTabel.Add(m);
                }
                a++;
            }

            //Read ignored tabels (These never should be present!)
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.AssemblyProcessor) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var proc = r.ReadUInt32();
                }
                a++;
            }
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.AssemblyOS) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    r.BaseStream.Position += 11; //Test please
                }
                a++;
            }
            //Read AssemblyRef Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.AssemblyRef) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new AssemblyRef();
                    m.Read(r);
                    AssemblyRefTabel.Add(m);
                }
                a++;
            }
            //Read AssemblyRefProcessor Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.AssemblyRefProcessor) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    r.BaseStream.Position += 8; //Test please
                }
                a++;
            }
            //Read AssemblyRefOS Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.AssemblyRefOS) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    r.BaseStream.Position += 16; //Test please
                }
                a++;
            }
            //Read File Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.File) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new File();
                    m.Read(r);
                    FileTable.Add(m);
                }
                a++;
            }
            //Read ExportedType Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.ExportedType) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new ExportedType();
                    m.Read(r);
                    ExportedTypeTable.Add(m);
                }
                a++;
            }
            //Read ManifestResource Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.ManifestResource) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new ManifestResource();
                    m.Read(r);
                    ManifestResourceTable.Add(m);
                }
                a++;
            }
            //Read NestedClass Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.NestedClass) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new NestedClass();
                    m.Read(r);
                    NestedClassTable.Add(m);
                }
                a++;
            }
            //Read GenericParam Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.GenericParam) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new GenericParam();
                    m.Read(r);
                    GenericParamTable.Add(m);
                }
                a++;
            }
            //Read MethodSpec Tabel
            if ((p.ClrMetaDataStreamHeader.TablesFlags & MetadataTableFlags.MethodSpec) != 0)
            {
                for (int i = 0; i < p.ClrMetaDataStreamHeader.TableSizes[a]; i++)
                {
                    var m = new MethodSpec();
                    m.Read(r);
                    MethodSpecTable.Add(m);
                }
                a++;
            }
        }
예제 #9
0
 public void RemovePInvokeInfo()
 {
     pinvokeImpl = null;
     methFlags  &= NotPInvoke;
 }
예제 #10
0
 public void AddPInvokeInfo(ModuleRef scope, string methName,
                            PInvokeAttr callAttr)
 {
     pinvokeImpl = new ImplMap((ushort)callAttr, this, methName, scope);
     methFlags  |= PInvokeImpl;
 }
예제 #11
0
 internal void AddPInvokeInfo(ImplMap impl)
 {
     pinvokeImpl = impl;
     methFlags  |= PInvokeImpl;
 }