public static int ShowPointersToDelegates(FileInfo winmd, string[] allowItem, IConsole console) { HashSet <string> allowTable = new HashSet <string>(allowItem); using WinmdUtils w1 = WinmdUtils.LoadFromFile(winmd.FullName); bool pointersFound = false; HashSet <string> delegateNames = new HashSet <string>(w1.GetTypes().Where(t => t is DelegateTypeInfo).Select(d => $"{d.Namespace}.{d.Name}")); foreach (var type in w1.GetTypes()) { foreach (var pointerInUse in PointerToOneOfNamesInUse(delegateNames, type)) { if (allowTable.Contains(pointerInUse.Name)) { continue; } if (!pointersFound) { console.Out.Write("Pointers to delegates detected:\r\n"); pointersFound = true; } console?.Out.Write($"{pointerInUse.Type},{pointerInUse.Name}\r\n"); } } if (!pointersFound) { console.Out.Write("No pointers to delegates found.\r\n"); } return(pointersFound ? -1 : 0); }
public static int ShowEmptyDelegates(FileInfo winmd, string[] allowItem, IConsole console) { HashSet <string> allowTable = new HashSet <string>(allowItem); using WinmdUtils w1 = WinmdUtils.LoadFromFile(winmd.FullName); bool emptyFound = false; foreach (DelegateTypeInfo type in w1.GetTypes().Where(t => t is DelegateTypeInfo)) { if (!type.Parameters.Any()) { if (allowTable.Contains(type.Name)) { continue; } if (!emptyFound) { emptyFound = true; console.Out.Write("Empty delegates detected:\r\n"); } console?.Out.Write($"{type.Name}\r\n"); } } if (!emptyFound) { console.Out.Write("No empty delegates found.\r\n"); } return(emptyFound ? -1 : 0); }
public static int ShowMissingImports(FileInfo first, FileInfo second, string exclusions, IConsole console) { int ret = 0; using WinmdUtils w1 = WinmdUtils.LoadFromFile(first.FullName); HashSet <string> remainingImports = new HashSet <string>(); foreach (var imp in w1.GetDllImports()) { remainingImports.Add(imp.Name.ToString()); } using WinmdUtils w2 = WinmdUtils.LoadFromFile(second.FullName); foreach (var imp in w2.GetDllImports()) { var text = imp.Name.ToString(); if (remainingImports.Contains(text)) { remainingImports.Remove(text); } } foreach (var imp in remainingImports) { if (ret == 0) { console.Out.Write("Missing imports detected:\r\n"); ret = -1; } console?.Out.Write($"{imp}\r\n"); } if (ret == 0) { console.Out.Write("No missing imports found.\r\n"); } return(ret); }