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 ShowDuplicateTypes(FileInfo winmd, IConsole console) { using WinmdUtils w1 = WinmdUtils.LoadFromFile(winmd.FullName); Dictionary <string, List <string> > nameToTypes = new Dictionary <string, List <string> >(); foreach (var type in w1.GetTypes()) { if (type is ClassInfo && type.Name == "Apis") { continue; } var toString = type.ToString(); if (!nameToTypes.TryGetValue(toString, out var structs)) { structs = new List <string>(); nameToTypes[toString] = structs; } structs.Add(type.Namespace); } bool dupsFound = false; foreach (var pair in nameToTypes) { if (pair.Value.Count > 1) { if (dupsFound == false) { dupsFound = true; console.Out.Write("Duplicate types detected:\r\n"); } pair.Value.Sort(); console.Out.Write($"{pair.Key}\r\n"); foreach (var type in pair.Value) { console.Out.Write($" {type}\r\n"); } } } if (!dupsFound) { console.Out.Write("No duplicate types found.\r\n"); } return(dupsFound ? -1 : 0); }
public static int ShowDuplicateConstants(FileInfo winmd, IConsole console) { using WinmdUtils w1 = WinmdUtils.LoadFromFile(winmd.FullName); Dictionary <string, List <string> > nameToNamespace = new Dictionary <string, List <string> >(); foreach (ClassInfo apiClass in w1.GetTypes().Where(t => t is ClassInfo && t.Name == "Apis")) { foreach (var field in apiClass.Fields) { if (!nameToNamespace.TryGetValue(field.Name, out var namespaces)) { namespaces = new List <string>(); nameToNamespace[field.Name] = namespaces; } namespaces.Add(apiClass.Namespace); } } bool dupsFound = false; foreach (var pair in nameToNamespace) { if (pair.Value.Count > 1) { if (dupsFound == false) { dupsFound = true; console.Out.Write("Duplicate constants detected:\r\n"); } pair.Value.Sort(); console?.Out.Write($"{pair.Key}\r\n"); foreach (var @namespace in pair.Value) { console?.Out.Write($" {@namespace}\r\n"); } } } if (!dupsFound) { console.Out.Write("No duplicate constants found.\r\n"); } return(dupsFound ? -1 : 0); }