Exemple #1
0
        private static void Main(string[] args)
        {
            try
            {
                var sysPaths0 = RegLib.GetValues(@"HKLM\SYSTEM\CURRENTCONTROLSET\CONTROL\SESSION MANAGER\ENVIRONMENT",
                                                 RegistryView.Registry64,
                                                 RegistryValueOptions.DoNotExpandEnvironmentNames)
                                .Where(x => x.key.Equals("Path", StringComparison.OrdinalIgnoreCase)).First().value;

                var sysPaths = sysPaths0
                               .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                               .Select(x => new PathDir {
                    Directory = x, isSystem = true, Sha1Sum = Sha1SumString($"{x}S")
                });

                var userPaths0 = RegLib.GetValues(@"HKCU\Environment",
                                                  RegistryView.Registry64,
                                                  RegistryValueOptions.DoNotExpandEnvironmentNames)
                                 .Where(x => x.key.Equals("Path", StringComparison.OrdinalIgnoreCase))
                                 .First().value;

                var userPaths = userPaths0
                                .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                                .Select(x => new PathDir {
                    Directory = x, isSystem = false, Sha1Sum = Sha1SumString($"{x}U")
                });

                var paths = sysPaths.Concat(userPaths);

                var group = paths.ToLookup(x => x.Directory);
                foreach (var dup in group.Where(x => x.Count() > 1))
                {
                    Console.WriteLine($"Directory {dup.Key} occurs twice in system Path");
                }


                var t1       = new ShaTrie();
                var prefixes = t1.GetShortestPrefix(paths.Select(x => x.Sha1Sum));
                paths = paths.Zip(prefixes, (a, b) => new PathDir {
                    Directory = a.Directory, isSystem = a.isSystem, Sha1Sum = a.Sha1Sum, Prefix = b
                });

                foreach (var p in paths)
                {
                    Console.WriteLine($"{p.Prefix,7} {p.Directory}");
                }
            }
            catch (Exception ex)
            {
                var fullname = System.Reflection.Assembly.GetEntryAssembly().Location;
                var progname = Path.GetFileNameWithoutExtension(fullname);
                Console.Error.WriteLine($"{progname} Error: {ex.Message}");
            }
        }
Exemple #2
0
        private static void PrintTypeLibs(bool is32bit = false)
        {
            var versionPattern = @"\\[a-z0-9]{1,3}\.[a-z0-9]{1,3}$";

            var view = is32bit ? RegistryView.Registry32 : RegistryView.Registry64;

            foreach (var name in RegLib.GetSubKeyNames(@"HKCR\typelib", view))
            {
                Console.WriteLine($"{name}");
                foreach (var k2 in RegLib.GetSubKeyNames(name, view))
                {
                    var match = Regex.Match(k2, versionPattern, RegexOptions.IgnoreCase);
                    if (match.Success)
                    {
                        Console.WriteLine($"    {k2}");
                        foreach (var k3 in RegLib.GetSubKeyNames(k2, view))
                        {
                            var flagsStr = "";
                            if (k3.EndsWith("flags", StringComparison.OrdinalIgnoreCase))
                            {
                                flagsStr = $":{RegLib.GetDefaultValue(k3, view)}";
                                Console.WriteLine($"        {k3}{flagsStr}");
                            }
                            else
                            {
                                var possibleLCID = RegLib.GetLastSegment(k3);
                                if (possibleLCID.All(char.IsDigit)) // the LCID
                                {
                                    Console.WriteLine($"        {k3}");
                                    foreach (var platform in RegLib.GetSubKeyNames(k3))
                                    {
                                        Console.WriteLine($"            platform:{RegLib.GetLastSegment(platform)}");
                                        foreach ((string key, string value) in RegLib.GetValues(platform, view))
                                        {
                                            Console.WriteLine($"                {key} {value}");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }