Exemplo n.º 1
0
        public static PdbSymbolReader TryOpenSymbolReaderForMetadataFile(string metadataFileName, string searchPath)
        {
            try
            {
                if (s_metadataDispenser == null || s_symBinder == null)
                {
                    return(null);
                }

                Guid IID_IMetaDataImport = new Guid(0x7dac8207, 0xd3ae, 0x4c75, 0x9b, 0x67, 0x92, 0x80, 0x1a, 0x49, 0x7d, 0x44);

                // Open an metadata importer on the given filename. We'll end up passing this importer straight
                // through to the Binder.
                object objImporter;
                if (s_metadataDispenser.OpenScope(metadataFileName, 0x00000010 /* read only */, ref IID_IMetaDataImport, out objImporter) < 0)
                {
                    return(null);
                }

                ISymUnmanagedReader reader;
                if (s_symBinder.GetReaderForFile(objImporter, metadataFileName, searchPath, out reader) < 0)
                {
                    return(null);
                }

                return(new UnmanagedPdbSymbolReader(reader));
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public PdbSymbols GetSymbolsProviderForFile(string assemblyFile)
        {
            PdbSymbols reader;

            if (!_readers.TryGetValue(assemblyFile, out reader))
            {
                ISymUnmanagedReader rawReader;
                var importerIID = typeof(IMetaDataImport).GUID;
                var importer    = _dispenser.OpenScope(assemblyFile, 0, ref importerIID);

                int result = _symbolBinder.GetReaderForFile2(importer,
                                                             assemblyFile,
                                                             Path.GetDirectoryName(assemblyFile),
                                                             SymSearchPolicies.AllowOriginalPathAccess,
                                                             out rawReader);

                if (result == (int)DiaErrors.E_PDB_NOT_FOUND ||
                    result < 0)
                {
                    return(null);
                }

                _readers.Add(assemblyFile, reader = new PdbSymbols(rawReader));
                _instanceCollector.AddComObject(rawReader);
                _instanceCollector.AddComObject(importer);
            }
            return(reader);
        }
Exemplo n.º 3
0
        public static ISymbolWriter CreateWriter(string assembly, string pdb)
        {
            SymWriter writer = new SymWriter(false);

            object objDispenser, objImporter;

            CoCreateInstance(ref s_dispenserClassID, null, 1, ref s_dispenserIID, out objDispenser);

            IMetaDataDispenser dispenser = (IMetaDataDispenser)objDispenser;

            dispenser.OpenScope(assembly, 1, ref s_importerIID, out objImporter);

            IntPtr importerPtr = Marshal.GetComInterfaceForObject(objImporter, typeof(IMetadataImport));

            try {
                if (File.Exists(pdb))
                {
                    File.Delete(pdb);
                }

                writer.Initialize(importerPtr, pdb, false);
            } finally {
                if (importerPtr != IntPtr.Zero)
                {
                    Marshal.Release(importerPtr);
                    Marshal.ReleaseComObject(objDispenser);
                    Marshal.ReleaseComObject(objImporter);
                    Marshal.ReleaseComObject(dispenser);
                }
            }

            return(writer);
        }
Exemplo n.º 4
0
    MetaDataReader(string moduleName)
    {
        CLRMetaHost    mh = new CLRMetaHost();
        CLRRuntimeInfo highestInstalledRuntime = null;

        foreach (CLRRuntimeInfo runtime in mh.EnumerateInstalledRuntimes())
        {
            if (highestInstalledRuntime == null ||
                string.Compare(highestInstalledRuntime.GetVersionString(), runtime.GetVersionString(), StringComparison.OrdinalIgnoreCase) < 0)
            {
                highestInstalledRuntime = runtime;
            }
        }
        if (highestInstalledRuntime == null)
        {
            throw new ApplicationException("Could not enumerate .NET runtimes on the system.");
        }

        IMetaDataDispenser metaDataDispenser = highestInstalledRuntime.GetIMetaDataDispenser();

        Guid   IMetaDataImport2_Guid = Guid("7DAC8207-D3AE-4c75-9B67-92801A497D44");
        object metaDataImportObj;

        metaDataDispenser.OpenScope(moduleName, 0, ref IMetaDataImport2_Guid, out metaDataImportObj);
        m_metaDataImport = metaDataImportObj as IMetadataImport2;
    }
Exemplo n.º 5
0
        public PDBReader(string assemblyPath)
        {
            object             metaDataImport = null;
            IMetaDataDispenser dispenser      = null;

            try
            {
                Guid metaDataImportIID = new Guid(IMetaDataImportGuid);

                dispenser = (IMetaDataDispenser)(new MetaDataDispenser());
                dispenser.OpenScope(assemblyPath, 0, ref metaDataImportIID, out metaDataImport);

                this.symReader = (ISymUnmanagedReader)(new CorSymReader_SxS());
                this.symReader.Initialize(metaDataImport, assemblyPath, null, null);
            }
            finally
            {
                // Release COM objects so that files don't remain locked.
                if (metaDataImport != null)
                {
                    Marshal.ReleaseComObject(metaDataImport);
                }

                if (dispenser != null)
                {
                    Marshal.ReleaseComObject(dispenser);
                }
            }
        }
Exemplo n.º 6
0
        public static ISymbolReader CreateReader(string filename)
        {
            SymBinder binder = new SymBinder();
            object    objDispenser, objImporter;

            CoCreateInstance(ref s_dispenserClassID, null, 1, ref s_dispenserIID, out objDispenser);

            IMetaDataDispenser dispenser = (IMetaDataDispenser)objDispenser;

            dispenser.OpenScope(filename, 0, ref s_importerIID, out objImporter);

            IntPtr        importerPtr = IntPtr.Zero;
            ISymbolReader reader;

            try {
                importerPtr = Marshal.GetComInterfaceForObject(objImporter, typeof(IMetadataImport));

                reader = binder.GetReader(importerPtr, filename, null);
            } finally {
                if (importerPtr != IntPtr.Zero)
                {
                    Marshal.Release(importerPtr);
                }
            }

            return(reader);
        }
Exemplo n.º 7
0
        public MetaDataInfo(string assemblyName)
        {
            Guid guid = new Guid(((GuidAttribute)Attribute.GetCustomAttribute(typeof(IMetaDataImportInternalOnly), typeof(GuidAttribute), false)).Value);
            IMetaDataDispenser corMetaDataDispenser = (IMetaDataDispenser)(new CorMetaDataDispenser());

            this.importInterface = (IMetaDataImportInternalOnly)corMetaDataDispenser.OpenScope(assemblyName, 0, ref guid);
            Marshal.ReleaseComObject(corMetaDataDispenser);
        }
Exemplo n.º 8
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.º 9
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;
 }
Exemplo n.º 10
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.º 11
0
        public static ISymbolReader CreateReader(string filename)
        {
            SymBinder binder;
            object    objImporter;

            IMetaDataDispenser dispenser = InstantiateDispenser(out binder);

            dispenser.OpenScope(filename, 0, ref s_importerIID, out objImporter);

            return(InstantiateReader(binder, filename, objImporter));
        }
Exemplo n.º 12
0
        public MetaDataInfo(string assemblyName)
        {
            // Get guid for IMetaDataImport
            Guid guidIMetaDataImport = new Guid(((GuidAttribute)Attribute.GetCustomAttribute(typeof(IMetaDataImportInternalOnly), typeof(GuidAttribute), false)).Value);

            // Get an IMetaDataImport for the assembly from a dispenser
            IMetaDataDispenser dispenser = (IMetaDataDispenser) new CorMetaDataDispenser();

            importInterface = (IMetaDataImportInternalOnly)dispenser.OpenScope(assemblyName, 0, ref guidIMetaDataImport);
            Marshal.ReleaseComObject(dispenser);
        }
Exemplo n.º 13
0
        public 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 = null;
            IMetaDataDispenser dispenser   = (IMetaDataDispenser)objDispenser;

            try
            {
                dispenser.OpenScope(pathModule, 0, ref importerIID, out objImporter);
            }
            catch
            {
                Console.WriteLine(" ERROR: Failed dispenser.OpenScope() - perhaps this app needs to be compiled in x86?");
                return(null);
            }

            IntPtr        importerPtr = IntPtr.Zero;
            ISymbolReader reader;

            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.º 14
0
        private MetadataReader(string path)
        {
            _path = path;
            // Create the metadata dispenser and open scope on the source file.
            _metaDispenser = (IMetaDataDispenser) new CorMetaDataDispenser();
            int hr = _metaDispenser.OpenScope(path, 0, ref s_importerGuid, out object obj);

            if (hr == 0)
            {
                _assemblyImport = (IMetaDataAssemblyImport)obj;
            }
        }
Exemplo n.º 15
0
        private static ISymUnmanagedReader CreateSymbolReader(string filename, string searchPath, bool avoidLocks)
        {
            // Guids for imported metadata interfaces.
            Guid CLSID_CorMetaDataDispenser = new Guid(0xe5cb7a31, 0x7512, 0x11d2, 0x89, 0xce, 0x00, 0x80, 0xc7, 0x92, 0xe5, 0xd8);
            Guid IID_IMetaDataImport        = new Guid(0x7dac8207, 0xd3ae, 0x4c75, 0x9b, 0x67, 0x92, 0x80, 0x1a, 0x49, 0x7d, 0x44);
            Guid CLSID_CorSymBinder         = new Guid("0A29FF9E-7F9C-4437-8B11-F424491E3931");

            // First create the Metadata dispenser.
            IMetaDataDispenser dispenser = (IMetaDataDispenser)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_CorMetaDataDispenser));

            IntPtr importer = IntPtr.Zero;

            try
            {
                int errorCode = dispenser.OpenScope(filename, 0, ref IID_IMetaDataImport, out importer);
                if (errorCode < 0)
                {
                    if (errorCode == E_FAIL ||
                        errorCode == E_FILE_NOT_FOUND)
                    {
                        return(null);
                    }
                    Marshal.ThrowExceptionForHR(errorCode);
                }

                ISymUnmanagedBinder3 binder = (ISymUnmanagedBinder3)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_CorSymBinder));
                ISymUnmanagedReader  reader;

                errorCode = CreateSymbolReader(binder, importer, filename, searchPath, avoidLocks, out reader);

                if (errorCode < 0)
                {
                    if (errorCode == E_FAIL ||
                        errorCode == E_PDB_DEBUG_INFO_NOT_IN_PDB ||
                        errorCode == E_PDB_NO_DEBUG_INFO ||
                        errorCode == E_PDB_NOT_FOUND)
                    {
                        return(null);
                    }
                    Marshal.ThrowExceptionForHR(errorCode);
                }

                return(reader);
            }
            finally
            {
                if (importer != IntPtr.Zero)
                {
                    Marshal.Release(importer);
                }
            }
        }
