private bool ReadInputFiles() { foreach (string filename in Filenames) { Console.WriteLine("Reading {0}...", filename); IRegistryImporter importer = null; try { if (File.Exists(filename)) { if (filename.EndsWith(".xml", StringComparison.OrdinalIgnoreCase)) { importer = new XmlRegFileImporter(File.ReadAllText(filename)); } else if (filename.EndsWith(".reg", StringComparison.OrdinalIgnoreCase)) { importer = RegFile.CreateImporterFromFile(filename, Options); } } if (importer == null) { string rootPathWithoutHive; RegistryKey key = Regis3.OpenRegistryHive(filename, out rootPathWithoutHive, CurrentRegistryView); if (key != null) { importer = new RegistryImporter(key, rootPathWithoutHive); } else { importer = RegFile.CreateImporterFromFile(filename, Options); } } Files.Add(importer.Import()); } catch (System.Data.SyntaxErrorException e) { Console.WriteLine(e.Message); return(false); } } if (CompareAgainstRegistry) { Files.Add(new RegistryImportRelativeToExistingRegKeyEntry(Files[0], CurrentRegistryView).Import()); Filenames.Add("REGISTRY"); } Console.WriteLine(); return(true); }
public void ImportOfflineRegistryTest() { IUnityContainer container = new UnityContainer(); IConfig config = new Config { UsernameLocations = new List <string>() { "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache" }, UserRegistryLocations = new List <string>() { "ntuser.dat", "Local Settings\\Application Data\\Microsoft\\Windows\\UsrClass.dat", "AppData\\Local\\Microsoft\\Windows\\UsrClass.dat" }, ShellbagRootLocations = new List <string> { "Software\\Microsoft\\Windows\\Shell\\BagMRU", "Software\\Microsoft\\Windows\\Shell\\Bags", "Software\\Microsoft\\Windows\\ShellNoRoam\\BagMRU", "Software\\Microsoft\\Windows\\ShellNoRoam\\Bags", "Local Settings\\Software\\Microsoft\\Windows\\Shell\\BagMRU", "Local Settings\\Software\\Microsoft\\Windows\\Shell\\Bags" }, KnownGuids = new Dictionary <string, string>() }; Selected selected = new Selected(); ShellItemCollection shellItems = new ShellItemCollection(); UserCollection users = new UserCollection(); RegistryHiveCollection registries = new RegistryHiveCollection(); container.RegisterType <IShellItemFactory, ShellItemFactory>(); container.RegisterInstance <IConfig>(config, InstanceLifetime.Singleton); container.RegisterInstance <IShellItemCollection>(shellItems, InstanceLifetime.Singleton); container.RegisterInstance <IUserCollection>(users, InstanceLifetime.Singleton); container.RegisterInstance <IRegistryHiveCollection>(registries, InstanceLifetime.Singleton); container.RegisterInstance <ISelected>(selected, InstanceLifetime.Singleton); IRegistryImporter regImporter = container.Resolve <RegistryImporter>(); (_, IEnumerable <IShellItem> items) = regImporter.ImportRegistry(false, true, "Resources\\UsrClass.dat"); Assert.IsTrue(shellItems.Count == items.Count()); Assert.IsTrue(registries.Count == 1); Assert.IsTrue(registries.First().Places.Distinct().SequenceEqual(registries.First().Places)); }
public void RegistryImporterTest() { IUnityContainer container = new UnityContainer(); IConfig config = new Config { UsernameLocations = new List <string>() { "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache" }, UserRegistryLocations = new List <string>() { "ntuser.dat", "Local Settings\\Application Data\\Microsoft\\Windows\\UsrClass.dat", "AppData\\Local\\Microsoft\\Windows\\UsrClass.dat" }, ShellbagRootLocations = new List <string> { "Software\\Microsoft\\Windows\\Shell\\BagMRU", "Software\\Microsoft\\Windows\\Shell\\Bags", "Software\\Microsoft\\Windows\\ShellNoRoam\\BagMRU", "Software\\Microsoft\\Windows\\ShellNoRoam\\Bags", "Local Settings\\Software\\Microsoft\\Windows\\Shell\\BagMRU", "Local Settings\\Software\\Microsoft\\Windows\\Shell\\Bags" }, KnownGuids = new Dictionary <string, string>() }; Selected selected = new Selected(); ShellItemCollection shellItems = new ShellItemCollection(); UserCollection users = new UserCollection(); RegistryHiveCollection registries = new RegistryHiveCollection(); container.RegisterType <IShellItemFactory, ShellItemFactory>(); container.RegisterInstance <IConfig>(config, InstanceLifetime.Singleton); container.RegisterInstance <IShellItemCollection>(shellItems, InstanceLifetime.Singleton); container.RegisterInstance <IUserCollection>(users, InstanceLifetime.Singleton); container.RegisterInstance <IRegistryHiveCollection>(registries, InstanceLifetime.Singleton); container.RegisterInstance <ISelected>(selected, InstanceLifetime.Singleton); IRegistryImporter regImporter = container.Resolve <RegistryImporter>(); Assert.IsTrue(regImporter != null); }