private void AddModuleToAssemblyDictionary(ModuleDefinition module, ModuleProcessor moduleProcessor) { modulesByAssembly[GetModuleKey(module)] = moduleProcessor; }
private IList <ModuleProcessor> GatherModulesNeedingProcessing() { var processors = new List <ModuleProcessor>(); if (!IsModuleProcessable(ModuleDefinition)) { return(processors); } var stilettoReferences = StilettoReferences.Create(AssemblyResolver); var mainModuleProcessor = new ModuleProcessor(errorReporter, ModuleDefinition, stilettoReferences); processors.Add(mainModuleProcessor); AddModuleToAssemblyDictionary(ModuleDefinition, mainModuleProcessor); var copyLocalAssemblies = new Dictionary <string, bool>(StringComparer.Ordinal); var localDebugFiles = new Queue <string>(); foreach (var copyLocal in ReferenceCopyLocalPaths) { if (copyLocal.EndsWith(".pdb") || copyLocal.EndsWith(".mdb")) { // We'll come back to the debug files after we have a complete // list of local assemblies. localDebugFiles.Enqueue(copyLocal); continue; } if (copyLocal.EndsWith(".exe") || copyLocal.EndsWith(".dll")) { copyLocalAssemblies[copyLocal] = false; } } // Check which assemblies have debug symbols and, consequently, // for which assemblies we will attempt to read and write such symbols. while (localDebugFiles.Count > 0) { var pdb = localDebugFiles.Dequeue(); var rawPath = Path.Combine(Path.GetDirectoryName(pdb), Path.GetFileNameWithoutExtension(pdb)); var dll = rawPath + ".dll"; var exe = rawPath + ".exe"; if (copyLocalAssemblies.ContainsKey(dll)) { copyLocalAssemblies[dll] = true; } if (copyLocalAssemblies.ContainsKey(exe)) { copyLocalAssemblies[exe] = true; } } foreach (var pathAndHasPdb in copyLocalAssemblies) { var path = pathAndHasPdb.Key; var hasPdb = pathAndHasPdb.Value; var assembly = AssemblyDefinition.ReadAssembly(path, new ReaderParameters { ReadSymbols = hasPdb }); // TODO: Figure out how to differentiate between third-party libs and client code. if (assembly.Name.HasPublicKey) { LogWarning("Assembly " + assembly.Name + " is strong-named and will not be processed."); continue; } dependencies[path] = Tuple.Create(assembly, hasPdb); foreach (var module in assembly.Modules) { if (!IsModuleProcessable(module)) { continue; } var moduleProcessor = new ModuleProcessor(errorReporter, module, stilettoReferences); processors.Add(moduleProcessor); AddModuleToAssemblyDictionary(module, moduleProcessor); } } return(processors); }