public override void VisitModuleDefinitionCollection(ModuleDefinitionCollection modules) { ModuleTable mt = m_tableReader.GetModuleTable(); if (mt == null || mt.Rows.Count != 1) { throw new ReflectionException("Can not read main module"); } ModuleRow mr = mt.Rows [0] as ModuleRow; string name = ReadString(mr.Name); ModuleDefinition main = new ModuleDefinition(name, m_asmDef, this, true); main.Mvid = m_streams.GuidHeap [mr.Mvid]; main.MetadataToken = new MetadataToken(TokenType.Module, 1); modules.Add(main); m_module = main; m_module.Accept(this); FileTable ftable = m_tableReader.GetFileTable(); if (ftable != null && ftable.Rows.Count > 0) { foreach (FileRow frow in ftable.Rows) { if (frow.Flags == Mono.Cecil.FileAttributes.ContainsMetaData) { name = ReadString(frow.Name); FileInfo location = new FileInfo(Path.Combine(m_img.FileInformation.DirectoryName, name)); if (!File.Exists(location.FullName)) { throw new FileNotFoundException("Module not found : " + name); } try { ImageReader module = ImageReader.Read(location.FullName); mt = module.Image.MetadataRoot.Streams.TablesHeap [ModuleTable.RId] as ModuleTable; if (mt == null || mt.Rows.Count != 1) { throw new ReflectionException("Can not read module : " + name); } mr = mt.Rows [0] as ModuleRow; ModuleDefinition modext = new ModuleDefinition(name, m_asmDef, new StructureReader(module, m_manifestOnly), false); modext.Mvid = module.Image.MetadataRoot.Streams.GuidHeap [mr.Mvid]; modules.Add(modext); } catch (ReflectionException) { throw; } catch (Exception e) { throw new ReflectionException("Can not read module : " + name, e); } } } } }
public override void VisitModuleDefinition(ModuleDefinition module) { if (module.Main) { ModuleTable modTable = m_tableWriter.GetModuleTable(); ModuleRow modRow = m_rowWriter.CreateModuleRow( (ushort)0, m_mdWriter.AddString(module.Name), m_mdWriter.AddGuid(module.Mvid), (uint)0, (uint)0); modTable.Rows.Add(modRow); } else { // multiple module assemblies throw new NotImplementedException(); } }
public override void VisitModuleDefinition(ModuleDefinition module) { if (module.Main) { ModuleTable modTable = m_tableWriter.GetModuleTable(); ModuleRow modRow = m_rowWriter.CreateModuleRow( 0, m_mdWriter.AddString(module.Name), m_mdWriter.AddGuid(module.Mvid), 0, 0); modTable.Rows.Add(modRow); module.MetadataToken = new MetadataToken(TokenType.Module, 1); } else { // multiple module assemblies throw new NotImplementedException(); } }