Exemplo n.º 16
0
        private PdbSymbolProvider(string binaryFilePath, string pdbFilePath = "")
        {
            _binaryFilePath = binaryFilePath;
            _pdbFilePath    = pdbFilePath;
            if (String.IsNullOrEmpty(_pdbFilePath))
            {
                _pdbFilePath = Path.ChangeExtension(binaryFilePath, ".pdb");
            }

            // 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;

            Marshal.ThrowExceptionForHR(NativeMethods.MetaDataGetDispenser(ref dispenserClassID, ref dispenserIID, out objDispenser));
            _metadataDispenser = (IMetaDataDispenser)objDispenser;

            // Create a symbol binder [?]
            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 (NativeMethods.CoCreateInstance(ref symBinderClassID,
                                               IntPtr.Zero, // pUnkOuter
                                               1,           // CLSCTX_INPROC_SERVER
                                               ref symBinderIID,
                                               out objBinder) < 0)
            {
                throw new InvalidComObjectException("PdbSymbolProvider unable to construct an ISymUnmanagedBinder.");
            }
            _symBinder = (ISymUnmanagedBinder)objBinder;

            // Create a symbol reader
            Guid importerIID = new Guid(0x7dac8207, 0xd3ae, 0x4c75, 0x9b, 0x67, 0x92, 0x80, 0x1a, 0x49, 0x7d, 0x44); // IID_IMetaDataImport

            // Open an metadata importer on the given filename. We'll end up passing this importer straight
            // through to the Binder.
            object objImporter;

            Marshal.ThrowExceptionForHR(_metadataDispenser.OpenScope(binaryFilePath, 0x00000010 /* read only */, ref importerIID, out objImporter));

            string pdbFolderPath = Path.GetDirectoryName(pdbFilePath);

            ISymUnmanagedReader reader;

            Marshal.ThrowExceptionForHR(_symBinder.GetReaderForFile(objImporter, binaryFilePath, pdbFolderPath, out reader));

            _symReader = reader;

            // Create a source file map [if we can find the map file]
            _sourceFileMap = SourceFileMap.Load(pdbFilePath);
        }
