protected MiniModule(String peFileName)
        {
            System.Diagnostics.Contracts.Contract.Requires(peFileName != null);

            _peFile = new PEFileReader(peFileName);
            _moduleName = Path.GetFileNameWithoutExtension(peFileName);
        }
 protected virtual void Dispose(bool disposing)
 {
     if (_peFile != null)
     {
         if (disposing)
             _peFile.Dispose();
         _peFile = null;
     }
 }
示例#3
0
        private static AssemblyInfo ReadAssemblyRef(PEFileReader peFile, MetadataToken assemblyRef)
        {
            System.Diagnostics.Contracts.Contract.Requires(peFile != null);
            System.Diagnostics.Contracts.Contract.Requires(assemblyRef.Table == MDTables.Tables.AssemblyRef);
            MDTables metaData = peFile.MetaData;
            BinaryReader B = metaData.B;

            metaData.SeekToMDToken(assemblyRef);
            UInt16 major = B.ReadUInt16();
            UInt16 minor = B.ReadUInt16();
            UInt16 build = B.ReadUInt16();
            UInt16 revision = B.ReadUInt16();
            Version v = new Version(major, minor, build, revision);
            UInt32 assemblyFlags = B.ReadUInt32();
            byte[] publicKey = metaData.ReadBlob();
            String simpleName = metaData.ReadString();
            String culture = metaData.ReadString();
            if ((culture != null) && (culture.Length == 0)) culture = null;
            return new AssemblyInfo(v, assemblyFlags, publicKey, simpleName, culture);
        }
示例#4
0
        // See the comments in Equals - we're doing string comparisons here
        // to compare full type names.
        public static bool Equals(MiniAssembly assemblyA, PEFileReader peFileB, MetadataToken assemblyRefB)
        {
            System.Diagnostics.Contracts.Contract.Requires(assemblyA != null);
            System.Diagnostics.Contracts.Contract.Requires(peFileB != null);
            System.Diagnostics.Contracts.Contract.Requires(assemblyRefB.Table == MDTables.Tables.AssemblyRef);

            String nameA, nameRefB;
            if (assemblyA.IsReflectionAssembly)
                nameA = AppDomain.CurrentDomain.ApplyPolicy(assemblyA._reflectionAssembly.FullName);
            else
            {
                AssemblyInfo assemblyInfoA = new AssemblyInfo();
                assemblyA._peFile.GetAssemblyInfo(ref assemblyInfoA);
                nameA = AppDomain.CurrentDomain.ApplyPolicy(assemblyInfoA.ToString());
            }

            AssemblyInfo assemblyInfoB = ReadAssemblyRef(peFileB, assemblyRefB);
            nameRefB = AppDomain.CurrentDomain.ApplyPolicy(assemblyInfoB.ToString());

            return Utils.AssemblyRefEqualsDef(nameRefB, nameA);
        }
示例#5
0
        private static MetadataToken FindTypeDef(PEFileReader peFile, MDTables mdScope, String typeName, String nameSpace)
        {
            System.Diagnostics.Contracts.Contract.Requires(typeName != null);

            uint numTypeDefs = mdScope.RowsInTable(MDTables.Tables.TypeDef);
            for (uint i = 0; i < numTypeDefs; i++) {
                mdScope.SeekToRowOfTable(MDTables.Tables.TypeDef, i);
                peFile.B.ReadUInt32();  // TypeAttributes
                String rowTypeName = mdScope.ReadString();
                if (!String.Equals(typeName, rowTypeName))
                    continue;
                String rowNameSpace= mdScope.ReadString();
                if (!String.Equals(nameSpace, rowNameSpace))
                    continue;
                return new MetadataToken(MDTables.Tables.TypeDef, i + 1);
            }
            throw new TypeLoadException(String.Format(CultureInfo.CurrentCulture, Res.CantFindTypeName, nameSpace, typeName));
        }