Exemplo n.º 1
0
        public PdbSymbolProvider()
        {
            try
            {
                // Create a COM Metadata dispenser
                Guid dispenserClassID = new Guid(0xe5cb7a31, 0x7512, 0x11d2, 0x89, 0xce, 0x00, 0x80, 0xc7, 0x92, 0xe5, 0xd8); // CLSID_CorMetaDataDispenser
                Guid dispenserIID = new Guid(0x809c652e, 0x7396, 0x11d2, 0x97, 0x71, 0x00, 0xa0, 0xc9, 0xb4, 0xd5, 0x0c); // IID_IMetaDataDispenser
                object objDispenser;
                if (MetaDataGetDispenser(ref dispenserClassID, ref dispenserIID, out objDispenser) < 0)
                    return;
                _metadataDispenser = (IMetaDataDispenser)objDispenser;

                Guid symBinderClassID = new Guid(0x0A29FF9E, 0x7F9C, 0x4437, 0x8B, 0x11, 0xF4, 0x24, 0x49, 0x1E, 0x39, 0x31); // CLSID_CorSymBinder
                Guid symBinderIID = new Guid(0xAA544d42, 0x28CB, 0x11d3, 0xbd, 0x22, 0x00, 0x00, 0xf8, 0x08, 0x49, 0xbd); // IID_ISymUnmanagedBinder
                object objBinder;
                if (CoCreateInstance(ref symBinderClassID,
                                 IntPtr.Zero, // pUnkOuter
                                 1, // CLSCTX_INPROC_SERVER
                                 ref symBinderIID,
                                 out objBinder) < 0)
                    return;
                _symBinder = (ISymUnmanagedBinder)objBinder;
            }
            catch
            {
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new symbol provider.
        /// Note that the symbol provider will cache the symbol readers it creates
        /// </summary>
        /// <param name="searchPath">A semicolon separated list of paths to search for a PDB file</param>
        /// <param name="searchPolicy">Flags which specify where else to search</param>
        public SymbolProvider(string searchPath, SymSearchPolicies searchPolicy)
        {
            m_searchPath = searchPath;
            m_searchPolicy = searchPolicy;

            // Create a metadata dispenser and symbol binder via COM interop to use for all modules
            m_metadataDispenser = new IMetaDataDispenser();
            m_symBinder = new ISymUnmanagedBinder2();
        }
Exemplo n.º 3
0
        private const int GENMAN_ENUM_TOKEN_BUF_SIZE = 16; // 128 from genman seems too big.

        /// <summary>
        /// Construct an instance for a source file.
        /// </summary>
        /// <param name="sourceFile">The assembly.</param>
        internal AssemblyInformation(string sourceFile)
        {
            // Extra checks for PInvoke-destined data.
            ErrorUtilities.VerifyThrowArgumentNull(sourceFile, "sourceFile");
            _sourceFile = sourceFile;

            // Create the metadata dispenser and open scope on the source file.
            _metadataDispenser = (IMetaDataDispenser)new CorMetaDataDispenser();
            _assemblyImport = (IMetaDataAssemblyImport)_metadataDispenser.OpenScope(sourceFile, 0, ref s_importerGuid);
        }
Exemplo n.º 4
0
 private MetadataReader(string path)
 {
     _path = path;
     // Create the metadata dispenser and open scope on the source file.
     _metaDispenser = (IMetaDataDispenser)new CorMetaDataDispenser();
     object obj;
     int hr = _metaDispenser.OpenScope(path, 0, ref s_importerGuid, out obj);
     if (hr == 0)
         _assemblyImport = (IMetaDataAssemblyImport)obj;
 }
 private MetadataReader(string path)
 {
     object obj2;
     this._path = path;
     this._metaDispenser = (IMetaDataDispenser) new CorMetaDataDispenser();
     if (this._metaDispenser.OpenScope(path, 0, ref _importerGuid, out obj2) == 0)
     {
         this._assemblyImport = (IMetaDataAssemblyImport) obj2;
     }
 }
Exemplo n.º 6
0
        static IMetaDataImport GetDataImport(string location)
        {
            var dispenser = new IMetaDataDispenser();

            var metaDataImportGuid = typeof(IMetaDataImport).GUID;

            object scope;

            var hr = dispenser.OpenScope(location, 0, ref metaDataImportGuid, out scope);
            AssertHresultIsZero(hr);

            return (IMetaDataImport)scope;
        }
 public void Close()
 {
     if (this._assemblyImport != null)
     {
         Marshal.ReleaseComObject(this._assemblyImport);
     }
     if (this._metaDispenser != null)
     {
         Marshal.ReleaseComObject(this._metaDispenser);
     }
     this._attributes = null;
     this._metaDispenser = null;
     this._assemblyImport = null;
 }
Exemplo n.º 8
0
        private static string[] PeVerify(byte[] peImage, int domainId, string assemblyPath)
        {
            if (MonoHelpers.IsRunningOnMono())
            {
                // PEverify is currently unsupported on Mono hence return an empty
                // set of messages
                return(new string[0]);
            }

            lock (s_guard)
            {
                GCHandle pinned = GCHandle.Alloc(peImage, GCHandleType.Pinned);
                try
                {
                    IntPtr buffer = pinned.AddrOfPinnedObject();

                    ICLRValidator          validator    = (ICLRValidator)GetRuntimeInterfaceAsObject(s_clsIdClrRuntimeHost, typeof(ICLRRuntimeHost).GUID);
                    ValidationErrorHandler errorHandler = new ValidationErrorHandler(validator);

                    IMetaDataDispenser dispenser = (IMetaDataDispenser)GetRuntimeInterfaceAsObject(s_clsIdCorMetaDataDispenser, typeof(IMetaDataDispenser).GUID);

                    // the buffer needs to be pinned during validation
                    Guid   riid           = typeof(IMetaDataImport).GUID;
                    object metaDataImport = null;
                    if (assemblyPath != null)
                    {
                        dispenser.OpenScope(assemblyPath, CorOpenFlags.ofRead, ref riid, out metaDataImport);
                    }
                    else
                    {
                        dispenser.OpenScopeOnMemory(buffer, (uint)peImage.Length, CorOpenFlags.ofRead, ref riid, out metaDataImport);
                    }

                    IMetaDataValidate metaDataValidate = (IMetaDataValidate)metaDataImport;
                    metaDataValidate.ValidatorInit(CorValidatorModuleType.ValidatorModuleTypePE, errorHandler);
                    metaDataValidate.ValidateMetaData();

                    validator.Validate(errorHandler, (uint)domainId, ValidatorFlags.VALIDATOR_EXTRA_VERBOSE,
                                       ulMaxError: 10, token: 0, fileName: assemblyPath, pe: buffer, ulSize: (uint)peImage.Length);

                    return(errorHandler.GetOutput());
                }
                finally
                {
                    pinned.Free();
                }
            }
        }
        private static ISymbolReader GetSymbolReaderForFile(
            System.Diagnostics.SymbolStore.SymBinder binder, string pathModule, string searchPath)
        {
            // Guids for imported metadata interfaces.
            Guid dispenserClassID = new Guid(0xe5cb7a31, 0x7512, 0x11d2, 0x89,
                                             0xce, 0x00, 0x80, 0xc7, 0x92, 0xe5, 0xd8); // CLSID_CorMetaDataDispenser
            Guid dispenserIID = new Guid(0x809c652e, 0x7396, 0x11d2, 0x97, 0x71,
                                         0x00, 0xa0, 0xc9, 0xb4, 0xd5, 0x0c);           // IID_IMetaDataDispenser
            Guid importerIID = new Guid(0x7dac8207, 0xd3ae, 0x4c75, 0x9b, 0x67,
                                        0x92, 0x80, 0x1a, 0x49, 0x7d, 0x44);            // IID_IMetaDataImport

            // First create the Metadata dispenser.
            object objDispenser;

            NativeMethods.CoCreateInstance(ref dispenserClassID, null, 1,
                                           ref dispenserIID, out objDispenser);

            // Now open an Importer on the given filename. We'll end up passing this importer
            // straight through to the Binder.
            object             objImporter;
            IMetaDataDispenser dispenser = (IMetaDataDispenser)objDispenser;

            dispenser.OpenScope(pathModule, 0, ref importerIID, out objImporter);

            IntPtr        importerPtr = IntPtr.Zero;
            ISymbolReader reader      = null;

            try
            {
                // This will manually AddRef the underlying object, so we need to
                // be very careful to Release it.
                importerPtr = Marshal.GetComInterfaceForObject(objImporter,
                                                               typeof(IMetadataImport));

                reader = binder.GetReader(importerPtr, pathModule, searchPath);
            }
            finally
            {
                if (importerPtr != IntPtr.Zero)
                {
                    Marshal.Release(importerPtr);
                }
            }
            return(reader);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Construct an instance for a source file.
        /// </summary>
        /// <param name="sourceFile">The assembly.</param>
        internal AssemblyInformation(string sourceFile)
        {
            // Extra checks for PInvoke-destined data.
            ErrorUtilities.VerifyThrowArgumentNull(sourceFile, "sourceFile");
            _sourceFile = sourceFile;

#if FEATURE_ASSEMBLY_LOADFROM
            if (NativeMethodsShared.IsWindows)
            {
                // Create the metadata dispenser and open scope on the source file.
                _metadataDispenser = (IMetaDataDispenser) new CorMetaDataDispenser();
                _assemblyImport    = (IMetaDataAssemblyImport)_metadataDispenser.OpenScope(sourceFile, 0, ref s_importerGuid);
            }
            else
            {
                _assembly = Assembly.ReflectionOnlyLoadFrom(sourceFile);
            }
#endif
        }
Exemplo n.º 11
0
        public void Dispose()
        {
            if (_symReader != null)
            {
                Marshal.ReleaseComObject(_symReader);
                _symReader = null;
            }

            if (_symBinder != null)
            {
                Marshal.ReleaseComObject(_symBinder);
                _symBinder = null;
            }

            if (_metadataDispenser != null)
            {
                Marshal.ReleaseComObject(_metadataDispenser);
                _metadataDispenser = null;
            }
        }
        public static ISymbolReader GetSymbolReader(SymBinder binder, string pathModule)
        {
            try
            {
                object objDispenser;
                CoCreateInstance(ref CLSID_CorMetaDataDispenser,
                                 null,
                                 1,
                                 ref IID_IMetaDataDispenser,
                                 out objDispenser);

                object             objImporter;
                IMetaDataDispenser dispenser = (IMetaDataDispenser)objDispenser;
                dispenser.OpenScope(pathModule, 0, ref IID_IMetaDataImport, out objImporter);

                IntPtr        importerPtr = IntPtr.Zero;
                ISymbolReader reader;
                try
                {
                    importerPtr = Marshal.GetComInterfaceForObject(objImporter, typeof(IMetadataImport));

                    reader = binder.GetReader(importerPtr, pathModule, null);
                }
                finally
                {
                    if (importerPtr != IntPtr.Zero)
                    {
                        Marshal.Release(importerPtr);
                    }
                }
                return(reader);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 13
0
 public void Close()
 {
     if (_assemblyImport != null)
         Marshal.ReleaseComObject(_assemblyImport);
     if (_metaDispenser != null)
         Marshal.ReleaseComObject(_metaDispenser);
     _attributes = null;
     _metaDispenser = null;
     _assemblyImport = null;
 }
 internal AssemblyInformation(string sourceFile)
 {
     Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgumentNull(sourceFile, "sourceFile");
     this.metadataDispenser = (IMetaDataDispenser) new CorMetaDataDispenser();
     this.assemblyImport    = (IMetaDataAssemblyImport)this.metadataDispenser.OpenScope(sourceFile, 0, ref importerGuid);
 }
Exemplo n.º 15
0
 internal PdbSymbolsResolver(ComInstanceCollector instanceCollector)
 {
     _instanceCollector = instanceCollector;
     _instanceCollector.AddComObject(_dispenser    = new IMetaDataDispenser());
     _instanceCollector.AddComObject(_symbolBinder = new ISymUnmanagedBinder2());
 }
 internal PdbSymbolsResolver(ComInstanceCollector instanceCollector)
 {
     _instanceCollector = instanceCollector;
     _instanceCollector.AddComObject(_dispenser = new IMetaDataDispenser());
     _instanceCollector.AddComObject(_symbolBinder = new ISymUnmanagedBinder2());
 }
Exemplo n.º 17
0
        /// <summary>
        /// Creates copy of read-only metadata of runnig assembly to enable changes.
        /// </summary>
        /// <param name="roEmitter">Read-only version of metadata.</param>
        /// <returns>Editable copy of metadata.</returns>
        private unsafe IMetaDataEmit createEmitterCopy(IMetaDataEmit roEmitter)
        {
            Object objDispenser, objEmitter = null;
            ulong saveSize;
            byte[] metadataBuffer;

            roEmitter.GetSaveSize((uint)CorSaveSize.cssAccurate,out saveSize);
            metadataBuffer = new byte[saveSize];
            roEmitter.SaveToMemory(metadataBuffer, saveSize);

            int hResult = NativeMethods.CoCreateInstance(ref dispenserClassID, null, 1, ref dispenserIID, out objDispenser);
            if (hResult == 0)
            {
                IMetaDataDispenser dispenser = (IMetaDataDispenser)objDispenser;

                UInt32 fVal = 0x01;
                object val = (object)fVal;
                dispenser.SetOption(ref metaDataSetENC, ref val);
                fixed(byte* buff = metadataBuffer){
                    dispenser.OpenScopeOnMemory(new IntPtr(buff), (uint)metadataBuffer.Length,CorOpenFlags.ofRead, ref emitterIID, out objEmitter);
                }
                oldDispenser = dispenser;
            }
            return (IMetaDataEmit)objEmitter;
        }
Exemplo n.º 18
0
 /// <summary>
 /// Creaters importer acccess to metadata for new version of assembly.
 /// </summary>
 /// <param name="fileName">URL to the new assembly.</param>
 /// <returns>Importer access to metadata of the new assembly.</returns>
 private IMetaDataImport createImporter(string fileName)
 {
     Object objDispenser, objImporter = null;
     int hResult = NativeMethods.CoCreateInstance(ref dispenserClassID, null, 1, ref dispenserIID, out objDispenser);
     if (hResult == 0)
     {
         IMetaDataDispenser dispenser = (IMetaDataDispenser)objDispenser;
         dispenser.OpenScope(fileName, 0, ref importerIID, out objImporter);
         newDispenser = dispenser;
     }
     return (IMetaDataImport)objImporter;
 }
Exemplo n.º 19
0
 public AssemblyMetaDataImport(string sourceFile)
 {
     this._metaDispenser  = (IMetaDataDispenser) new CorMetaDataDispenser();
     this._assemblyImport = (IMetaDataAssemblyImport)this._metaDispenser.OpenScope(sourceFile, 0U, ref AssemblyMetaDataImport._importerGuid);
 }