Ejemplo n.º 1
0
        public void ReadSymbols(ISymbolReader reader, bool throwIfSymbolsAreNotMaching)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            symbol_reader = reader;

            if (!symbol_reader.ProcessDebugHeader(GetDebugHeader()))
            {
                symbol_reader = null;

                if (throwIfSymbolsAreNotMaching)
                {
                    throw new SymbolsNotMatchingException("Symbols were found but are not matching the assembly");
                }

                return;
            }

            if (HasImage && ReadingMode == ReadingMode.Immediate)
            {
                var immediate_reader = new ImmediateModuleReader(Image);
                immediate_reader.ReadSymbols(this);
            }
        }
Ejemplo n.º 2
0
        public void ReadSymbols(ISymbolReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            symbol_reader = reader;

            ProcessDebugHeader();

            if (HasImage && ReadingMode == ReadingMode.Immediate)
            {
                var immediate_reader = new ImmediateModuleReader(Image);
                immediate_reader.ReadSymbols(this);
            }
        }
Ejemplo n.º 3
0
        private static void Write(ModuleDefinition module, Disposable <Stream> stream, WriterParameters parameters)
        {
            if ((module.Attributes & ModuleAttributes.ILOnly) == (ModuleAttributes)0)
            {
                throw new NotSupportedException("Writing mixed-mode assemblies is not supported");
            }
            if (module.HasImage && module.ReadingMode == ReadingMode.Deferred)
            {
                ImmediateModuleReader immediateModuleReader = new ImmediateModuleReader(module.Image);
                immediateModuleReader.ReadModule(module, false);
                immediateModuleReader.ReadSymbols(module);
            }
            module.MetadataSystem.Clear();
            if (module.symbol_reader != null)
            {
                module.symbol_reader.Dispose();
            }
            AssemblyNameDefinition assemblyNameDefinition = (module.assembly != null) ? module.assembly.Name : null;
            string fileName  = stream.value.GetFileName();
            uint   timestamp = parameters.Timestamp ?? module.timestamp;
            ISymbolWriterProvider symbolWriterProvider = parameters.SymbolWriterProvider;

            if (symbolWriterProvider == null && parameters.WriteSymbols)
            {
                symbolWriterProvider = new DefaultSymbolWriterProvider();
            }
            if (parameters.StrongNameKeyPair != null && assemblyNameDefinition != null)
            {
                assemblyNameDefinition.PublicKey = parameters.StrongNameKeyPair.PublicKey;
                module.Attributes |= ModuleAttributes.StrongNameSigned;
            }
            using (ISymbolWriter symbol_writer = GetSymbolWriter(module, fileName, symbolWriterProvider, parameters))
            {
                MetadataBuilder metadata = new MetadataBuilder(module, fileName, timestamp, symbolWriterProvider, symbol_writer);
                BuildMetadata(module, metadata);
                ImageWriter imageWriter = ImageWriter.CreateWriter(module, metadata, stream);
                stream.value.SetLength(0L);
                imageWriter.WriteImage();
                if (parameters.StrongNameKeyPair != null)
                {
                    CryptoService.StrongName(stream.value, imageWriter, parameters.StrongNameKeyPair);
                }
            }
        }