Exemplo n.º 17
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;
        }
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
        private static string[] PeVerify(byte[] peImage, int domainId, string assemblyPath, bool metadataOnly)
        {
            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();

                    if (!metadataOnly)
                    {
                        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();
                }
            }
        }
Exemplo n.º 20
0
            private static ISymbolReader TryGetSymbolReaderForFile(
                SymBinder binder, string pathModule, string searchPath)
            {
                ISymbolReader reader;

                IMetaDataDispenser  dispenser = null;
                IMetaDataImportStub importer  = null;
                var importerPtr = IntPtr.Zero;

                try
                {
                    // ReSharper disable once SuspiciousTypeConversion.Global
                    dispenser = (IMetaDataDispenser) new CorMetaDataDispenser();
                    var importerGuid = new Guid(InterfaceMetaDataImportGuid);
                    importer = (IMetaDataImportStub)dispenser.OpenScope(pathModule, 0, ref importerGuid);

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

                    try
                    {
                        reader = binder.GetReader(importerPtr, pathModule, searchPath);
                    }
                    catch (COMException)
                    {
                        reader = null;
                    }
                }
                finally
                {
                    if (importerPtr != IntPtr.Zero)
                    {
                        Marshal.Release(importerPtr);
                    }

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

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

                return(reader);
            }
Exemplo n.º 21
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.º 22
0
        private static string[] PeVerify(byte[] peImage, int domainId, string assemblyPath)
        {
            lock (Guard)
            {
                GCHandle pinned = GCHandle.Alloc(peImage, GCHandleType.Pinned);
                try
                {
                    IntPtr buffer = pinned.AddrOfPinnedObject();

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

                    IMetaDataDispenser dispenser = (IMetaDataDispenser)RuntimeEnvironment.GetRuntimeInterfaceAsObject(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();
                }
            }
        }
        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.º 24
0
        public ISymUnmanagedReader GetSymbolReaderForFile(string metadataFileName)
        {
            if (!File.Exists(Path.ChangeExtension(metadataFileName, ".pdb")))
            {
                return(null);
            }

            if (_metadataDispenser == null || _symBinder == null)
            {
                return(null);
            }

            try
            {
                Guid importerIID = new Guid(0x7dac8207, 0xd3ae, 0x4c75, 0x9b, 0x67, 0x92, 0x80, 0x1a, 0x49, 0x7d, 0x44); // IID_IMetaDataImport

                // Open an metadata importer on the given filename. We'll end up passing this importer straight
                // through to the Binder.
                object objImporter;
                if (_metadataDispenser.OpenScope(metadataFileName, 0x00000010 /* read only */, ref importerIID, out objImporter) < 0)
                {
                    return(null);
                }

                ISymUnmanagedReader reader;
                if (_symBinder.GetReaderForFile(objImporter, metadataFileName, "", out reader) < 0)
                {
                    return(null);
                }
                return(reader);
            }
            catch
            {
                return(null);
            }
        }